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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3452|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

STC11F02E單鍵模式控制之折騰三

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:72519 發(fā)表于 2015-1-23 00:54 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
其實(shí),這個(gè)程序的主要看點(diǎn)是在拉幕部份,說(shuō)實(shí)話我也是通過(guò)不斷的調(diào)試和修改才編寫成功的,另外就是動(dòng)態(tài)掃描部份是見鑒別人的空間里面的,把它吸收消化了。中斷計(jì)時(shí)這部份程序的處理,對(duì)我來(lái)說(shuō)我已經(jīng)很成熟化了和老練了。
好了,不多說(shuō)了,上代碼了!
  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,Time_Count,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,BT_4Sec;
  22. //uchar Display_number[]={0xd7,0x14,0xcd,0x5d,0x1e,0x5b,0xdb,0x15,0xdf,0x5f,0x00};
  23. uchar code Display_number[]={0xff,0xff,0x28,0xeb,0x32,0xa2,0xe1,0xa4,0x24,0xea,0x20,0xa0,0xf7,0xff}; //0123456789 -
  24. uchar code Display_string[]={0xff,0xff,0xff,0xf7,0xeb,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//-1HZ-
  25. uchar code Display_string2[]={0xff,0xff,0xff,0xf7,0x32,0x61,0x32,0xf7,0xff,0xff,0xff,0xff,0xff,0xff};//-2HZ-
  26. uchar Clock[]={0xff,0xff,0xff,0xeb,0x32,0xf7,0xeb,0x32,0xf7,0xeb,0x32,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
  27. //---------------------------------------------------
  28. //---------------------------------------------------
  29. //4COM 共陽(yáng)數(shù)碼管 1234 SR410361K
  30. //---------------------------------------------------
  31. //P1.0 A;    |---|
  32. //P1.2 B;    |   |
  33. //P1.4 C;    |---|
  34. //P1.6 D;    |   |
  35. //P1.7 E;    |---|
  36. //P1.1 F;
  37. //P1.3 G;
  38. //P1.5 Dp;
  39. //SMG1=P3.7,SMG2=P3.5,SMG3=P3.4,SMG4=P3.3;
  40. //---------------------------------------------------
  41. //---------------------------------------------------
  42. void display_Scan(void);
  43. void Delay_ms();
  44. void Delay_ms(uint Tms)
  45. {
  46.   uint i,j;
  47.   for(i=Tms;i>0;i--)
  48.   for(j=1220;j>0;j--)
  49.   {;}
  50. }
  51. void Delay_us(uint Tus)
  52. {
  53.   while(--Tus);
  54. }
  55. void Buz(void)
  56.   {
  57.     uint i;
  58.     for(i=0;i<200;i++)
  59.     {
  60.       BUZ=~BUZ;
  61.      Delay_us(300);
  62.     }
  63.     BUZ=0;
  64.   }
  65. void Beep_Bi(void)
  66. {
  67.   if(Beep_time!=0)
  68.   {
  69.    Beep_time--;
  70.    BUZ=~BUZ;
  71.   }
  72.   else
  73.   {
  74.    BUZ=0;
  75.   }
  76. }
  77. void T0_ini()
  78. {
  79.    TMOD=0x12;
  80.   TH1=(65536-1000)/256;
  81.   TL1=(65536-1000)%256;
  82.   TR1=1;
  83.   ET1=1;
  84.   TH0=6;
  85.   TL0=6;
  86.   TR0=0;
  87.   ET0=1;
  88.   EA=1;
  89. }
  90. void TM0(void)interrupt 1
  91. {
  92.   //uint Time_Count,BTime_Count;
  93.   TF0=0;
  94.   Time_Count++;BTime_Count++;BP_Count++;
  95.   if(BTime_Count==1000)
  96.   {
  97.    BTime_Count=0;BT_Sec++;
  98.    if(BT_Sec==2)
  99.    {
  100.      BT_Sec=0;BTime_Flag=~BTime_Flag;BT_4Sec++;
  101.     if(BT_4Sec==8)
  102.     {
  103.      BT_4Sec=0;Key_Select=0;
  104.     }
  105.    }
  106.   }
  107.   if(BP_Count==2)      //1ms DiDa Batime;
  108.   {
  109.    BP_Count=0;
  110.    Beep_Bi();
  111.   }
  112.   if(Key_Select_Flag==1)   //1Hz
  113.   {
  114.    if(Time_Count==2000)
  115.    {
  116.     Time_Count=0;Dp=~Dp;Signle=~Signle;
  117.    }     
  118.   }

  119.   if(Key_Select_Flag==2)   //2Hz
  120.   {
  121.    if(Time_Count==1000)
  122.    {
  123.     Time_Count=0;Dp=~Dp;Signle=~Signle;
  124.    }
  125.   }
  126.     //if(Time_Count==2000) // ext atxl 12MHz;500ms
  127.   //if(Time_Count==1333) // ext atxl 8MHz 500ms;
  128.   //if(Time_Count==998) // built in atxl; 500ms
  129. }
  130. void TM1(void)interrupt 3
  131. {
  132.   TH1=(65536-1000)/256;
  133.   TL1=(65536-1000)%256;
  134.   Led_Scan=1;Led_Loop++;Led_Loop=Led_Loop&0x03;
  135.       
  136.     Key1=1;
  137.     if(Key1==0)
  138.     {
  139.      Key_count++;
  140.    if(Key_count==20)
  141.    {
  142.      Beep_time=100;Key_flag=1;
  143.      TR0=1;Key_Select++;
  144.      if(Key_Select==3)
  145.      {
  146.       Key_Select=0;Key_flag=0;TR0=1;
  147.      }
  148.        if(Key_Select==1)
  149.      {
  150.     BTime_Count=0;BT_Sec=0;BT_4Sec=0;Time_Count=0;
  151.     Key_Select_Flag=0;Key_Select_Flag=1;
  152.      }
  153.     if(Key_Select==2)
  154.      {
  155.     BTime_Count=0;BT_Sec=0;BT_4Sec=0;Time_Count=0;
  156.     Key_Select_Flag=0;Key_Select_Flag=2;
  157.         }   
  158.    }
  159.   }
  160.      else
  161.    {Key_count=0;Key_long_flag=0;}
  162.    }
  163.   void SmgDisp(uchar ch,uchar num)
  164.   {
  165.   uchar number;
  166.   number=num;
  167.   //P3=0x03;
  168.   P1=0xff;
  169.   SMG1=0;SMG2=0;SMG3=0;SMG4=0;
  170.   switch(ch)
  171.   {
  172.    case 1:SMG4=1;LM_Count=0;break;    //SMG排列 1 2 3 4 第四個(gè)數(shù)碼管
  173.    case 2:SMG3=1;LM_Count++;break;    //SMG排列 1 2 3 4 第三個(gè)數(shù)碼管
  174.    case 3:SMG2=1;LM_Count++;break;    //SMG排列 1 2 3 4 第二個(gè)數(shù)碼管
  175.    case 4:SMG1=1;LM_Count++;break;    //SMG排列 1 2 3 4 第一個(gè)數(shù)碼管
  176.    default:break;
  177.   }
  178.   if((Key_Select==0)&(Key_Select_Flag==1))
  179.   {
  180.    P1=Display_string[number];
  181.   }
  182.   else if((Key_Select==0)&(Key_Select_Flag==2))
  183.   {
  184.    P1=Display_string2[number];
  185.   }
  186.   else
  187.    P1=Display_number[number];
  188.   }
  189.   void CheckTime()
  190.   {
  191.   if(Led_Scan)
  192.   {
  193.    switch(Led_Loop)
  194.    {
  195.     case 0:SmgDisp(4,LM_Count+LM_GroupCNT);break; //第一個(gè)數(shù)碼管
  196.     case 1:SmgDisp(3,LM_Count+LM_GroupCNT);break; //第二個(gè)數(shù)碼管
  197.     case 2:SmgDisp(2,LM_Count+LM_GroupCNT);break; //第三個(gè)數(shù)碼管
  198.     case 3:SmgDisp(1,LM_Count+LM_GroupCNT);break; //第四個(gè)數(shù)碼管
  199.    }
  200.      Led_Scan=0;
  201.   }
  202.   }
  203.   
  204. void Display(void)
  205. {
  206.   if((BTime_Flag)&(Key_Select==1))
  207.    {
  208.    P1=0xff;SMG1=0;SMG2=0;SMG3=0;SMG4=0;
  209.              //P3=0x00;
  210.   }
  211.   else
  212.   {
  213.    if(BTime_Flag)
  214.   {
  215.    Dp=0;SMG1=1;       //P3=0x80;
  216.    Delay_ms(1);SMG1=0;      //P3=0x00;
  217.    Dp=0;SMG2=1;       //P3=0x20;
  218.    Delay_ms(1);SMG2=0;      //P3=0x00;
  219.   }
  220.   P1=Display_string[4];
  221.    SMG1=1;          //P3=0x80;
  222.   Delay_ms(1);
  223.    SMG1=0;          //P3=0x00;
  224.    P1=0xff;
  225.   P1=Display_string[5];
  226.    SMG2=1;          //P3=0x20;
  227.    Delay_ms(1);
  228.    SMG2=0;          //P3=0x00;
  229.    P1=0xff;
  230.   }
  231.   if((BTime_Flag)&(Key_Select==2))
  232.    {
  233.    P1=0xff;SMG1=0;SMG2=0;SMG3=0;SMG4=0; //P3=0x00;
  234.   }
  235.   else
  236.   {
  237.    if(BTime_Flag)
  238.   {
  239.    Dp=0;SMG3=1;       //P3=0x10;
  240.    Delay_ms(1);SMG3=0;      //P3=0x00;
  241.    Dp=0;SMG4=1;       //P3=0x08;
  242.    Delay_ms(1);SMG4=0;      //P3=0x00;
  243.   }
  244.   P1=Display_string2[4];
  245.    SMG3=1;          //P3=0x10;
  246.    Delay_ms(1);
  247.    SMG3=0;          //P3=0x00;
  248.   P1=0xff;
  249.   P1=Display_string2[5];
  250.    SMG4=1;          //P3=0x08;
  251.    Delay_ms(1);
  252.    SMG4=0;          //P3=0x00;
  253.    P1=0xff;
  254.   }
  255. }
  256. void exint0(void)interrupt 0
  257. {
  258.   Buz();T0_ini();EX0=0;EA=1;
  259. }
  260.   
  261. void Display_Scan(void)
  262. {  
  263.   P1=0x00;
  264.   P3=0x00;
  265. //---------"A"--------------p1.0
  266.   //P1=0x01;
  267.   P1=0xfe;
  268.   P3=0x80;   //smg1
  269.   Delay_ms(5);
  270.   P1=0xff;
  271.   P3=0x00;
  272.   P1=0xfe;
  273.   P3=0x20;   //smg2
  274.   Delay_ms(5);
  275.   P1=0xff;
  276.   P3=0x00;
  277.   P1=0xfe;
  278.   P3=0x10;   //smg3
  279.   Delay_ms(5);
  280.   P1=0xff;
  281.   P3=0x00;
  282.   P1=0xfe;
  283.   P3=0x08;   //smg4
  284.   Delay_ms(5);
  285.   P1=0xff;
  286.   P3=0x00;
  287.   P1=0xfe;
  288.   P3=0x40;
  289.   Delay_ms(250);
  290. //---------"B"--------------p1.2
  291.   P1=0xfb;
  292.   P3=0x80;
  293.   Delay_ms(5);
  294.   P1=0xff;
  295.   P3=0x00;
  296.   P1=0xfb;
  297.   P3=0x20;
  298.   Delay_ms(5);
  299.   P1=0xff;
  300.   P3=0x00;
  301.   P1=0xfb;
  302.   P3=0x10;
  303.   Delay_ms(5);
  304.   P1=0xff;
  305.   P3=0x00;
  306.   P1=0xfb;
  307.   P3=0x08;
  308.   Delay_ms(5);
  309.   P1=0xff;
  310.   P3=0x00;
  311.   P1=0xfb;
  312.   P3=0x40;
  313.   Delay_ms(250);
  314. //---------"C"--------------p1.4
  315.   //P1=0x10;
  316.   P1=0xef;
  317.   P3=0x80;
  318.   Delay_ms(5);
  319.   P1=0xff;
  320.   P3=0x00;
  321.   P1=0xef;
  322.   P3=0x20;
  323.   Delay_ms(5);
  324.   P1=0xff;
  325.   P3=0x00;
  326.   P1=0xef;
  327.   P3=0x10;
  328.   Delay_ms(5);
  329.   P1=0xff;
  330.   P3=0x00;
  331.   P1=0xef;
  332.   P3=0x08;
  333.   Delay_ms(5);
  334.   P1=0xff;
  335.   P3=0x00;
  336.   P1=0xef;
  337.   P3=0x40;
  338.   Delay_ms(250);
  339. //---------"D"--------------p1.6
  340. //-----p1.7 p1.6 p1.5 p1.4 p1.3 p1.2 p1.1 p1.0---//
  341. //-------1011 1111-------------------------------//
  342.   P1=0xbf;
  343.   P3=0x80;
  344.   Delay_ms(5);
  345.   P1=0xff;
  346.   P3=0x00;
  347.   P1=0xbf;
  348.   P3=0x20;
  349.   Delay_ms(5);
  350.   P1=0xff;
  351.   P3=0x00;
  352.   P1=0xbf;
  353.   P3=0x10;
  354.   Delay_ms(5);
  355.   P1=0xff;
  356.   P3=0x00;
  357.   P1=0xbf;
  358.   P3=0x08;
  359.   Delay_ms(5);
  360.   P1=0xff;
  361.   P3=0x00;
  362.   P1=0xbf;
  363.   P3=0x40;
  364.   Delay_ms(250);
  365. //---------"E"--------------p1.7
  366.   P1=0x7f;
  367.   P3=0x80;
  368.   Delay_ms(5);
  369.   P1=0xff;
  370.   P3=0x00;
  371.   P1=0x7f;
  372.   P3=0x20;
  373.   Delay_ms(5);
  374.   P1=0xff;
  375.   P3=0x00;
  376.   P1=0x7f;
  377.   P3=0x10;
  378.   Delay_ms(5);
  379.   P1=0xff;
  380.   P3=0x00;
  381.   P1=0x7f;
  382.   P3=0x08;
  383.   Delay_ms(5);
  384.   P1=0xff;
  385.   P3=0x00;
  386.   P1=0x7f;
  387.   P3=0x40;
  388.   Delay_ms(250);
  389. //---------"F"--------------p1.1
  390.   P1=0xfd;
  391.   P3=0x80;
  392.   Delay_ms(5);
  393.   P1=0xff;
  394.   P3=0x00;
  395.   P1=0xfd;
  396.   P3=0x20;
  397.   Delay_ms(5);
  398.   P1=0xff;
  399.   P3=0x00;
  400.   P1=0xfd;
  401.   P3=0x10;
  402.   Delay_ms(5);
  403.   P1=0xff;
  404.   P3=0x00;
  405.   P1=0xfd;
  406.   P3=0x08;
  407.   Delay_ms(5);
  408.   P1=0xff;
  409.   P3=0x00;
  410.   P1=0xfd;
  411.   P3=0x40;
  412.   Delay_ms(250);
  413. //---------"G"--------------p1.3
  414.   P1=0xf7;
  415.   P3=0x80;
  416.   Delay_ms(5);
  417.   P1=0xff;
  418.   P3=0x00;
  419.   P1=0xf7;
  420.   P3=0x20;
  421.   Delay_ms(5);
  422.   P1=0xff;
  423.   P3=0x00;
  424.   P1=0xf7;
  425.   P3=0x10;
  426.   Delay_ms(5);
  427.   P1=0xff;
  428.   P3=0x00;
  429.   P1=0xf7;
  430.   P3=0x08;
  431.   Delay_ms(5);
  432.   P1=0xff;
  433.   P3=0x00;
  434.   P1=0xf7;
  435.   P3=0x40;
  436. //------------------------------
  437.   P1=0x00;
  438.   P3=0xfc;
  439.   Delay_ms(500);
  440. //------------------------------
  441.   P1=0x00;
  442.   P3=0x80;
  443.   Delay_ms(100);   //smg1
  444.   P1=0x00;
  445.   P3=0x20;
  446.   Delay_ms(100); //smg2
  447.   P1=0x00;
  448.   P3=0x10;
  449.   Delay_ms(100); //smg3
  450.   P1=0x00;
  451.   P3=0x08;  //smg4
  452.   Delay_ms(100);
  453.   P1=0x00;
  454.   P3=0xfc;
  455.   Delay_ms(250);
  456.   P1=0xff;
  457.   P3=0x00;
  458.   Delay_ms(250);
  459.   P1=0x00;
  460.   P3=0xfc;
  461.   Delay_ms(250);
  462. }
  463. void main(void)
  464. {
  465.    uint k;
  466.   Buz();Display_Scan();                                                                           
  467.    T0_ini();
  468.    while(1)
  469.    {
  470. ///*/-------------按鍵小于2次有分鐘睡眠模式-----------------
  471.    if(Hour==4)
  472.    {
  473.     EX0=1;
  474.     EA=1;
  475.     Key_flag=0;
  476.     Min_1=0;
  477.     Hour_1=0;                     
  478.     Signle=1;
  479.     TR0=1;
  480.     P1=0xff;
  481.     PCON=0x02;
  482.    }
  483. ////---------------------------------------------------------   */
  484.    if(Key_Select==0)
  485.    {  
  486.      //for(LM_GroupCNT=0;LM_GroupCNT<13;LM_GroupCNT++)//拉幕時(shí)鐘時(shí)分秒顯示
  487.     for(LM_GroupCNT=0;LM_GroupCNT<10;LM_GroupCNT++)
  488.     {
  489.      for(k=65500;k>0;k--)
  490.      {
  491.       CheckTime();
  492.      }
  493.     }
  494.    }
  495.    else
  496.    Display();
  497.    }
  498. }
復(fù)制代碼



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

使用道具 舉報(bào)

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 日韩av啪啪网站大全免费观看 | 色网站入口 | 影音先锋中文字幕在线观看 | 亚洲成人一区 | 99久久婷婷国产亚洲终合精品 | 夜夜久久 | 久久久久无码国产精品一区 | 久久精品视频在线观看 | 午夜精品一区二区三区三上悠亚 | 久久精品亚洲精品国产欧美 | 特级特黄特色的免费大片 | 色视频欧美| 孕妇一级毛片 | 天天干在线播放 | 国产在线视频一区二区董小宛性色 | 欧美精品一区二区三区一线天视频 | 精品视频一区二区三区在线观看 | 看毛片网站 | 亚洲精品在线观 | 欧美综合一区二区三区 | 精品欧美乱码久久久久久1区2区 | 亚洲a毛片| 欧美日韩一二区 | 夜夜骑首页 | 精品久久久久久18免费网站 | 精品欧美激情在线观看 | 99re在线视频观看 | 香蕉视频一区二区 | 国产成人99久久亚洲综合精品 | 毛片视频网站 | 欧美三区在线观看 | 99热精品在线观看 | 成人精品视频在线观看 | 一区二区三区在线免费观看 | 成人网在线观看 | 国产成人精品一区二区三区在线 | av中文在线 | 激情欧美日韩一区二区 | 草草草草视频 | 久久久久久99 | 欧美视频在线播放 |