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

ArktiTic
Sun May 05 2024, 07:06 pm
CesslasyNear
Sun May 05 2024, 02:58 pm
chimichmedic1204
Sun May 05 2024, 11:06 am
Jamiegob
Sun May 05 2024, 10:11 am
Gregoryjed
Sun May 05 2024, 10:02 am
Mariocax
Sun May 05 2024, 08:51 am
WilliamErync
Sun May 05 2024, 02:35 am
Danielnof
Sat May 04 2024, 11:12 pm