How to Use Timer-0 in AT89C1051 (Split Mode)

The following code demonstrate, how to use timer-0 in split mode. In this mode TL0 and TH0 both are incremented by 1 on each clock cycle. Both timer-0 registers are incremented independently. Timer flag TF0 is generate when TL0 count reaches 256 and TF1 is generated when TH0 count reaches 256. The code is written in Keil uVision2 IDE and simulation is done with Proteus 8.0. At the end of code, you can find complete project files for download.

Code Using Keil uVision2

#include <REG51.H>
#include <stdio.h>
// proto-types
void ConfigTimerSplitMode(void);
void MonitorTimer1OverflowFlag(void);
void Delayms(unsigned int x_time);
// pin labling
sbit CLK0 = P1^0;
sbit CLK1 = P1^1;
sbit TF0_STATUS = P3^0;
sbit TF1_STATUS = P3^1;
void main(void)
{
// make as output
CLK0 = 0;
CLK1 = 0;
TF0_STATUS = 0;
TF1_STATUS = 0;
// config timer in split mode
ConfigTimerSplitMode();
while(1)
{
// flag status
TF0_STATUS = TF0;
if(TF0 == 1)
{
CLK0 = ~CLK0;
TF0 = 0;
TL0 = 0;
}
TF1_STATUS = TF1;
if(TF1 == 1)
{
CLK1 = ~CLK1;
TF1 = 0;
TH0 = 50;
}
}
}
void ConfigTimerSplitMode(void)
{
// master clock is 12MHz
// timer clock is 1/12th => 1MHz
// clear all registers
TL0 = 0;
TH0 = 50;
// set timer-0, mode-3 (8-bit split)
// set timer-1 disable
TMOD = 0x33;
// start timer-0
TR0 = 1;
// start timer-1
TR1 = 1;
}
void Delayms(unsigned int x_time)
{
unsigned int x,y;
for(x=0;x<x_time;x++)
for(y=0;y<122;y++);
}

Download Files

For download Keil project and Proteus 8.0 simulation files, click here.

Comments

Popular posts from this blog

How to Program Parallel Slave Port (PSP) in PIC16F877A

How to Program Interrupts in PIC16F877A

How to Program SPI in PIC16F877A (Slave Mode)