单片机中断的仿真电路图
仿真文件下载:http://www.51hei.com/bbs/dpj-50777-1.html
- /*
- 这段代码特别重要,有两个东西要记住‘
- 1是 不能给P3^2这种类型的变量赋值,只能给 P3赋值
- 2是 不能把P3^2Z这种类型的变量写到while(括号里),否则无论P3^2是等于0还是等于1都会出现死循环
- */
- #include <reg52.h>
- //共阳数码管显示0-9
- unsigned char DisNumber[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- char i = 0;
- void delay100ms(void) //误差 0us
- {
- unsigned char a,b,c;
- for(c=19;c>0;c--)
- for(b=20;b>0;b--)
- for(a=130;a>0;a--);
- }
- void INTERRUPT() interrupt 0 using 0
- {
- if (i < 9)
- i += 1;
- else
- i = 0;
- delay100ms();
- while (P3 == 0XFB); //如果写成 while (!P3^2)或者写成 while (P3^2) 死循环了,因为不管P3^2值是0还是1都会出现死循环
- }
- void main(void)
- {
- //P3 = 0XFF;
- EA = 1;
- EX0 = 1;
- IT0 = 0;
-
- while (1)
- P0 = DisNumber[i];
- }
- //小月子2016年5月21日编辑 如果您有什么不理解的地方请加小月子
- //小月子是个电子发烧友,小月子电子网店卖的是电子电路类、编程类学习资料教学视频
- //请关注我的网
复制代码
|