hjl4
Member
Why is it that led on GP5 never turns on? I get led working on GP1, but after pressing momentary switch on GP3, the delay should count for about a minute, and turn GP5 on. Can anyone see whats wrong?
Code:
list p=12f629 ; list directive to define processor
#include <p12f629.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
;***** VARIABLE DEFINITIONS
w_temp EQU 0x20 ; variable used for context saving
status_temp EQU 0x21 ; variable used for context saving
d1 EQU 0x40
d2 EQU 0x41
d3 EQU 0x42
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
bcf STATUS,RP0 ; set file register bank to 0
;very small delay 5 micro seconds
nop
nop
nop
nop
nop
;GPIO port setup
bcf STATUS,RP0 ;set file register bank to 0
clrf GPIO ;clear port
movlw 07h ;set GP0,GP1 and GP2
movwf CMCON ;turn comparator off
bsf STATUS,RP0 ;set file register to bank 1
movlw 1Ch ;move literal(value) 1C in hex or 00011100 in binary to working register.
movwf TRISIO ;move literal(value) in working register to TRISIO making GP2, GP3 and GP4 as inputs
;and leaving GP0,GP1, and GP5 as outputs.
bcf STATUS,RP0 ;set file register bank to 0
start
bsf GPIO,1 ;set GP1 high
;LED on GP1 should be on.
;to confirm that microprocessor has setup all ports to input and outputs.
check nop ;5us delay to allow PIC to settle.
nop
nop
nop
nop
btfss GPIO,3 ;test GP3 if button on computer was pressed
goto check ;if not then return to check again
goto doublecheck ;if set then goto doublecheck
doublecheck
nop
nop
nop
nop
nop
btfss GPIO,3 ;test GP3 if button on computer was pressed
goto check ;if not then return to check again
call Delay
ready movlw 10h
movwf 05 ;make GP5 high turning HMR3000 on
nop ;again small delay
nop
nop
nop
nop
nop
goto scanswitch
scanswitch
btfss GPIO,3 ;scan GP3 for state change 1=high, 0=low
goto scanswitch ;if not set then do nothing but rescan button(switch).
goto stop
stop movlw 0h ;make bit 5(GP5) low shuting down HMR3000
movwf 05h
nop ;again small delay
nop
nop
nop
nop
nop
goto check ;after shutting down HMR3000 return to check
;for change of state on GP3.
Delay
;1 minute delay
movlw 0x23
movwf d1
movlw 0xCB
movwf d2
movlw 0x83
movwf d3
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto $+2
decfsz d3, f
goto Delay_0
;2 cycles
goto $+1
;4 cycles (including call)
return
; initialize eeprom locations
ORG 0x2100
DE 0x00, 0x01, 0x02, 0x03
END ; directive 'end of program'