
Fig. 1 PIC1684A interrupt map.
Programming PIC16F84A-PIC16F628A TMR0 Interrupts
by Lewis Loflin
We utilize TMR0 interrupts to increment a counter, then when reaching a select number the program toggles the state of a LED on PB0. this is very easy to program and we will walk through the steps.
To fully understand PIC16FXX interrupts see Programming PIC16F84A-PIC16F628A Interrupts by Example. Note the partial code below
ORG 0x004 ; interrupt vector ;ISR code DECFSZ CNT GOTO $+7 MOVLW B'00000001' XORWF PORTB, F MOVLW D'10' ; 50mS * value MOVWF CNT MOVLW D'60' ; preload value MOVWF TMR0 bcf INTCON, T0IF ; clr TMR0 interrupt flag retfie ; return from interrupt SETUP ; setup registers ; setp TMR0 operation ; internal clock, pos edge, prescale 256 movlw b'10000111' movwf OPTION_REG BCF STATUS, RP0 ; BANK 0 ; 256uS * 195 =~ 50mS ; 255 - 195 = 60 MOVLW D'60' MOVWF TMR0 ; preload timer value ; setup TMR0 INT bsf INTCON, GIE ; enable global interrupt bsf INTCON, T0IE ; enable TMR0 interrupt bcf INTCON, T0IF ; clr TMR0 interrupt flag to turn on, ; must be cleared after interrupt MOVLW D'10' ; 50mS * 20 = 1 Sec. MOVWF CNT goto LOOP
The code is self-explanatory and is a combination of earlier coding. When TMR0 overflows the interrupt decrement CNT until it reaches zero. Otherwise most of the code is skipped (GOTO $+7), except the TMR0 interrupt flag is always cleared to 0. See the following:
- Programming PIC16F84A-PIC16F628A Interrupts by Example
- PIC16F84A-PIC16F628A Pull Up Resistors with Interrupts
- Programming PIC16F84A-PIC16f628a Timers by Example
- Programming PIC16F84A-PIC16F628A TMR0 Interrupts
- Programming PIC16F84A Software Delay Routines by Example
- YouTube videos:
- PIC16F84A-628A Hardware Time Delays
- PIC16F84A-628A Timer Interrupt Delays
- PIC16F84A-628A Pullups and Interrupts
- PIC16F84A-628A Hardware Interrupts Tutorial

- Microchip PIC related videos:
- How to Use K150 PIC Programmer
- Microchip PIC16F628A Basic H-Bridge Motor Control
- Microchip PIC16F628A Counts BCD on 8 LEDs
- PIC16F84A Operates H-Bridge Motor Control
- PIC16F84A Operates MOSFET H-Bridge
- Using Velleman K8048 PIC Development Board
- Microchip PIC16F84A H-Bridge Motor Control
- Microchip PIC16F628A Basic H-Bridge Motor Control
- PICAXE Operates H-Bridge Motor Controller
- PICAXE Micorcontroller Controls Motor Speed - Direction
- PICAXE Projects
- Arduino Port Registers Revisited
- Digispark ATtiny85 with MCP23016 GPIO Expander
- Safely Build Program a H-Bridge
- Build H-Bridge Motor Control Without Fireworks
- MOSFET H-Bridge for Arduino 2
- Web Master
- Gen. Electronics
- YouTube Channel
- Arduino Projects
- Raspberry Pi & Linux
- PIC18F2550 in C
- PIC16F628A Assembly
- PICAXE Projects
Web site Copyright Lewis Loflin, All rights reserved.
If using this material on another site, please provide a link back to my site.