前辈,这就是我的测试程序,就是把外部中断的脉冲数显示到开发板的数码管上,结果脉冲数一直在增加。
- #include<reg52.h>
- sbit ADDR0=P1^0;
- sbit ADDR1=P1^1;
- sbit ADDR2=P1^2;
- sbit ADDR3=P1^3;
- sbit ENLED=P1^4;
- unsigned char code LedChar[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
- unsigned char LedBuff[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
- unsigned long second=0;
- unsigned int count=0;
- unsigned char i=0;
- bit dir=0;
- unsigned int count1;
- void main()
- {
- ENLED=0;
- ADDR3=1;
-
- EA=1;
- TMOD&=0xF0;
- TMOD|=0x01;
- TH0=0xFC;
- TL0=0x67;
- ET0=1;
- TR0=1;
- EX0=1;
- IT0=1;
- while(1)
- {
- if(dir)
- {
- dir=0;
- LedBuff[0]=LedChar[count1%10];
- LedBuff[1]=LedChar[count1/10%10];
- LedBuff[2]=LedChar[count1/100%10];
- LedBuff[3]=LedChar[count1/1000%10];
- LedBuff[4]=LedChar[count1/10000%10];
- LedBuff[5]=LedChar[count1/100000%10];
- }
- }
- }
- void InterruptTimer0() interrupt 1
- {
- TH0=0xFC;
- TL0=0x67;
- count++;
- if(count>=1000)
- {
- count=0;
- dir=1;
- }
- P0=0xFF;
- P1=(P1&0xF8)|i;
- P0=LedBuff[i];
- if(i<5) i++;
- else i=0;
- }
- void OutTimer0() interrupt 0
- {
- count1++;
- }
复制代码 |