LED blinking using timer0 of pic16f877 microcontroller
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”.
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
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
JLCPCB Prototype: Only $2 for 10pcs 10×10cm, 24 hours Quick Turn, DHL Delivery in 3 days
Current Project / Post can also be found using:
- 16f877a pic timer pdf
- 16f877a led timer program
- blinking led as power indicator pic 16f877
- Timer 0 project