標題: 單片機按鍵中斷程序 [打印本頁]

作者: 1463307579    時間: 2020-5-7 10:16
標題: 單片機按鍵中斷程序
按鍵中斷
  1. #include<reg51.h>
  2. unsigned char code aaa[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  3. sbit K1=P3^7;
  4. sbit LED1=P2^0;
  5. void Delay(unsigned int a);
  6. void Delay10ms();
  7. unsigned char xx;
  8. void main()
  9. {
  10.   
  11.     IT0=1;
  12.         EX0=1;
  13.         IT1=1;
  14.         EX1=1;
  15.         EA=1;

  16.        
  17.   while(1)
  18.   {
  19.         if(xx==13)
  20.                 {
  21.                         xx=0;
  22.         }
  23.                 if(xx==255)
  24.                 {
  25.                         xx=12;
  26.                 }
  27.        
  28.         P2=aaa[xx/10];
  29.         P1=0xFE;
  30.         Delay(5);
  31.         P2=0x00;

  32.         P2=aaa[xx%10];
  33.         P1=0xFD;
  34.         Delay(5);
  35.         P2=0x00;
  36.             
  37.   }
  38. }
  39. void Int0() interrupt 0
  40.          {
  41.            Delay(1);
  42.            xx++;
  43.           
  44.          }
  45.          
  46. void Int1() interrupt 2
  47.          {
  48.            Delay(1);
  49.            xx--;
  50.           
  51.          }

  52.        
  53.          
  54. void Delay(unsigned int c)
  55.   {
  56.     unsigned char a,b;
  57.         for(;c>0;c--)
  58.             for(b=38;b>0;b--)
  59.                    for(a=130;a>0;a--);
  60.   }
復制代碼


按鍵中斷.zip

53.17 KB, 下載次數(shù): 5, 下載積分: 黑幣 -5

按鍵中斷






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