Summary of LED blinking using timer0 of pic16f877 microcontroller
This article explains how to blink an LED using Timer0 of the PIC16F877 microcontroller without external delay functions. It details the mathematical calculation for achieving a 1-second interval using a 20 MHz crystal and a 1:256 prescaler, resulting in approximately 76 overflows. The guide highlights configuring the OPTION_REG (set to 87H) and INTCON registers, specifically monitoring the T0IF bit for overflow events to toggle the LED.
Parts used in the LED blinking using timer0 of pic16f877 microcontroller:
- PIC16F877 microcontroller
- LED
- 20 MHz crystal oscillator
- Timer0 register (TMR0)
- OPTION_REG register
- INTCON register
Here I discuss very good knowledge based project LED blinking using timer0 of pic16f877 microcontroller. You can see in my Earlier project “Simple Project on LED blinking by PIC 16 Microcontroller” where I have used delay program for LED blinking. For LED blinking we have to call inbuilt/external delay program. Now think without calling delay program how LED blinking is possible?
It is possible and possible by using timer 0 of pic16f877 microcontroller. As we know pic16f877 microcontroller has three inbuilt timers. 1. Timer 0 2. Timer 1 3. Timer 2. For more knowledge on timer in pic16f877 please go through my old post “Timer Modules in pic16f877 microcontroller”.
Project Description
In this project, it is very easily discuss that how easily a LED is blinking using inbuilt timer of pic16f877 microcontroller with exact 1 sec time interval. Now think about the Timer0 register, which is TMR0 and how it work. We know TMR0 is 8-bit register so it takes time to count from 00h to FFh is 255×0.2µs=51µs (If we use 20 MHz crystal oscillator to run the microcontroller). In TMR0 when 255 count complete the overflow done and overflow flag is set. Now calculate how many overflow would we need, if we want to have an exact 1 second time delay? It would be over 19500 overflows. For 1ms delay would require about 20 overflows because we see for 1 overflow 51µs is needed. Now concentrate on prescaler value and how it affects counting of TMR0. Prescaler value of 1:4 would take 4 instruction cycles to increment TMR0 by 1. On the other hand, prescaler value of 1:256 requires 256 instruction cycles for the increment. With prescaler value of 1:256, one overflow would take 255x256x0.2µs=13056µs. Therefore, with 1:256, it would take only 76 overflows to have an exact 1 second timing.
See the simple simulation circuit diagram of project “LED blinking using timer0 of pic16f877 microcontroller “
Now in c programming we have to concentrate on two spacial register operation_reg and INTCON. And we have to set proper bit pattern for both of this register as per our project need. For this project i set operation_reg = 87 H and INTCON= 00H. why i set operation_reg = 87 H and INTCON= 00H? For that please go through my post “Timer Modules in pic16f877 microcontroller”.
Now we can concentrate on Bit 2 position that is T0IF, of INTCON register because this bit is responsible for overflow occur in side TMR0. If TMR0 overflow occur it will set.
For more detail: LED blinking using timer0 of pic16f877 microcontroller
- How is LED blinking possible without calling a delay program?
It is possible by using the inbuilt Timer0 of the PIC16F877 microcontroller. - What are the three inbuilt timers available in the PIC16F877?
The microcontroller has Timer0, Timer1, and Timer2. - How long does it take for the TMR0 register to count from 00h to FFh with a 20 MHz crystal?
It takes 51 microseconds. - Which prescaler value requires 256 instruction cycles for one increment?
A prescaler value of 1:256 requires 256 instruction cycles. - How many overflows are needed to achieve an exact 1 second timing with a 1:256 prescaler?
Only 76 overflows are needed. - Which two special registers must be configured for this project?
The OPTION_REG and INTCON registers must be set properly. - What specific bit in the INTCON register indicates a Timer0 overflow?
Bit 2 position, known as T0IF, is responsible for indicating the overflow.
