Hi guys
I have been getting some assistance on creating a project and I want to insert he code from the following location into my software.
I can't seem to make it work because of the definitions in the included msecdelay4MHz.inc
I also cannot work out how to easily remove the double click code from the code.
Can someone please have a look for me and tell me the best way to put it in to my code?
My code is here
The link to the button code is here
http://pcbheaven.com/picpages/A_Clever_Button/
I want it to work like so, Switch A short press calls SwAPressed.
Switch A Held for 1 second or more calls LVC_Setting
Switch B short press calls SwBPressed
Also, after I set my low voltage cutoff setting how can I return to my program without powering off the circuit?
Thanks
Steve
I have been getting some assistance on creating a project and I want to insert he code from the following location into my software.
I can't seem to make it work because of the definitions in the included msecdelay4MHz.inc
I also cannot work out how to easily remove the double click code from the code.
Can someone please have a look for me and tell me the best way to put it in to my code?
My code is here
Rich (BB code):
;****************************************************
;SimpleTimer.asm *
;
;14-6-2011 *
;****************************************************
;
list p=12F683
radix dec
include "p12f683.inc"
errorlevel -224 ; Don't complain about tris
errorlevel -302 ; Don't complain about BANK 1 Registers
__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT ;Internal osc.
;_MCLRE_OFF - master clear must be off for gp3 to work as input pin
;****************************************************************
; variables - names and files
;****************************************************************
temp1 equ 20h ;
temp2 equ 21h ;
pushes equ 22h
flashes equ 23h
on_time equ 24h
off_time equ 25h
minutes equ 26h
loops equ 27h
A_Dvalue equ 28h
delA equ 29h
delB equ 30h
;****************************************************************
;Equates
;****************************************************************
status equ 0x03
rp1 equ 0x06
rp0 equ 0x05
option_reg equ 81h
Setup bsf STATUS, RP0 ;Bank 1
movlw b'11111100' ;Set TRIS GP0,1 out GP2(AN2), 3,4,5 input
movwf TRISIO
movlw b'01010100'
movwf ANSEL ;A/D Clock FOSC/16, AN2(GP2) Set as analogue
BCF STATUS, RP0 ;bank 0
movlw 07h ;turn off Comparator ports
movwf CMCON0 ;must be placed in bank 0
movlw b'00001001'
movwf ADCON0 ;Result left justified, Ref Vdd, Select AN2, ADC on
;read 3 locations in EEPROM
bsf status,rp0
clrf EEADR ;EEPROM location 0 for flashes of LED
bsf EECON1,0 ;to show number of 5 mins
movf EEDATA,w
bcf STATUS,RP0
movwf flashes ;EEPROM 0 into flashes
bsf STATUS,RP0
incf EEADR ;EEPROM location 1 for on_time
bsf EECON1,0 ;starts EEPROM read operation storing result in EEDATA
movf EEDATA,w ;move read data into w
bcf STATUS,RP0
movwf on_time ;EEPROM 1 into on_time
bsf STATUS,RP0
incf EEADR ;EEPROM location 2 for off_time
bsf EECON1,0
movf EEDATA,w
bcf STATUS,RP0
movwf off_time ;EEPROM 2 into off_time
goto Main
;********************
;* Delays *
;********************
_50uS movlw .15
movwf delA
decfsz delA,f
goto $-1
retlw 00
_327mS goto $+1
decfsz delA,f
goto $-2
decfsz delB,f
goto $-4
retlw 00
;****************************
;* Sub Routines *
;****************************
SwA_Pressed
incf flashes,f
movlw 07
xorwf flashes,w ;if flashes=7
btfss STATUS,Z ;z=1 if flashes=7
goto $+3
clrf flashes
goto $-6
;put flashes into EEPROM 0
movf flashes,w ;put flashes into w
bsf STATUS,RP0 ;select bank1
movwf EEDATA
clrf EEADR
bcf STATUS,RP0 ;select bank0
call write
;put same value into EEPROM 1 for on_time
movf flashes,w ;put flashes into w
bsf STATUS,RP0 ;select bank1
movwf EEDATA
incf EEADR,1
bcf STATUS,RP0 ;select bank0
call write
;flash LED 1-5 times
movf flashes,w
movwf temp1 ;save flashes in temp1 for decrementing
bsf GPIO,0 ;turn on LED
call _327mS
bcf GPIO,0 ;turn off LED
call _327mS
decfsz temp1,f
goto $-5
btfss GPIO,5 ;loop until SwA is released
goto $-1
retlw 00
;SwB = minutes = off_time
SwB_Pressed
incf minutes,f
movlw 06
xorwf minutes,w ;if minutes=6
btfss STATUS,Z ;z=1 if minutes=6
goto $+3
clrf minutes
goto $-6
;put minutes into EEPROM 2 as off_time
movf minutes,w ;put minutes into w
bsf STATUS,RP0 ;select bank1
movwf EEDATA
movlw 2
movwf EEADR
bcf STATUS,RP0 ;select bank0
call write
;flash LED 1-5 times
movf minutes,w
movwf temp1 ;save minutes in temp1 for decrementing
bsf GPIO,0 ;turn on LED
call _327mS
bcf GPIO,0 ;turn off LED
call _327mS
decfsz temp1,f
goto $-5
btfss GPIO,4 ;loop until SwB is released
goto $-1
retlw 00
;microcontroller loops this sub-routine producing ON time
;as stored in EEPROM location 1
;look for sw press every 327mS
time_on
movlw 1
bsf STATUS,RP0
movwf EEADR
bsf EECON1,0 ;starts EEPROM read operation. Result in EEDATA
movf EEDATA,w ;move read data into w
bcf STATUS,RP0
movwf on_time ;will be 1-5
;convert each value of "on_time" to 5 minutes
;327mS x 16 x 58 = 5 minutes
swapf on_time,f ;rlf x 4 = 16 = swap nibbles
movlw .58
movwf loops
bsf GPIO,1 ;turn on relay
call _327mS
btfss GPIO,5 ;test switchA
goto SwA_Pressed
btfss GPIO,4 ;test switchB
goto SwB_Pressed
decfsz loops,f
goto $-6
decfsz on_time,f
goto $-.09
retlw 00
;microcontroller loops this sub-routine producing OFF time
;as stored in EEPROM location 2
;look for sw press every 327mS
http://pcbheaven.com/picpages/A_Clever_Button/
I want it to work like so, Switch A short press calls SwAPressed.
Switch A Held for 1 second or more calls LVC_Setting
Switch B short press calls SwBPressed
Also, after I set my low voltage cutoff setting how can I return to my program without powering off the circuit?
Thanks
Steve