Header Ads

Using Timer 0 as a Delay using PIC16C62B Microcontroller

Microcontroller Pin Diagram:

In this tutorial, I have used Timer0 as a delay (1 sec). The output led is connected in sourcing mode. The LED turns on and off after having 1 second delay.
Components Used:
The following circuit components are used:
1. Crystal oscilator
2. 2 Capacitors
3. one 256 ohms resistor
4. one 10k ohms resistor
5. one LED Proteus Circuit Diagram:
MikroC Code:
//Code by Shahid Khan
// Timer0 as Delay
sbit led at PORTC.B3;
void T0Delay() //Timer0 1sec delay
{
unsigned char i;//define variable
for(i=0;i<30;i++) //for loop for delay
{
while(!INTCON.T0IF); //wait untill timer rollover
INTCON.T0IF=0; //CLEAR TIMER FLAG
}
}
void main() {
TRISC.RC3 = 0; //set RC3 as output
TMR0 = 0;//Load initial value to timer0
OPTION_REG=0x07; //prescale assigned to Timer0, prescaler value = 256, crystal 8MHz
while(1)//endless loop
{
led=1;//turn on led
T0Delay(); //wait 1 sec
led = 0;//turn off led
T0Delay();//wait 1 sec
}
}
Simulation Video:

No comments

Powered by Blogger.