我是一个新手,现在想用单片机做一个东西,用到了两个外部中断和串口,现在仿真的时候中断老是出错,请高手指教:
#include <REG2051.H>
#define uint unsigned int
#define uchar unsigned char
float angle;
void delay(uint);
void main()
{
angle=0;
TMOD=0x20;
TH1=0xFD;
TL1=0XFD;
TR1=1;
SM0=0;
SM1=1;
EA=1;
EX0=1;
IT0=1;
EX1=1;
IT1=1;
PCON=0X00;
ES=1;
/* while(1)
{
ES=1;
delay(20);
ES=0;
} */
}
/*void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
} */
void intsvr0(void) interrupt 0 using 1
{
angle=angle+0.1;
}
void intsvr1(void) interrupt 2 using 1
{
if(angle>0)
angle=angle-0.1;
else
angle=angle+360.0-0.1;
}
void serial(void) interrupt 4 using 1
{
ES=0;
SBUF=angle;
while(!TI);
TI=0;
ES=1;
} |