Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/16/06 07:17
Read: times


 
#118390 - Timer0_ISR delay troubles
I'm trying to make a fairly simple alarm clock for a school project. I am trying to use the 8051 timer 0 in 16 bit auto-reload mode to keep time. I figured out a timer seed for 10 millis and put it into the auto reload vars (I'm using Keil C51). The problem is that when I try to have the timer0_isr handle the time incrementing it takes way longer than if I have another function handle it...not good. I need to have the interrupt handle the time incrementing so I can have the user do other functions and still have the device keep time. Here's some code:

--------------
Works:

int count = 0;
int seconds = 0;
void foo(void) {
count++;
if (count == 100) {
seconds++;
count = 0;
}
}

void main(void) {
unsigned short seed = 55536;
while(1) {
TMOD = 1;
TR0 = 0;
TH0 = seed >> 8;
TL0 = seed & 0xff;
TF0 = 0;
TR0 = 1;
while(!TF0);
foo();
}
}

----------------
Doesn't work (seconds take about 2.5 seconds to increment):

int count = 0, seconds = 0;
void timer0_ISR (void) interrupt 1 {
if (count == 100) {
seconds++;
count = 0;
}
count++;
}

void main(void) {
unsigned short seed = 55536;
TMOD = 1;
TR0 = 0;
TH0 = seed >> 8;
TL0 = seed & 0xff;
TF0 = 0;
TR0 = 1;
EA = 1;
ET0 = 1;
while(1);
}

List of 19 messages in thread
TopicAuthorDate
Timer0_ISR delay troubles            01/01/70 00:00      
   Why it doesn't work            01/01/70 00:00      
      Extra Atomic            01/01/70 00:00      
   Been there Done That            01/01/70 00:00      
   Yes,very atomic            01/01/70 00:00      
      nuclear explosions            01/01/70 00:00      
   Also            01/01/70 00:00      
      Thanks everyone            01/01/70 00:00      
         learn to swim before diving in            01/01/70 00:00      
         using 1            01/01/70 00:00      
            Some code from the prof broke interrupt            01/01/70 00:00      
               Nevermind            01/01/70 00:00      
               which it is not            01/01/70 00:00      
                  Explain?            01/01/70 00:00      
   What happend to common sense?            01/01/70 00:00      
      specific examples are dangerous            01/01/70 00:00      
      Uncommon Sense            01/01/70 00:00      
         Practical programming            01/01/70 00:00      
            Charles            01/01/70 00:00      

Back to Subject List