공학속으로/마이컴

8051/4051 Timers

더월드 2020. 3. 4.

Program for timer mode0

#include <reg51.h>			/* Include x51 header file */
sbit test = P1^0;			/* set test pin 0 of port1 */ 

void timer_delay()			/* Timer0 delay function */
{
	TH0 = 0xE3;			/* Load 8-bit in TH0 (here Timer0 used) */
	TL0 = 0x14;			/* Load 5-bit in TL0 */
	TR0 = 1;			/* Start timer0 */
	while(TF0 == 0);		/* Wait until timer0 flag set */
	TR0 = 0;			/* Stop timer0 */
	TF0 = 0;			/* Clear timer0 flag */
}
void main()
{
	TMOD = 0x00;			/* Timer0/1 mode0 (13-bit timer mode) */
	while(1)
	{
		test = ~test;		/* Toggle test pin */
		timer_delay();		/* Call timer0 delay */
	}
}

 

Program for timer mode1

/*
 * 8051_Timer_Mode1
 */
#include <reg51.h>		/* Include x51 header file */
sbit test = P1^0;		/* set test pin0 of port1 */ 

void timer_delay()		/* Timer0 delay function */
{
	TH0 = 0xFC;		/* Load higher 8-bit in TH0 */
	TL0 = 0x74;		/* Load lower 8-bit in TL0 */
	TR0 = 1;		/* Start timer0 */
	while(TF0 == 0);	/* Wait until timer0 flag set */
	TR0 = 0;		/* Stop timer0 */
	TF0 = 0;		/* Clear timer0 flag */
}
void main()
{
	TMOD = 0x01;		/* Timer0 mode1 (16-bit timer mode) */
	while(1)
	{
		test = ~test;	/* Toggle test pin */
		timer_delay();	/* Call timer0 delay */
	}
}

'공학속으로 > 마이컴' 카테고리의 다른 글

8051 모든 인터럽트  (0) 2020.03.04
외부 인터럽트  (0) 2020.03.04
8051/4051 UART Interrupt  (0) 2020.03.03
8051/4051 UART  (0) 2020.03.03
8051 LED Blinking Program  (0) 2020.03.03

댓글

💲 추천 글