Many of PIC 18 timers are 16 bit wide. PIC 18 has 8 bit Architecture so 16 bit timer is accessed as two separate registers of low byte(TMRxL) and high byte(TMRxH) where x=0,1,2,3. First of all we are going to talk about Timer0. Timer0 can be used as 8-bit or 16-bit timer.
- T0CON register is used to control Timer0. You don’t need to learn any of registers. These are in given in the Datasheet of PIC Microcontroller.
- PIC Microcontroller first divide the crystal frequency by 4 before further use for timers. Let’s say I am using 10MHZ crystal then PIC Microcontroller divide this frequency by 4 i.e. 10/4 = 2.5MHZ. So my one machine cycle is 1/2.5MHZ = .4 Micro sec
- Steps to Program Timer0
- Load T0CON register with selected prescaler As I told you PIC Microcontroller divides crystal frequency by 4 then prescale further divide this frequency more. let’s say I select prescale as 001 so I divide crystal frequency by 4 more 2.5/4 = 0.625
- Set values for TMR0L and TMR0H according to your delay
- Timer on
- Keep monitoring TMR0IF bit. TMR0IF bit becomes one when Timer0 reaches value FFFFH
- When TMR0IF bit becomes 1 Stop Timer
- Clear TMR0IF
- In the following Program Led is blinking and you have two different delays which can be choose with a switch
thanks keep it up ....knowledge sharing is very good matter .......
ReplyDelete