timer delay in 8051 (1 second)
Discussion in "8051 Discussion Forum" started by sachinmm Jun 27, 2015.
Sat Jun 27 2015, 10:39 am
how calculate 1 second delay in 8051 by using timer and what value should be store in TH0 & TLO register??
Tue Jun 30 2015, 11:15 pm
The 8051 timer can't do 1 second.
It can do 50ms, so set up the interrupt handler to count 20 times .
It can do 50ms, so set up the interrupt handler to count 20 times .
Fri Jul 03 2015, 03:04 pm
Here you have an example using timer 0:
You just need to insert how many miliseconds you want or you can change the values in TH0 e TL0 to reduce the cicle.
Hope this help.
void delay_ms (unsigned char ms) { unsigned int MS = ms; while (MS){ TMOD &= 0xF0; TMOD |= 0x01; ET0 = 0; TH0 = 254; TL0 = 35; TF0 = 0; TR0 = 1; while(TF0==0); MS--; } TR0 = 0; }
You just need to insert how many miliseconds you want or you can change the values in TH0 e TL0 to reduce the cicle.
Hope this help.
Powered by e107 Forum System