Pic2008
- 7th November 2008, 11:30
When I first power ON the PIC16F877, sometimes I don't see the LED turn ON, which means my code not running. Anything wrong?
include "modedefs.bas"
define osc 20
asm
device pic16f877,hs_osc,BOD_OFF,wdt_off,pwrt_on,protect_o ff
endasm
clear
ADCON1=%00000111 'PIC16F877 turn off analog comparator,
OPTION_REG.7 = 0 'enable internal pull up GPPU
OPTION_REG.6 = 0 'falling edge INT
TRISB = %00010001
'*********************** ASSEMBLY INTERUPT VARIABLES ***********************
wsave var byte $20 system
wsave1 var byte $a0 system ' Necessary for devices with RAM in bank1
wsave2 var byte $120 system ' Necessary for devices with RAM in bank2
wsave3 var byte $1a0 system ' Necessary for devices with RAM in bank3
ssave var byte bank0 system
psave var byte bank0 system
a var byte
b var byte
c var byte
d var byte
task var byte
enc_counter var word
RxD var PORTC.7
TxD var PORTC.6
led var PORTE.2
goto start 'skip over interupt handler
'*********************** ASSEMBLY INTERUPT HANDLER *************************
define INTHAND myint
Asm
myint
; Save W, STATUS and PCLATH registers, if not done previously
;movwf wsave
;swapf STATUS, W
;clrf STATUS
;movwf ssave
;movf PCLATH, W
; movwf psave
movlw high 100 ; Wait 100us to debounce encoder
movwf R0 + 1
movlw low 500
call PAUSEUSL
incf _d, w ;d dummy counter
nop
movwf _d
incfsz _enc_counter,W ; Add one to low byte
decf _enc_counter+1,F ; No carry (negates next step)
incf _enc_counter+1,F ; Add one to high byte
movwf _enc_counter ; Store updated low byte back.
iorwf _enc_counter+1,W ; Set Z flag
bsf _led ;turn on led
; Restore saved registers
movf psave, W
movwf PCLATH
swapf ssave, W
movwf STATUS
swapf wsave, F
swapf wsave, W
bcf INTCON, INTF
bcf INTCON, RBIF ; Clear the Interupt Flag
RETFIE ; Return from interrupt
endasm
start:
intcon=%10011000 ' enable int
a= 1
high led
pause 500
low led
include "modedefs.bas"
define osc 20
asm
device pic16f877,hs_osc,BOD_OFF,wdt_off,pwrt_on,protect_o ff
endasm
clear
ADCON1=%00000111 'PIC16F877 turn off analog comparator,
OPTION_REG.7 = 0 'enable internal pull up GPPU
OPTION_REG.6 = 0 'falling edge INT
TRISB = %00010001
'*********************** ASSEMBLY INTERUPT VARIABLES ***********************
wsave var byte $20 system
wsave1 var byte $a0 system ' Necessary for devices with RAM in bank1
wsave2 var byte $120 system ' Necessary for devices with RAM in bank2
wsave3 var byte $1a0 system ' Necessary for devices with RAM in bank3
ssave var byte bank0 system
psave var byte bank0 system
a var byte
b var byte
c var byte
d var byte
task var byte
enc_counter var word
RxD var PORTC.7
TxD var PORTC.6
led var PORTE.2
goto start 'skip over interupt handler
'*********************** ASSEMBLY INTERUPT HANDLER *************************
define INTHAND myint
Asm
myint
; Save W, STATUS and PCLATH registers, if not done previously
;movwf wsave
;swapf STATUS, W
;clrf STATUS
;movwf ssave
;movf PCLATH, W
; movwf psave
movlw high 100 ; Wait 100us to debounce encoder
movwf R0 + 1
movlw low 500
call PAUSEUSL
incf _d, w ;d dummy counter
nop
movwf _d
incfsz _enc_counter,W ; Add one to low byte
decf _enc_counter+1,F ; No carry (negates next step)
incf _enc_counter+1,F ; Add one to high byte
movwf _enc_counter ; Store updated low byte back.
iorwf _enc_counter+1,W ; Set Z flag
bsf _led ;turn on led
; Restore saved registers
movf psave, W
movwf PCLATH
swapf ssave, W
movwf STATUS
swapf wsave, F
swapf wsave, W
bcf INTCON, INTF
bcf INTCON, RBIF ; Clear the Interupt Flag
RETFIE ; Return from interrupt
endasm
start:
intcon=%10011000 ' enable int
a= 1
high led
pause 500
low led