欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 單片機外部中斷按鍵次數(shù)統(tǒng)計顯示程序+Proteus仿真 [打印本頁]

作者: 1001du    時間: 2019-6-10 10:22
標題: 單片機外部中斷按鍵次數(shù)統(tǒng)計顯示程序+Proteus仿真
單片機外部中斷按鍵次數(shù)統(tǒng)計仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機源程序如下:
  1. #include <reg51.h>
  2. #include <intrins.h>
  3. // 1 外部中斷0初始化 2 中斷函數(shù)統(tǒng)計按鍵次數(shù)
  4. // 3 顯示按鍵次數(shù)
  5. #define SEG1 P1
  6. #define SEG2 P2
  7. #define SEG0 P0
  8. //共陽極數(shù)碼管                                   //0    1    2    3    4    5    6    7    8    9    A    b    C    d    e    F
  9. unsigned char code DIG_CODE_CA[16]={0xC0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};//共陽極數(shù)碼管
  10. //共陰極數(shù)碼管                                   //0    1    2    3    4    5    6    7    8    9    A    b    C    d    e    F
  11. unsigned char code DIG_CODE_CC[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//共陰極數(shù)碼管
  12. sbit Key3=P3^2;
  13. sbit Key4=P3^3;
  14. unsigned int Num0=0;
  15. unsigned int Num1=0;
  16. //子函數(shù)
  17. void Delay1ms();
  18. void DelayNms(unsigned int n);
  19. //主函數(shù)
  20. void main()
  21. {
  22.         //1 外部中斷0 1初始化
  23.         IT0=1;IT1=1;//TCON = 0x05;
  24.         EA=1;EX0=1;EX1=1;//IE=0x85;
  25.         while(1)
  26.         {
  27.                 // 3 顯示按鍵次數(shù)
  28.                 if(Num0==100)Num0=0;
  29.                 SEG1=DIG_CODE_CC[Num0/10];
  30.                 SEG2=DIG_CODE_CC[Num0%10];
  31.                 if(Num1==10)Num1=0;
  32.                 SEG0=DIG_CODE_CC[Num1];
  33.         }
  34. }
  35. //2 外部中斷0中斷函數(shù) 統(tǒng)計按鍵key3次數(shù)
  36. void INT0_ISR() interrupt 0
  37. {
  38.         DelayNms(10);
  39.         if(Key3==0)
  40.                 Num0++;
  41. }
  42. //2 外部中斷1中斷函數(shù) 統(tǒng)計按鍵key4次數(shù)
  43. void INT1_ISR() interrupt 2
  44. {
  45.         DelayNms(10);
  46.         if(Key4==0)
  47.                 Num1++;
  48. }
  49. //子函數(shù)聲明
  50. void Delay1ms()                //@12.000MHz
  51. {
  52.         unsigned char i, j;

  53.         i = 2;
  54.         j = 239;
  55.         do
  56.         {
  57.                 while (--j);
  58.         } while (--i);
  59. }
  60. void DelayNms(unsigned int n)
  61. {
  62.         while(n--)
  63.         Delay1ms();
  64. }
復制代碼

所有資料51hei提供下載:
外部中斷按鍵次數(shù)統(tǒng)計.rar (55.72 KB, 下載次數(shù): 18)






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