標(biāo)題: 單片機(jī)按鍵控制中斷時(shí)鐘源程序 [打印本頁(yè)]

作者: shengwuben    時(shí)間: 2018-1-24 22:12
標(biāo)題: 單片機(jī)按鍵控制中斷時(shí)鐘源程序
按鍵控制中斷時(shí)鐘
單片機(jī)源程序如下:
  1. #include"STC15F2K60S2.H"
  2. #include"INTRINS.H"

  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. #define dula 0xef
  6. #define wela 0xcf
  7. uchar gang = 0xbf;
  8. uchar temp,num;
  9. uchar shi=11,fen=0,miao=11;
  10. uchar code table[]=
  11. {
  12.         0xc0,0xf9,0xa4,0xb0,0x99,
  13.         0x92,0x82,0xf8,0x80,0x90       
  14. };
  15. uchar code table1[]=
  16. {
  17.         0x01,0x02,0x04,0x08,
  18.         0x10,0x20,0x40,0x80
  19. };
  20. void Delay1ms(uint m)                //@11.0592MHz
  21. {
  22.         unsigned char i, j;
  23.         uint z;
  24.         for(z=m;z>0;z--)
  25.         {
  26.         _nop_();
  27.         _nop_();
  28.         _nop_();
  29.         i = 11;
  30.         j = 190;
  31.         do
  32.         {
  33.                 while (--j);
  34.         } while (--i);
  35.         }
  36. }

  37. void show()
  38. {
  39.         P2 = ((P2&0x1f)|dula);
  40.         P0 = table[shi/10];
  41.         P2 &= 0x1f;
  42.         P2 = ((P2&0x1f)|wela);                  //shi
  43.         P0 = table1[0];
  44.         P2 &= 0x1f;
  45.         Delay1ms(1);

  46.         P2 = ((P2&0x1f)|dula);
  47.         P0 = table[shi%10];
  48.         P2 &= 0x1f;                                          //shi
  49.         P2 = ((P2&0x1f)|wela);
  50.         P0 = table1[1];
  51.         P2 &= 0x1f;
  52.         Delay1ms(1);

  53.         P2 = ((P2&0x1f)|dula);
  54.         P0 = gang;
  55.         P2 &= 0x1f;                                                //-
  56.         P2 = ((P2&0x1f)|wela);
  57.         P0 = table1[2];
  58.         P2 &= 0x1f;
  59.         Delay1ms(1);


  60.         P2 = ((P2&0x1f)|dula);
  61.         P0 = table[fen/10];
  62.         P2 &= 0x1f;                                                 //fen
  63.         P2 = ((P2&0x1f)|wela);
  64.         P0 = table1[3];
  65.         P2 &= 0x1f;
  66.         Delay1ms(1);

  67.         P2 = ((P2&0x1f)|dula);
  68.         P0 = table[fen%10];                                   //fen
  69.         P2 &= 0x1f;
  70.         P2 = ((P2&0x1f)|wela);
  71.         P0 = table1[4];
  72.         P2 &= 0x1f;
  73.         Delay1ms(1);

  74.         P2 = ((P2&0x1f)|dula);
  75.         P0 = gang;
  76.         P2 &= 0x1f;                                                        //-
  77.         P2 = ((P2&0x1f)|wela);
  78.         P0 = table1[5];
  79.         P2 &= 0x1f;
  80.         Delay1ms(1);

  81.         P2 = ((P2&0x1f)|dula);
  82.         P0 = table[miao/10];                                  //miao
  83.         P2 &= 0x1f;
  84.         P2 = ((P2&0x1f)|wela);
  85.         P0 = table1[6];
  86.         P2 &= 0x1f;
  87.         Delay1ms(1);

  88.         P2 = ((P2&0x1f)|dula);                                //miao
  89.         P0 = table[miao%10];
  90.         P2 &= 0x1f;
  91.         P2 = ((P2&0x1f)|wela);
  92.         P0 = table1[7];
  93.         P2 &= 0x1f;
  94.         Delay1ms(1);


  95.        
  96. }
  97. void show_1()
  98. {
  99.         P2 = ((P2&0x1f)|0x80);
  100.         P0 = 0xff;
  101.         P2 &= 0x1f;
  102.         Delay1ms(1);
  103. }
  104. void init()
  105. {
  106.         TMOD = 0X01;
  107.         TL0 = 0X00;
  108.         TH0 = 0X4C;
  109.         TR0 = 1;
  110.         ET0 = 1;
  111.         EA = 1;

  112. }
  113. void key()
  114. {
  115.         if(P30==0)
  116.         {
  117.                 EA = 0;
  118.                 Delay1ms(20);
  119.                
  120.                 if(P30==0)
  121.                 {       
  122.                         while(!P30);
  123.                         fen++;
  124.                         if(fen==60)
  125.                         {
  126.                                         fen=0;
  127.                                         shi++;                               
  128.                         }
  129.                 }
  130.        

  131.         }
  132.         if(P31==0)
  133.         {
  134.                 EA = 0;
  135.                 Delay1ms(20);
  136.                 if(P31==0)
  137.                         {
  138.                         while(!P31);
  139.                                 fen--;                       
  140.                                 if(fen==-1)
  141.                                 {
  142.                                         fen=59;
  143.                                         shi--;
  144.                                 }
  145.                         }

  146.                 }

  147.         if(P32==0)
  148.         {
  149.                 EA=1;
  150.                 while(!P32);
  151.                 Delay1ms(1);
  152.         }
  153. }
  154. void main()
  155. {
  156.         show_1();
  157.         init();
  158.         while(1)
  159.         {
  160.                 show();
  161.                 key();       
  162.         }
  163. }
  164. void time() interrupt 1
  165. {
  166.         TL0 = 0X00;
  167.         TH0 = 0X4C;
  168.         temp++;
  169.        

  170.         if(temp==20)
  171.         {
  172.                 temp=0;
  173. ……………………

  174. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
按鍵控制中斷時(shí)鐘.rar (30.59 KB, 下載次數(shù): 12)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1