A 1ms HIGH 1ms LOW (500Hz 50% Duty) square wave is generated on PinB0 using Timer0
Description
Timer0 is configured in Timer Mode with using the internal clock period of 1us @4HHz clock.
The objective is for Timer0 to overflow and generate an interrupt where the PortB0 pulse is generated after receiving exactly 1000 clock cycles. Since Timer0 is an 8 bit timer it will normally overflow after 256 clocks. To increase the range of Timer0 the prescalor is used. A prescalor of 1:4 means Timer0 will overflow after 1024 clocks. However this is too many clocks so one additional technique is used, Register Preloading. To remove the additional 24 clocks a value of 6 (6 x 4 = 24)is preloaded into the Timer0 register every interrupt. The result is that Timer0 overflows every 1000 clocks.
If the clock frequency is selected at 4Mhz, the internal clock frequency is 1Mhz or a period of 1us. This means 1000 clock cycles is 1ms (1000 x 1us) Thus the interrupt pulse is generated every 1 millisecond on Pin B0
| Filename | Version | Description |
| tut9.pjt | 1.0 | MPLAB Project |
| tut9.asm | 1.0 | PIC16F877 Assembler code |
| tut9.hex | 1.0 | Precompiled HEX |
| tut9.lst | 1.0 | Precompiled LST |
| tut9.vbb | 1.0 | Virtual Breadboard simulation |
|
|
Timer0 Timer Mode |
|
|
Timer0 Prescalor |
|
|
Timer0 Interrupt |
|
|
Timer0 Register Load |