Hi
I have been learning PIC assembly language and is very interesting and am doing about interrupt routines I have studied a lot of articles about registers that might be useful.
My personal task is to use the built in timer0 as the source of interrupt to create a square wave or flashing LED. when the interrupt occurs it should turn the light off or set pin to low and after the interrupt the light should be turned back on or set to high until the next interrupt occurs, which is after every 1ms.
My code doesn't work, it doesn't even trigger the interrupt and need some help, have been working at it for weeks, even included the option register to select the clock source and still nothing and even restoring status and w register.
Would appreciate some insight. This builds without errors on MPLAB but has some messages and warnings but when I send it to the board, the LED just stays on. doesn't flash.
Thanks
I have been learning PIC assembly language and is very interesting and am doing about interrupt routines I have studied a lot of articles about registers that might be useful.
My personal task is to use the built in timer0 as the source of interrupt to create a square wave or flashing LED. when the interrupt occurs it should turn the light off or set pin to low and after the interrupt the light should be turned back on or set to high until the next interrupt occurs, which is after every 1ms.
My code doesn't work, it doesn't even trigger the interrupt and need some help, have been working at it for weeks, even included the option register to select the clock source and still nothing and even restoring status and w register.
Code:
#include <p16f72.inc>
__config (_HS_OSC & _WDT_OFF & _PWRTE_OFF & _CP_OFF)
; /////////////////////////////////////////////////////////////////////////
; Define all registers and variable addresses!
; Note: Crystal frequency is 4MHz, so 1 tick = prescaler * 4 / 4 MHz
; to get 1ms @40MHz with prescaler of 32
; 256 - ((delay * Fosc)/(prescalar * 4))
; 256 - ((1ms * 4Mhz)/(32*4)) = 225
;
; /////////////////////////////////////////////////////////////////////////
STATUS EQU 3
PORTC EQU 7
PORTB EQU 6
INTCON EQU h'B'
TMR0 EQU 1
TRISC EQU h'87'
TRISB EQU h'86'
OPTION_REG EQU h'81'
W_SAVE EQU 25
STATUS_SAVE EQU 26
COUNTA EQU 27
;******************************************************************
list P=16F72
ORG 000H
GOTO MAIN
ORG 004H
GOTO INTFUNCT
; /////////////////////////////////////////////////////////////////////////
; Initialize all variables and port pins here!
; /////////////////////////////////////////////////////////////////////////
MAIN:
BSF STATUS, RP0
MOVLW B'00000000'
MOVWF TRISB
MOVLW B'00101100'
MOVWF OPTION_REG
BCF STATUS, RP0
CLRF PORTB
MOVLW .225
MOVWF TMR0
BCF INTCON, TMR0IF
BSF INTCON, TMR0IE
BSF INTCON, GIE
PROGRAM:
BSF PORTB,0 ;keep light on until after 1ms interrupt will trigger
GOTO PROGRAM
INTFUNCT:
MOVWF W_SAVE ; save W
SWAPF STATUS, W ; save STATUS
MOVWF STATUS_SAVE
BCF INTCON, TMR0IF
BCF INTCON, GIE
BCF STATUS, RP0
BCF PORTB,0 ;turn off the light
MOVLW .198 ;1ms delay including time it takes to execute delay loop and commands till return
MOVWF CountA ;create a delay of 1ms - the duration the light will stay off
Call DelayFunct
MOVLW .225
MOVWF TMR0
SWAPF STATUS_SAVE, W
MOVWF STATUS
SWAPF W_SAVE, F
SWAPF W_SAVE, W
RETFIE
DelayFunct:
NOP
DECFSZ CountA
GOTO DelayFunct
return
END
Thanks