Darkstar64
New Member
Hey Ive been working on some interesting code well interesting to me that is haha anyways it invloves the use of 4 12F509's using all the Pins from GP0 - GP5
but GP3 and GP5 are the inputs im currently looking for a way to have it scan the pins to see if the button is pressed or not and if its pressed I want to it loop a certain code untill the other button is pressed witch will do a different code here is what I have now
but GP3 and GP5 are the inputs im currently looking for a way to have it scan the pins to see if the button is pressed or not and if its pressed I want to it loop a certain code untill the other button is pressed witch will do a different code here is what I have now
Code:
list p=12F509 ; list directive to define processor
#include <p12F509.inc> ; processor specific variable definitions
__config _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
cblock 0x07
;***** VARIABLE DEFINITIONS
dc1 ; Delay Loop Counters
dc2
dc3
shadow ; Shadow variable used in rain to keep all top leds on or for cycle to resest all bits to 0
delaytime ; Adjustable delay variable
endc
;************************************************* *********************
; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.
org 0
MAIN
movwf OSCCAL ; update register with factory cal value
;******** Main Code
start
movlw b'101000' ; Configure only GP3 and GP5 as a input
tris GPIO
loop
waitdn btfsc GPIO,3 ; Wait untill button is pressed on GP3 ( GP3 low )
goto waitdn
call Cycle
movlw .2
pagesel delay10
call delay10 ; Delay of 20ms to debounce GP3 ( GP3 low )
pagesel $
waitdn2 btfsc GPIO,5 ; Wait untill button is pressed on GP5 ( GP5 low )
goto waitdn2
call Rain
movlw .2
pagesel delay10
call delay10 ; Delay of 20ms to debounce GP5 ( GP5 low )
pagesel $
goto loop
;******** Main Subroutine's / Effects
Cycle
movlw .5
movwf delaytime
movlw b'000000'
movwf shadow
call lightledA
call lightledB
call lightledC
call lightledD
call lightledE
call lightledF
call lightledG
call lightledH
call lightledI
call lightledJ
call lightledK
call lightledL
goto Cycle
Rain
movlw b'000000'
movwf shadow
movlw .2
movwf delaytime
call lightledA
call lightledD
call lightledG
call lightledJ
movlw .9
call delay10
movlw .3
movwf delaytime
call lightledC
call lightledF
call lightledI
call lightledL
movlw .9
call delay10
movlw .9
call delay10
movlw .9
movwf delaytime
call lightledA
call lightledD
call lightledG
call lightledJ
movlw .9
call delay10
movlw .9
call delay10
movlw .9
call delay10
movlw .4
movlw delaytime
call lightledB
call lightledE
call lightledH
call lightledK
goto Rain
Randomeffect
movlw b'000000'
movwf shadow
movlw .2
movwf delaytime
call lightledE
call lightledH
call lightledA
call lightledB
call lightledC
call lightledF
call lightledI
call lightledL
call lightledK
call lightledJ
call lightledG
call lightledD
call lightledE
call lightledH
call lightledA
call lightledB
call lightledC
call lightledF
call lightledI
call lightledL
call lightledK
call lightledJ
call lightledG
call lightledD
call lightledE
call lightledH
call lightledA
call lightledB
call lightledC
call lightledF
call lightledI
call lightledL
call lightledK
call lightledJ
call lightledG
call lightledD
goto Randomeffect
;************* Subroutines
;****************** LED Subroutines
lightledA
movlw b'111010' ; Configure GP4 and GP1 as input
tris GPIO
movlw b'000001' ; Change corresponding bit of GP0 to 1
movwf GPIO ; Writes 1 to GP0
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change corresponding bit of GP0 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO ; Write 0 to GP0
retlw 0
lightledB
movlw b'001110' ; Configure GP1 and GP2 as inputs
tris GPIO
movlw b'000001' ; Change corresponding bit of GP0 to 1
movwf GPIO ; Writes 1 to GP0
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP1 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledC
movlw b'001110' ; Configure pins GP1 and GP2 to inputs
tris GPIO
movlw b'010000' ; Change corresponding bit of GP4 to 1
movwf GPIO ; Writes 1 to GP4
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP4 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledD
movlw b'011001' ; Configure pins GP1 and GP4 to inputs
tris GPIO
movlw b'000100' ; Change corresponding bit of GP2 to 1
movwf GPIO ; Writes 1 to GP2
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP2 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledE
movlw b'011001' ; Configure pins GP0 and GP4 to inputs
tris GPIO
movlw b'000010' ; Change corresponding bit of GP1 to 1
movwf GPIO ; Writes 1 to GP1
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP2 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledF
movlw b'001101' ; Configure pins GP0 and GP2 to inputs
tris GPIO
movlw b'010000' ; Change corresponding bit of GP4 to 1
movwf GPIO ; Writes 1 to GP4
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP4 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledG
movlw b'011100' ; Configure pins GP2 and GP4 to inputs
tris GPIO
movlw b'000010' ; Change corresponding bit of GP1 to 1
movwf GPIO ; Writes 1 to GP1
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP0 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledH
movlw b'011001' ; Configure pins GP0 and GP4 to inputs
tris GPIO
movlw b'000100' ; Change corresponding bit of GP2 to 1
movwf GPIO ; Writes 1 to GP2
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP2 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledI
movlw b'001011' ; Configure pins GP0 and GP1 to inputs
tris GPIO
movlw b'000110' ; Change corresponding bit of GP1 to 1
movwf GPIO ; Writes 1 to GP1
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP1 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledJ
movlw b'011100' ; Configure pins GP2 and GP4 to inputs
tris GPIO
movlw b'001001' ; Change corresponding bit of GP0 to 1
movwf GPIO ; Writes 1 to GP0
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP1 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledK
movlw b'011001' ; Configure pins GP0 and GP4 to inputs
tris GPIO
movlw b'000010' ; Change corresponding bit of GP1 to 1
movwf GPIO ; Writes 1 to GP1
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP0 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
lightledL
movlw b'001110' ; Configure pins GP0 and GP1 to inputs
tris GPIO
movlw b'010000' ; Change corresponding bit of GP4 to 1
movwf GPIO ; Writes 1 to GP4
movlw delaytime ; Get from dealytime variable
call delay10 ; Delay of 50 x 10ms = 500ms or .5s
movlw shadow ; Change correspoding bit of GP0 to 0
movwf GPIO
movlw b'101000' ; Configure GP0,GP1,GP2,GP4 to outputs
tris GPIO
retlw 0
;****************** Delay Subroutine ( 10 ms )
delay10 ; Delay W x 10ms
movwf dc3 ; Delay = 1 + W x (3 + 10009 + 3) - 1 + 4 -> W x 10.015ms
dly2 movlw .13 ; Repeat inner loop 13 times
movwf dc2 ; -> 13 x (767 + 3) - 1 = 10009 cycles
clrf dc1 ; Inner loop = 256 x 3 - 1 = 767 cycles
dly1 decfsz dc1,f
goto dly1
decfsz dc2,f ; End middle loop
goto dly1
decfsz dc3,f ; End outer loop
goto dly2
retlw 0
end