#include <AT89x52.h> //#include <reg52.h> #define uchar unsigned char
#define uint unsigned int uchar data one_sec; uint data time; //sfr T2MOD=0XC9; void delay(uint t) { IE=0; //禁止所有中断 T2MOD=0X00; TCON=0; //所有中断标志清0 T2CON=0x00; ET2=1; //允许T2中断 TH2=-46080/256; TL2=-46080%256; RCAP2H=TH2; RCAP2L=TL2; one_sec=20; time=t; TR2=1; //启动T2定时 EA=1; //CPU开中断 while(time!=0); TR2=0; EA=0; }
void timer2(void) interrupt 5 { TF2=0; one_sec--; if(one_sec==0) { one_sec=20; time--; } }
void main() { delay(1000); while(1); }
为什么退出来的时候time=0x00ff.太想不通了。 |