Discussion in "8051 Discussion Forum" started by    sachinmm    Jun 27, 2015.
Sat Jun 27 2015, 10:39 am
#1
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
#2
The 8051 timer can't do 1 second.
It can do 50ms, so set up the interrupt handler to count 20 times .
Fri Jul 03 2015, 03:04 pm
#3
Here you have an example using timer 0:

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.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

EdwardFew
Mon Mar 18 2024, 01:14 pm
EmeryPah
Mon Mar 18 2024, 11:51 am
RobertMax
Sun Mar 17 2024, 10:22 pm
DanielJar
Fri Mar 15 2024, 06:52 pm
Tuzaimecor
Fri Mar 15 2024, 02:32 am
PromotionFoode
Thu Mar 14 2024, 08:11 pm
EdwardGeawn
Sun Mar 10 2024, 12:24 pm
ZacharyShado
Sat Mar 09 2024, 10:04 am