; Use 4 MHz crystal frequency.
list P=PIC16F877, F=INHX8M, C=160, N=80, ST=OFF, MM=OFF, R=DEC
include "C:\MPLAB\MCHIP_Tools\p16F877.inc"
__config ( _HS_OSC & _LVP_OFF)
errorlevel -302
;----------------- Define vaiables ----------------
LBTMR1 equ H'77' ;
HBTMR1 equ H'EC' ;
reg equ 0x20 ; ON, OFF, ON, OFF Led at bit 0
Temp_W equ 0x21
Temp_STATUS equ 0x22
;----------------- Vectors -------------------------
org H'000'
goto Main
org H'004'
goto ISR
Main
call Initial
Loop
Initial
bcf STATUS,RP0 ;
bcf STATUS,RP1 ; Bank 0 selected
clrf PORTA
bsf STATUS,RP0 ; Bank 1 selected
movlw H'00' ; All pins of PORTA outputs
movwf TRISA
bcf STATUS,RP0 ;
bcf STATUS,RP1 ; Bank 0 selected
movlw b'00000001'
movwf reg ; first interrut of TMR1, turn LED on
call TMR1Setup
return
TMR1Setup
bcf STATUS, RP0
bcf STATUS, RP1 ; Bank 0 selected
movlw LBTMR1 ; H'77'
movwf TMR1L
movlw HBTMR1 ; H'EC'
movwf TMR1H
clrf FlagsReg
movlw H'01' ; Timer 1 prescaler set to 1
movwf T1CON ; Turn on TMR1
bsf STATUS, RP0 ; Bank 1 selected
bsf PIE1,TMR1IE
bcf STATUS, RP0 ; Bank 0 selected
movlw H'C0' ; Set GIE, PEIE
movwf INTCON ; Interrupt controller setting
return
ISR
call Context_saving
call Display
call TMR1Reset
call Context_restoring
retfie
Context_saving
movwf Temp_W
swapf STATUS, W
movwf Temp_STATUS
return
Context_restoring
swapf Temp_STATUS, W
movwf STATUS
swapf Temp_W, F
swapf Temp_W, W
return
TMR1Reset
movlw LBTMR1
movwf TMR1L
movlw HBTMR1
movwf TMR1H
bcf PIR1,TMR1IF ; clear the TMR1 interrupt flag
return
Display
btfss reg, 0
call Turn_On
call Turn_Off
return
Turn_On
bsf reg,0
movlw b'11111111'
movwf PORTA
return
Turn_Off
bcf reg,0
movlw b'00000000'
movwf PORTA
return