??? 04/20/05 20:13 Read: times |
#92014 - DS89C450 / uVision2, timer0 trouble |
Hello All,
I've run into some problems while trying to implement a simple delay-routing on my DS89C450. After having peeked into various application notes and having tried out the code therein with no immediate success, I ventured on to my current, rather simple approach. Below you will find my source code - I hope I am not offending anyone by posting it in the message - and the problematic part is that when it is flashed into the micro, the if-statements determining the current time and incrementing seconds, minutes and hours are left untouched, whereas in the simulator they work. /Thomas #include <REG420.H> char timer0_tick; int secs,mins,hrs; void timer0_isr(void) interrupt 1 { timer0_tick++; P1 ^= 0x80; return; } void timer0_initialize(void) { EA = 0; /* disable interrupts */ TMOD = (TMOD & 0xF0) | 0x01; /* Set T/C0 Mode */ CKCON = (CKCON & ~0x03); /* Select external oscillator as source */ CKMOD = (CKMOD & ~0x03); /* Select external oscillator as source */ TMOD = (TMOD & ~0x02); /* Select external oscillator as source */ ET0 = 1; /* Enable Timer 0 Interrupts */ TR0 = 1; /* Start Timer 0 Running */ EA = 1; /* enable interrupts */ return; } void init(void) { timer0_tick = 0; timer0_initialize(); secs, mins, hrs = 0; P0 = P1 = P2 = P3 = 0x00; return; } void main(void) { init(); while(1) { if(timer0_tick == 14) { secs++; timer0_tick = 0; P1 ^= 0x01; } if(secs == 60) { secs = 0; mins++; P1 ^= 0x02; } if(mins == 60) { mins = 0; hrs++; P1 ^= 0x04; } if(hrs == 24) { hrs = 0; P1 ^= 0x08; } } } |