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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/18/05 07:13
Read: times


 
#99622 - my timer dosen't work.
hi all.

I am working on 8051 core at a very beginer level, so I need some time to develope myself.

currently I am facing a problem with my followin code. So can any body help me.
The code is very simple just I am toggling a LED at one of the port pin every time the timer overflows and the for loop gets completaed.But it turns ON only once, and its not repeating at all.
After compiling it in keil it dosen't show any errors or warnings as such. I really don't know where is the problem.

--------------code with ISR-----------
#include<8051.h>
#include<stdio.h>

sbit LED=P2^0;
void starttimer();
unsigned int j=2;
static unsigned int count=0;
static unsigned char flag=1;

void main(void)
{
EA=1; // enable all interrupts.
ET0=1; // enable timer 0 interrupt.
LED=1;
while(1)
{
while(count < j)
{
if(flag)
starttimer();
flag=0;
LED=~(LED);
}


}
}

void starttimer()
{
TMOD = 0X01; // set mode 01 for timer.
TH0 = 0X3C; //load count in timer0 to generate 50ms delay.
TL0 = 0XAF;
TR0 = 1; // Start Timer0

}
//---------------------------------------

void timer0_ISR0 (void)interrupt 1
{
TF0 =0;
count++;
flag=1;
}

//-----------------------------


Or can anybody tell me the simplest Way of getting the accurate delay for 1 or >1 seconds,using a normal 8051 timers in 16 bit timer mode.



List of 4 messages in thread
TopicAuthorDate
my timer dosen't work.            01/01/70 00:00      
   Missing brackets            01/01/70 00:00      
   Critical error            01/01/70 00:00      
   This works for me.            01/01/70 00:00      

Back to Subject List