標(biāo)題: 單片機(jī)兩個(gè)外部中斷控制計(jì)數(shù)和清零仿真電路和源碼 [打印本頁(yè)]

作者: 我去去去    時(shí)間: 2018-5-28 18:17
標(biāo)題: 單片機(jī)兩個(gè)外部中斷控制計(jì)數(shù)和清零仿真電路和源碼
簡(jiǎn)單的運(yùn)用外部中斷的仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. #include<reg51.h>
  2. #include<intrins.h>
  3. #define uchar unsigned char
  4. #define uint unsigned int
  5. uchar code SMG[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,
  6.                     0x6f,0x00};//共陰段碼,最后一位為數(shù)碼管不顯示
  7. uchar Display_Smg[4] = {0,0,0,0}; //計(jì)數(shù)值分解后的各待顯示數(shù)位
  8. uchar Dis_Buffer[4]; //顯示緩沖,用于存放待顯示的數(shù)字的段碼
  9. uint Count = 0;
  10. sbit Key_Clear = P3^6;
  11. void delay(uchar t)
  12. {
  13.         uchar i;
  14.         while(t--) for(i = 0;i < 120;i++);
  15. }
  16. void Display_Count()
  17. {
  18.         static uchar Scan_Bit = 0xF7;
  19.         static uchar Dsy_Idx = 0;
  20.         uchar i;
  21.         Display_Smg[3] = Count /1000;//取千位
  22.         Display_Smg[2] = Count /100%10;//取百位
  23.         Display_Smg[1] = Count % 100/10;
  24.         Display_Smg[0] = Count % 10;
  25.         for(i = 0; i < 4;i++)
  26.         {
  27.                 Dis_Buffer[i] = SMG[Display_Smg[i]];
  28.         }
  29.         P2 = Scan_Bit;
  30.         P0 = Dis_Buffer[Dsy_Idx];
  31.         delay(1);
  32.         Scan_Bit = _cror_(Scan_Bit,1);
  33.         Dsy_Idx = (Dsy_Idx+1)%4;
  34. }
  35. void main()
  36. {
  37.         EA = 1;
  38.         EX0 = 1;
  39.         EX1 = 1;
  40.         IT0 = 1;
  41.         IT1 = 1;
  42.         while(1)
  43.         {
  44.                 if(Count == 10000) Count = 0;
  45.     Display_Count();
  46.         }
  47. }
  48. void jishu() interrupt 0
  49. {
  50.         Count++;
  51. }
  52. void clear0() interrupt 2
  53. {
  54.         Count = 0;
  55. }
復(fù)制代碼

所有資料51hei提供下載:
兩個(gè)外部中斷控制計(jì)數(shù)和清零.zip (59.21 KB, 下載次數(shù): 25)







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