久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3874|回復: 0
打印 上一主題 下一主題
收起左側

STC11F02E單鍵控制的兩種模式選擇

[復制鏈接]
跳轉到指定樓層
樓主
ID:72519 發表于 2015-1-23 00:53 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
OMG! 今晚,出去買煙時,走著想著,構思著,一個按鍵控制四個數碼管顯示;按第一下高位顯示1H并閃爍;按第二下低位顯2H并閃爍;
按第三下則把選擇后的狀態用拉幕的方式顯示出來;
PCB打了10個樣品收到了,今天組裝了并下載以前的程序個功能是好;現在程序改好了,空閑時下載到新的板子上,再調試調試,應該是可以的;
好了,上代碼了!
  1. //#pragma src(signle.a51)

  2. #include <reg52.h>
  3. #include <display.c>
  4. #define uchar unsigned char
  5. #define uint unsigned int

  6. //sfr PCON = 0x87h;
  7. sbit Key1 = P3^2;
  8. sbit BUZ = P3^1;

  9. sbit Signle = P3^0;
  10. sbit Led0  = P1^0;
  11. sbit JDQ  = P1^2;
  12. sbit Dp = P1^5;
  13. sbit SMG1 = P3^7;
  14. sbit SMG2 = P3^5;
  15. sbit SMG3 = P3^4;
  16. sbit SMG4 = P3^3;
  17. uint Key_count,Time_value,BTime_Count;
  18. uchar Beep_time,Key_flag,BTime_Flag,JDQ_flag,BP_Count,LM_Count,LM_GroupCNT;
  19. uchar BT_Sec,Sec,Min,Hour,Key_Select,Key_long_flag,Key_long_count;
  20. uchar Led_Scan,Led_Loop,Sec_1,Min_1,Hour_1,BT_Sec_1;
  21. uchar Key_Select_Flag;
  22. //uchar Display_number[]={0xd7,0x14,0xcd,0x5d,0x1e,0x5b,0xdb,0x15,0xdf,0x5f,0x00};
  23. uchar code Display_number[]={0x28,0xeb,0x32,0xa2,0xe1,0xa4,0x24,0xea,0x20,0xa0,0xff,0xf7}; //0123456789 -
  24. uchar code Display_string[]={0xff,0xff,0xff,0xf7,0xeb,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//0001HZ00000
  25. uchar code Display_string2[]={0xff,0xff,0xff,0xf7,0x32,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//0002HZ00000;
  26. uchar code Display_NUM[]={0,1,2,3,4,5,6,7,8,9,10,11};
  27. uchar Clock[]={0xff,0xff,0xff,0xeb,0x32,0xf7,0xeb,0x32,0xf7,0xeb,0x32,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
  28. //---------------------------------------------------
  29. //---------------------------------------------------
  30. //4COM 共陽數碼管 1234 SR410361K
  31. //---------------------------------------------------
  32. //P1.0 A;    |---|
  33. //P1.2 B;    |   |
  34. //P1.4 C;    |---|
  35. //P1.6 D;    |   |
  36. //P1.7 E;    |---|
  37. //P1.1 F;
  38. //P1.3 G;
  39. //P1.5 Dp;
  40. //SMG1=P3.7,SMG2=P3.5,SMG3=P3.4,SMG4=P3.3;
  41. //---------------------------------------------------
  42. //---------------------------------------------------
  43. void display_Scan(void);
  44. void Delay_ms();
  45. void Clock_Prog();
  46. void Clock_Prog_1();
  47. void Delay_ms(uint Tms)
  48. {
  49.   uint i,j;
  50.   for(i=Tms;i>0;i--)
  51.   for(j=1220;j>0;j--)
  52.   {;}
  53. }
  54. void Delay_us(uint Tus)
  55. {
  56.   while(--Tus);
  57. }
  58. void Buz(void)
  59.   {
  60.     uint i;
  61.     for(i=0;i<200;i++)
  62.     {
  63.       BUZ=~BUZ;
  64.      Delay_us(300);
  65.     }
  66.     BUZ=0;
  67.   }
  68. void Beep_Bi(void)
  69. {
  70.   if(Beep_time!=0)
  71.   {
  72.    Beep_time--;
  73.    BUZ=~BUZ;
  74.   }
  75.   else
  76.   {
  77.    BUZ=0;
  78.   }
  79. }
  80. void T0_ini()
  81. {
  82.    TMOD=0x12;
  83.   TH1=(65536-1000)/256;
  84.   TL1=(65536-1000)%256;
  85.   TR1=1;
  86.   ET1=1;
  87.   TH0=6;
  88.   TL0=6;
  89.   TR0=0;
  90.   ET0=1;
  91.   EA=1;
  92. }
  93. void TM0(void)interrupt 1
  94. {
  95.   uint Time_Count;
  96.   TF0=0;
  97.   Time_Count++;BTime_Count++;
  98.   BP_Count++;
  99.   if(BTime_Count==2000)
  100.   {
  101.    BT_Sec++;BTime_Flag=~BTime_Flag;
  102.   }
  103.   if(BP_Count==2)      //1ms DiDa Batime;
  104.   {
  105.    BP_Count=0;
  106.    Beep_Bi();
  107.   }
  108.   if(Key_Select_Flag==1)   //1Hz
  109.   {
  110.     if(Time_Count==2000)
  111.    {
  112.      Time_Count=0;Dp=~Dp;Signle=~Signle;
  113.    }
  114.   }
  115.   if(Key_Select_Flag==2)   //2Hz
  116.   {
  117.    if(Time_Count==1000)
  118.    {
  119.     Time_Count=0;Dp=~Dp;Signle=~Signle;
  120.    }
  121.   }
  122.     //if(Time_Count==2000) // ext atxl 12MHz;500ms
  123.   //if(Time_Count==1333) // ext atxl 8MHz 500ms;
  124.   //if(Time_Count==998) // built in atxl; 500ms
  125.     //{
  126.   // Time_Count=0;
  127.    //BTime_Flag=~BTime_Flag;
  128.    //BT_Sec++;
  129.   // Dp=~Dp;
  130.    //BT_Sec_1++;
  131.   // Signle=~Signle;
  132.    /*/if(Key_flag==1)
  133.    {
  134.     BT_Sec=0;
  135.     if(BT_Sec_1==2)
  136.     {
  137.       BT_Sec_1=0;
  138.      Sec_1++;
  139.      if(Sec_1==60)
  140.      {
  141.       Sec_1=0;Min_1++;
  142.      }
  143.      if(Min_1==60)
  144.      {
  145.       Min_1=0;Hour_1++;
  146.      }
  147.      if(Hour_1==24)
  148.      {
  149.       Hour_1=0;
  150.      }
  151.     // Clock_Prog_1();
  152.     }
  153.    } */
  154. // }
  155.   if(BT_Sec==2)
  156.   {
  157.    BT_Sec=0;
  158.    Sec++;
  159.    if(Sec==60)
  160.    {
  161.     Sec=0;Min++;
  162.    }
  163.      if(Min==60)        
  164.    {
  165.     Min=0;Hour++;
  166.    }
  167.    if(Hour==24)
  168.    {
  169.     Hour=0;
  170.    }
  171.    //Clock_Prog();
  172.   }
  173. }
  174. void TM1(void)interrupt 3
  175. {
  176.   TH1=(65536-1000)/256;
  177.   TL1=(65536-1000)%256;
  178.   Led_Scan=1;Led_Loop++;Led_Loop=Led_Loop&0x03;
  179.   
  180.     Key1=1;
  181.     if(Key1==0)
  182.     {
  183.      Key_count++;
  184.    if(Key_count==20)
  185.    {
  186.      Beep_time=100;
  187.      Key_flag=1;
  188.      TR0=1;
  189.      Key_Select++;
  190.      if(Key_Select==3)
  191.      {
  192.       Key_Select=0;Key_flag=0;
  193.      }
  194.   //  }
  195.   // if(Key_count>=20*50)
  196.   // {     
  197.   //  Key_count=500; // 設置長按快跳進度
  198.   //  Key_long_flag=1;
  199.   //  {
  200.        if(Key_Select==1)
  201.      {
  202.       Key_Select_Flag=0;
  203.     Key_Select_Flag=1;
  204.      // Min++; if(Min==60)Min=0;
  205.      }
  206.     if(Key_Select==2)
  207.      {
  208.     Key_Select_Flag=0;
  209.     Key_Select_Flag=2;
  210.      // Hour++; if(Hour==24)Hour=0;
  211.         }   
  212.   //  }
  213.   // }
  214.    }
  215.   }
  216.      else
  217.    {Key_count=0;Key_long_flag=0;Key_Select_Flag=0;}
  218.    }
  219.    void Clock_Prog()
  220.   {
  221.    //Clock[0]=Display_number[10];
  222.    //Clock[1]=Display_number[10];
  223.    Clock[3]=Display_number[Hour/10];
  224.    Clock[4]=Display_number[Hour%10];
  225.    Clock[5]=Display_number[11];//
  226.    Clock[6]=Display_number[Min/10];
  227.    Clock[7]=Display_number[Min%10];
  228.    Clock[8]=Display_number[11];//
  229.    Clock[9]=Display_number[Sec/10];
  230.    Clock[10]=Display_number[Sec%10];
  231.    //Clock[11]=Display_number[10];
  232.    //Clock[12]=Display_number[10];
  233.    //Clock[13]=Display_number[10];
  234.    //Clock[14]=Display_number[10];
  235.   }
  236.    void Clock_Prog_1()
  237.   {
  238.    //Clock[0]=Display_number[10];
  239.    //Clock[1]=Display_number[10];
  240.    Clock[3]=Display_number[Hour/10];
  241.    Clock[4]=Display_number[Hour%10];
  242.    Clock[5]=Display_number[11];//
  243.    Clock[6]=Display_number[Min_1/10];
  244.    Clock[7]=Display_number[Min_1%10];
  245.    Clock[8]=Display_number[11];//
  246.    Clock[9]=Display_number[Sec_1/10];
  247.    Clock[10]=Display_number[Sec_1%10];
  248.    //Clock[11]=Display_number[10];
  249.    //Clock[12]=Display_number[10];
  250.    //Clock[13]=Display_number[10];
  251.    //Clock[14]=Display_number[10];
  252.   }
  253.   void SmgDisp(uchar ch,uchar num)
  254.   {
  255.   uchar number;
  256.   number=num;
  257.   //P3=0x03;
  258.   P1=0xff;
  259.   SMG1=0;SMG2=0;SMG3=0;SMG4=0;
  260.   switch(ch)
  261.   {
  262.    case 1:SMG4=1;LM_Count=0;break;    //SMG排列 1 2 3 4 第四個數碼管
  263.    case 2:SMG3=1;LM_Count++;break;    //SMG排列 1 2 3 4 第三個數碼管
  264.    case 3:SMG2=1;LM_Count++;break;    //SMG排列 1 2 3 4 第二個數碼管
  265.    case 4:SMG1=1;LM_Count++;break;    //SMG排列 1 2 3 4 第一個數碼管
  266.    default:break;
  267.   }
  268.    //P1=Display_number[Clock[number]];
  269.   //P1=Display_string[number];
  270.   if(Key_Select==0||Key_Select_Flag==1)
  271.   {
  272.    P1=Display_string[number];
  273.   }
  274.   if(Key_Select_Flag==2)
  275.   {
  276.    P1=Display_string2[number];
  277.   }
  278.   //P1=Clock[number];
  279.   }
  280.   void CheckTime()
  281.   {
  282.   if(Led_Scan)
  283.   {
  284.    switch(Led_Loop)
  285.    {
  286.     case 0:SmgDisp(4,LM_Count+LM_GroupCNT);break; //第一個數碼管
  287.     case 1:SmgDisp(3,LM_Count+LM_GroupCNT);break; //第二個數碼管
  288.     case 2:SmgDisp(2,LM_Count+LM_GroupCNT);break; //第三個數碼管
  289.     case 3:SmgDisp(1,LM_Count+LM_GroupCNT);break; //第四個數碼管
  290.    }
  291.      Led_Scan=0;
  292.   }
  293.   }
  294.   
  295. void Display(void)
  296. {
  297.   if(BTime_Flag&(Key_Select==2)&(Key_long_flag==0))
  298.    {
  299.    P1=0xff;SMG1=0;SMG2=0;SMG3=0;SMG4=0;
  300.              //P3=0x00;
  301.   }
  302.   else
  303.   {
  304.    if(BTime_Flag)
  305.   {
  306.    Dp=0;SMG1=1;       //P3=0x80;
  307.    Delay_ms(1);SMG1=0;      //P3=0x00;
  308.    Dp=0;SMG2=1;       //P3=0x20;
  309.    Delay_ms(1);SMG2=0;      //P3=0x00;
  310.   }
  311.   //P1=Display_number[Hour/10];
  312.   P1=Display_string[4];
  313.    SMG1=1;          //P3=0x80;
  314.   Delay_ms(1);
  315.    SMG1=0;          //P3=0x00;
  316.    P1=0xff;
  317.    //P1=Display_number[Hour%10];
  318.   P1=Display_string[5];
  319.    SMG2=1;          //P3=0x20;
  320.    Delay_ms(1);
  321.    SMG2=0;          //P3=0x00;
  322.    P1=0xff;
  323.   }
  324.   if(BTime_Flag&(Key_Select==1)&(Key_long_flag==0))
  325.    {
  326.    P1=0xff;SMG1=0;SMG2=0;SMG3=0;SMG4=0; //P3=0x00;
  327.   }
  328.   else
  329.   {
  330.    if(BTime_Flag)
  331.   {
  332.    Dp=0;SMG3=1;       //P3=0x10;
  333.    Delay_ms(1);SMG3=0;      //P3=0x00;
  334.    Dp=0;SMG4=1;       //P3=0x08;
  335.    Delay_ms(1);SMG4=0;      //P3=0x00;
  336.   }
  337.   //P1=Display_number[Min/10];
  338.   P1=Display_string2[4];
  339.    SMG3=1;          //P3=0x10;
  340.    Delay_ms(1);
  341.    SMG3=0;          //P3=0x00;
  342.    P1=0xff;
  343.    //=Display_number[Min%10];
  344.   P=Display_string2[5];
  345.    SMG4=1;          //P3=0x08;
  346.    Delay_ms(1);
  347.    SMG4=0;          //P3=0x00;
  348.    P1=0xff;
  349.   }
  350. }
  351. void exint0(void)interrupt 0
  352. {
  353.   Buz();T0_ini();EX0=0;EA=1;
  354. }
  355.   
  356. void Display_Scan(void)
  357. {  
  358.   P1=0x00;
  359.   P3=0x00;
  360. //---------"A"--------------
  361.   //P1=0x01;
  362.   P1=0xfe;
  363.   P3=0x80;   //smg1
  364.   Delay_ms(1);
  365.   P1=0xff;
  366.   P3=0x00;
  367.   P1=0xfe;
  368.   P3=0x20;   //smg2
  369.   Delay_ms(1);
  370.   P1=0xff;
  371.   P3=0x00;
  372.   P1=0xfe;
  373.   P3=0x10;   //smg3
  374.   Delay_ms(1);
  375.   P1=0xff;
  376.   P3=0x00;
  377.   P1=0xfe;
  378.   P3=0x08;   //smg4
  379.   Delay_ms(1);
  380.   P1=0xff;
  381.   P3=0x00;
  382.   P1=0xfe;
  383.   Delay_ms(100);
  384. //---------"B"--------------
  385.   P1=0xfb;
  386.   P3=0x80;
  387.   Delay_ms(1);
  388.   P1=0xff;
  389.   P3=0x00;
  390.   P1=0xfb;
  391.   P3=0x20;
  392.   Delay_ms(1);
  393.   P1=0xff;
  394.   P3=0x00;
  395.   P1=0xfb;
  396.   P3=0x10;
  397.   Delay_ms(1);
  398.   P1=0xff;
  399.   P3=0x00;
  400.   P1=0xfb;
  401.   P3=0x08;
  402.   Delay_ms(1);
  403.   P1=0xfb;
  404.   P1=0xff;
  405.   P3=0x00;
  406.   Delay_ms(100);
  407. //---------"C"--------------
  408.   //P1=0x10;
  409.   P1=0xef;
  410.   P3=0x80;
  411.   Delay_ms(1);
  412.   P1=0xff;
  413.   P3=0x00;
  414.   P1=0xef;
  415.   P3=0x20;
  416.   Delay_ms(1);
  417.   P1=0xff;
  418.   P3=0x00;
  419.   P1=0xef;
  420.   P3=0x10;
  421.   Delay_ms(1);
  422.   P1=0xff;
  423.   P3=0x00;
  424.   P1=0xef;
  425.   P3=0x08;
  426.   Delay_ms(1);
  427.   P1=0xef;
  428.   P1=0xff;
  429.   P3=0x00;
  430.   Delay_ms(100);
  431. //---------"D"--------------
  432.   P1=0xcf;
  433.   P3=0x80;
  434.   Delay_ms(1);
  435.   P1=0xff;
  436.   P3=0x00;
  437.   P1=0xcf;
  438.   P3=0x20;
  439.   Delay_ms(1);
  440.   P1=0xff;
  441.   P3=0x00;
  442.   P1=0xcf;
  443.   P3=0x10;
  444.   Delay_ms(1);
  445.   P1=0xff;
  446.   P3=0x00;
  447.   P1=0xcf;
  448.   P3=0x08;
  449.   Delay_ms(1);
  450.   P1=0xff;
  451.   P3=0x00;
  452.   Delay_ms(100);
  453. //---------"E"--------------
  454.   P1=0x7f;
  455.   P3=0x80;
  456.   Delay_ms(1);
  457.   P1=0xff;
  458.   P3=0x00;
  459.   P1=0x7f;
  460.   P3=0x20;
  461.   Delay_ms(1);
  462.   P1=0xff;
  463.   P3=0x00;
  464.   P1=0x7f;
  465.   P3=0x10;
  466.   Delay_ms(1);
  467.   P1=0xff;
  468.   P3=0x00;
  469.   P1=0x7f;
  470.   P3=0x08;
  471.   Delay_ms(1);
  472.   P1=0xff;
  473.   P3=0x00;
  474.   Delay_ms(100);
  475. //---------"F"--------------
  476.   P1=0xfd;
  477.   P3=0x80;
  478.   Delay_ms(1);
  479.   P1=0xff;
  480.   P3=0x00;
  481.   P1=0xfd;
  482.   P3=0x20;
  483.   Delay_ms(1);
  484.   P1=0xff;
  485.   P3=0x00;
  486.   P1=0xfd;
  487.   P3=0x10;
  488.   Delay_ms(1);
  489.   P1=0xff;
  490.   P3=0x00;
  491.   P1=0xfd;
  492.   P3=0x08;
  493.   Delay_ms(1);
  494.   P1=0xff;
  495.   P3=0x00;
  496.   Delay_ms(100);
  497. //---------"G"--------------
  498.   P1=0xf7;
  499.   P3=0x80;
  500.   Delay_ms(1);
  501.   P1=0xff;
  502.   P3=0x00;
  503.   P1=0xf7;
  504.   P3=0x20;
  505.   Delay_ms(1);
  506.   P1=0xff;
  507.   P3=0x00;
  508.   P1=0xf7;
  509.   P3=0x10;
  510.   Delay_ms(1);
  511.   P1=0xf7;
  512.   P3=0x08;
  513.   P1=0xff;
  514.   P3=0x00;
  515.   Delay_ms(1);
  516.   P1=0x00;
  517.   P3=0xfc;
  518.   Delay_ms(100);
  519. //------------------------------
  520.   P1=0xff;
  521.   P3=0x00;
  522.   Delay_ms(200);
  523.   P1=0x00;
  524.   P3=0xfc;
  525.   Delay_ms(200);
  526. //------------------------------
  527.   P1=0x00;
  528.   P3=0x80;
  529.   Delay_ms(30);   //smg1
  530.   P1=0x00;
  531.   P3=0x20;
  532.   Delay_ms(30); //smg2
  533.   P1=0x00;
  534.   P3=0x10;
  535.   Delay_ms(30); //smg3
  536.   P1=0x00;
  537.   P3=0x08;  //smg4
  538.   Delay_ms(30);
  539.   P1=0x00;
  540.   P3=0xfc;
  541.   Delay_ms(200);
  542.   P1=0xff;
  543.   P3=0x00;
  544.   Delay_ms(200);
  545.   P1=0x00;
  546.   P3=0xfc;
  547.   Delay_ms(200);
  548. }
  549. void main(void)
  550. {
  551.    uint k;
  552.   Buz();Display_Scan();                                                                           
  553.    T0_ini();Clock_Prog();
  554.    while(1)
  555.    {
  556. ///*/-------------按鍵小于2次有分鐘睡眠模式-----------------
  557.    if(Hour==4)
  558.    {
  559.     EX0=1;
  560.     EA=1;
  561.     Key_flag=0;
  562.     Min_1=0;
  563.     Hour_1=0;                     
  564.     Signle=1;
  565.     TR0=1;
  566.     P1=0xff;
  567.     PCON=0x02;
  568.    }
  569. ////---------------------------------------------------------   */
  570.    //Clock_Prog();
  571.    if(Sec%5==0)
  572.    {  
  573.      //for(LM_GroupCNT=0;LM_GroupCNT<13;LM_GroupCNT++)//拉幕時鐘時分秒顯示
  574.     for(LM_GroupCNT=0;LM_GroupCNT<10;LM_GroupCNT++)
  575.     {
  576.      for(k=65500;k>0;k--)
  577.      {
  578.       CheckTime();
  579.      }
  580.     }
  581.    }
  582.    else
  583.    Display();
  584.    }
  585. }
復制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧洲精品码一区二区三区免费看 | 成人h视频在线 | 亚洲综合无码一区二区 | 亚洲精品国产成人 | 亚洲欧美国产一区二区三区 | 精品三区 | 国产视频在线观看一区二区三区 | 国产精品黄色 | 国产在线一级片 | 国产内谢 | 免费在线毛片 | 精品久久九 | 亚洲成人一级 | 在线观看国产 | 国产一区二区三区在线观看免费 | 亚洲不卡视频 | 一区二区在线 | 欧美久久久久久久 | 久久88 | 99久久夜色精品国产亚洲96 | 久久成人免费 | 亚洲精品免费在线观看 | 日本高清中文字幕 | 国产乱码精品一区二区三区忘忧草 | 91精品国模一区二区三区 | 欧美日韩在线一区二区三区 | 欧美美乳 | 国产精产国品一二三产区视频 | 日韩精品视频网 | 91精品国产综合久久婷婷香蕉 | 激情黄色在线观看 | 国产精品成人一区二区三区 | 亚洲精品中文字幕 | 国产成人精品久久二区二区91 | 一区二区在线免费观看 | 国产乱一区二区三区视频 | 久久精品亚洲精品国产欧美kt∨ | 精品欧美乱码久久久久久 | 日韩在线综合 | 久久三级av | 免费毛片网站在线观看 |