#define OSC_FREQ 12000000 #define C1ms (65536-OSC_FREQ/(12000000/980)) //考虑重装时时间上的误差,将1000调整为980 unsigned int ms, second; void main() { DelayXms(60000); //延时6s DelayXms(6); //延时6ms } void DelayXms(unsigned long z) { second=0; ms=0; TMOD=TMOD&(0x0f)|0x10; EA=1; ET1=1; TR1=1; do { } while (second*1000+ms<z); TR1=0; second=0; ms=0; }
void timer1(void) interrupt 3 using 3 { TH1=C1ms/256; TL1=C1ms%256; if(ms>=1000) { ms=0; if(second>=60) { second=0; } else{ second++; } } else{ ms++; } } |