有些问题我都标到注释里面了,请大家帮我看看啊 好像是进不去中断。。不知道为什么 进不去T0的中断
#include <REG51.H> unsigned int r; unsigned char a,b,c,d; unsigned char code display[]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09}; void delay(); sbit P3_6=P3^6; sbit P1_0=P1^0; sbit P1_1=P1^1; sbit P0_0=P0^0; sbit P0_1=P0^1; sbit P0_2=P0^2; sbit P0_3=P0^3; long counter=0; //旋转编码器的脉冲计数值
void main()
{ TMOD=0x21; TH0=(65536-10000)/256; TL0=(65536-10000)%256; TR0=1; ET0=1; TH1=0xfd; TL1=0xfd; //波特率设置为9600 TR1=1;
SCON=0x50; PCON=0xef;
IT1 = 1; //外部中断1为边沿触发 EX1 = 1; //使能外部中断1 EA = 1; //使能中断 while(1) { if(P3_6==1) P1_0=0; else P1_1=0;
a=r%10; //执行到这里就执行不下去了, 为什么呢 b=(r/10)%10; c=(r/100)%10; d=(r/1000)%10;
P2=display[a]; P0_0=0; delay(); P2=0xff;
P2=display[c]; P0_2=0; delay(); P2=0xff;
P2=display[d]; P0_3=0; delay(); P2=0xff;
P2=display; P0_1=0; delay(); P2=0xff;
} }
void delay() { unsigned char i; for (i=0;i<50;i++); //延迟 50*8+10=410us
}
void int1() interrupt 2 //是否是interrupt 2 ?? { counter++; }
void t0_() interrupt 1 using 1 ////是否是interrupt 1 ?? { unsigned char h,rh,rl ; TH0=(65536-10000)/256; TL0=(65536-10000)%256; h++; if(h==100) {h=0; r=60*counter/500; counter=0; } rh=r<<8; rl=r&0x00ff; SBUF=rl; while(!TI); TI=0; SBUF=rh; while(!TI); TI=0; }
|