I Know I just haven't found what i like. And I don't think i should start with justYou do not have to use a stamp to use basic or other higher language. See the SourceBoost series of compilers. Free for up to 2k programs, quite reasonable for unlimited.
list p=12F683 ; list directive to define processor
#include <p12F683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
cblock 0x20
InBuffer
combo1
combo2
combo3
combo4
dbctr
swlatch
NoGo
d1
d2
endc
org 0x0000 ; org sets the origin, 0x0000
goto Start ; go to beginning of program
org 0x0004 ;interrupt vector
goto Start
Start
movlw 07h ; Set GPIO <2:0) to
movwf CMCON0 ; digital I/O
clrf ANSEL ; digital I/0
movlw b'001111'
banksel TRISIO
movwf TRISIO
banksel GPIO
clrf GPIO
getinput
movlw InBuffer ; 4 character input buffer address
movwf FSR ; FSR = &InBuffer
getnext
call getbutton ; get a button press
movwf INDF ; add to buffer (1, 2, 4, or 8)
incf FSR,F ;
movlw InBuffer+4 ;
xorwf FSR,W ; all 4 buttons added?
bnz getnext ; no, branch, else,
chkcombo
movf InBuffer+0 ; W = InBuffer[0]
xorlw combo1 ; same as combination key 1?
bnz NoGo ; no, branch, else
movf InBuffer+1 ; W = InBuffer[1]
xorlw combo2 ; same as combination key 2?
bnz NoGo ; no, branch, else
movf InBuffer+2 ; W = InBuffer[2]
xorlw combo3 ; same as combination key 3?
bnz NoGo ; no, branch, else
movf InBuffer+3 ; W = InBuffer[3]
xorlw combo4 ; same as combination key 4?
bnz NoGo ; no, branch, else
;
; we've got a good combo
;
getbutton
movlw 20 ; reset debounce counter
movwf dbctr ; to 20 msecs
dbdelay
call DelayCy ; use 1 msec sample interval
comf GPIO,W ; sample active low switches
andlw 0x0F ; sample only b3..b0 bits
xorwf swlatch,W ; a difference (press or release)?
bz getbutton ; no, branch (reset), else
decfsz dbctr,f ; debounced? yes, skip, else
goto dbdelay ; sample again
xorwf swlatch,F ; update debounced switch state latch
andwf swlatch,W ; a debounced "new press"?
bz getbutton ; no, branch (a "new release"), else
return ; returns W = 1, 2, 4, or 8
DelayCy ;998 cycles
movlw 0xC7
movwf d1
movlw 0x01
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;2 cycles
goto $+1
END ; directive 'end of program'
list p=12F683 ; list directive to define processor
#include <p12F683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
cblock 0x20
KeyBuffer:4
Keys
Previous
codevalue
d1
d2
endc
org 0x0000 ; org sets the origin, 0x0000
goto main ; go to beginning of program
org 0x0004 ;interrupt vector
goto main
main
movlw 07h ; Set GPIO <2:0) to
movwf CMCON0 ; digital I/O
clrf ANSEL ; digital I/0
movlw b'001111'
banksel TRISIO
movwf TRISIO
banksel GPIO
clrf GPIO
clrf Previous
movlw KeyBuffer
movwf FSR
movlw b'1001'
movwf codevalue
open
call KeyLoop
subwf codevalue, W ; is it same as code?
btfss STATUS, Z ; zero set if yes
goto open
call ledOn ; frist thing to do
goto open
KeyLoop
call Delay10mS ;debounce delay
movfw Keys ;keep copy of previous keys
movwf Previous
movfw GPIO ;get key state
xorlw 0xff ;1 = key pressed
andlw 0x0f ;keep only 0-3 bits <-added
movwf Keys ;save for later
xorwf Previous,W ;find keys that have changed
andwf Keys,W ;and are currently pressed
btfsc STATUS,Z
goto KeyLoop
movwf INDF ;store the key
incf FSR,f ;move pointer forward
movfw FSR ;see if we have 4 keys yet
xorlw KeyBuffer+4
btfss STATUS,Z
goto KeyLoop
;here KeyBuffer will contain 4 key values.
ledOn
banksel GPIO ;turn on led on GP5
bsf GPIO,GP5
Delay10mS ;9998 cycles
movlw 0xCF
movwf d1
movlw 0x08
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;2 cycles
goto $+1
end
movlw b'1001'
movwf codevalue
open
call KeyLoop
subwf codevalue, W ; is it same as code?
btfss STATUS, Z ; zero set if yes
goto open
call ledOn ; frist thing to do
goto open
list p=12F683 ; list directive to define processor
#include <p12F683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
cblock 0x20
KeyBuffer:4
Keys
Previous
codevalue
d1
d2
endc
org 0x0000 ; org sets the origin, 0x0000
goto main ; go to beginning of program
org 0x0004 ;interrupt vector
goto main
main
movlw 07h ; Set GPIO <2:0) to
movwf CMCON0 ; digital I/O
clrf ANSEL ; digital I/0
movlw b'001111'
banksel TRISIO
movwf TRISIO
banksel GPIO
clrf GPIO
clrf Previous
GetLoop movlw KeyBuffer
movwf FSR
movlw b'1001'
movwf codevalue
call KeyLoop
movfw KeyBuffer ;test the first key press
xorlw b'0001' ;was it key 1
btfss STATUS,Z ;yes so skip
goto GetLoop ;no so go back and get new keys
movfw KeyBuffer+1 ;test the second key press
xorlw b'0010' ;2
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+2 ;test the third key press
xorlw b'0100' ;3
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+3 ;test the fourth key press
xorlw b'0001' ;1
btfss STATUS,Z
goto GetLoop
;if it get's to here then keys 1,2,3,1 were pressed.
;turn on LED here
goto GetLoop
KeyLoop
call Delay10mS ;debounce delay
movfw Keys ;keep copy of previous keys
movwf Previous
movfw GPIO ;get key state
xorlw 0xff ;1 = key pressed
andlw 0x0f ;keep only 0-3 bits <-added
movwf Keys ;save for later
xorwf Previous,W ;find keys that have changed
andwf Keys,W ;and are currently pressed
btfsc STATUS,Z
goto KeyLoop
movwf INDF ;store the key
incf FSR,f ;move pointer forward
movfw FSR ;see if we have 4 keys yet
xorlw KeyBuffer+4
btfss STATUS,Z
goto KeyLoop
;here KeyBuffer will contain 4 key values.
return
Delay10mS ;9998 cycles
movlw 0xCF
movwf d1
movlw 0x08
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;2 cycles
goto $+1
return
end
movlw b'1001'
movwf codevalue
;if it get's to here then keys 1,2,3,1 were pressed.
;turn on LED here
call LedOn
goto GetLoop
LedOn
banksel GPIO
bsf GPIO,GP5 ;turn on led on GP5
goto LedOn ;keeps it in this loop for now
Correct.I don't need this part do ICode:movlw b'1001' movwf codevalue
My buttons are low going high on press
KeyLoop
call Delay10mS ;debounce delay
movfw Keys ;keep copy of previous keys
movwf Previous
movfw GPIO ;get key state
[COLOR="Red"];; xorlw 0xff ;1 = key pressed <-remove[/COLOR]
andlw 0x0f ;keep only 0-3 bits <-added
movwf Keys ;save for later
list p=12F683 ; list directive to define processor
#include <p12F683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF &[COLOR="Red"] _MCLRE_OFF [/COLOR]& _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
cblock 0x20
KeyBuffer:4
Keys
Previous
codevalue
d1
d2
endc
org 0x0000 ; org sets the origin, 0x0000
goto main ; go to beginning of program
org 0x0004 ;interrupt vector
goto main
main
movlw 07h ; Set GPIO <2:0) to
movwf CMCON0 ; digital I/O
clrf ANSEL ; digital I/0
movlw b'001111'
banksel TRISIO
movwf TRISIO
banksel GPIO
clrf GPIO
clrf Previous
GetLoop
call KeyLoop
movfw KeyBuffer ;test the first key press
xorlw b'0001' ;was it key 1
btfss STATUS,Z ;yes so skip
goto GetLoop ;no so go back and get new keys
movfw KeyBuffer+1 ;test the second key press
xorlw b'0010' ;2
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+2 ;test the third key press
xorlw b'0100' ;3
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+3 ;test the fourth key press
xorlw b'0001' ;1
btfss STATUS,Z
goto GetLoop
[COLOR="Red"]call LedOn[/COLOR]
;if it get's to here then keys 1,2,3,1 were pressed.
;turn on LED here
[COLOR="Red"]
LedOn
banksel GPIO
bsf GPIO,GP5
goto LedOn[/COLOR]
KeyLoop
call Delay10mS ;debounce delay
movfw Keys ;keep copy of previous keys
movwf Previous
movfw GPIO ;get key state
xorlw 0xff ;1 = key pressed
andlw 0x0f ;keep only 0-3 bits <-added
movwf Keys ;save for later
xorwf Previous,W ;find keys that have changed
andwf Keys,W ;and are currently pressed
btfsc STATUS,Z
goto KeyLoop
movwf INDF ;store the key
incf FSR,f ;move pointer forward
movfw FSR ;see if we have 4 keys yet
xorlw KeyBuffer+4
btfss STATUS,Z
goto KeyLoop
;here KeyBuffer will contain 4 key values.
return
Delay10mS ;9998 cycles
movlw 0xCF
movwf d1
movlw 0x08
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;2 cycles
goto $+1
return
end
banksel TRISIO
movwf TRISIO
[COLOR="Red"] clrf ANSEL ; bank 1, digital I/0
[/COLOR] banksel GPIO
clrf GPIO
clrf Previous
GetLoop
[COLOR="Red"] movlw KeyBuffer
movwf FSR ;Buffer to FSR
[/COLOR] call KeyLoop
movfw KeyBuffer ;test the first key press
list p=12F683 ; list directive to define processor
#include <p12F683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
cblock 0x20
KeyBuffer:4
Keys
Previous
codevalue
d1
d2
endc
org 0x0000 ; org sets the origin, 0x0000
goto main ; go to beginning of program
org 0x0004 ;interrupt vector
goto main
main
movlw 07h ; Set GPIO <2:0) to
movwf CMCON0 ; digital I/O
movlw b'001111'
banksel TRISIO
movwf TRISIO
clrf ANSEL
banksel GPIO
clrf GPIO ; digital I/0
clrf Previous
GetLoop movlw KeyBuffer
movwf FSR
call KeyLoop
movfw KeyBuffer ;test the first key press
xorlw b'0001' ;was it key 1
btfss STATUS,Z ;yes so skip
goto GetLoop ;no so go back and get new keys
movfw KeyBuffer+1 ;test the second key press
xorlw b'0010' ;2
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+2 ;test the third key press
xorlw b'0100' ;3
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+3 ;test the fourth key press
xorlw b'0001' ;1
btfss STATUS,Z
goto GetLoop
;if it get's to here then keys 1,2,3,1 were pressed.
;turn on LED here
goto GetLoop
KeyLoop
call Delay10mS ;debounce delay
movfw Keys ;keep copy of previous keys
movwf Previous
movfw GPIO ;get key state
xorlw 0xff ;1 = key pressed
andlw 0x0f ;keep only 0-3 bits <-added
movwf Keys ;save for later
xorwf Previous,W ;find keys that have changed
andwf Keys,W ;and are currently pressed
btfsc STATUS,Z
goto KeyLoop
movwf INDF ;store the key
incf FSR,f ;move pointer forward
movfw FSR ;see if we have 4 keys yet
xorlw KeyBuffer+4
btfss STATUS,Z
goto KeyLoop
call LedOn
;here KeyBuffer will contain 4 key values.
return
LedOn
banksel GPIO
bsf GPIO,GP5
goto LedOn
return
Delay10mS ;9998 cycles
movlw 0xCF
movwf d1
movlw 0x08
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;2 cycles
goto $+1
return
end
clrf ANSEL ;still analog IO pin
;banksel 0x81 = banksel TRISIO = banksel ANSEL
banksel ANSEL ;bank 1
clrf ANSEL ;turn to digital IO pin
bansel 0 ;bank 0
movlw b'001111'
banksel TRISIO
movwf TRISIO
clrf ANSEL
list p=12F683 ; list directive to define processor
#include <p12F683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
cblock 0x20
KeyBuffer:4
Keys
Previous
codevalue
d1
d2
endc
org 0x0000 ; org sets the origin, 0x0000
goto main ; go to beginning of program
org 0x0004 ;interrupt vector
goto main
main:
movlw 07h ; Set GPIO <2:0) to
movwf CMCON0 ; digital I/O
movlw b'001111'
banksel TRISIO
movwf TRISIO
clrf ANSEL ; digital I/0
banksel GPIO
clrf GPIO
clrf Previous
GetLoop:
movlw KeyBuffer
movwf FSR
call KeyLoop
movfw KeyBuffer ;test the first key press
xorlw b'1110' ;was it key 1
btfss STATUS,Z ;yes so skip
goto GetLoop ;no so go back and get new keys
movfw KeyBuffer+1 ;test the second key press
xorlw b'1101' ;2
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+2 ;test the third key press
xorlw b'1011' ;3
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+3 ;test the fourth key press
xorlw b'0111' ;1
btfss STATUS,Z
goto GetLoop
goto Myled
[COLOR="Red"]Myled:
clrf GPIO
bcf GPIO,GP4
goto Myled[/COLOR]
;if it get's to here then keys 1,2,3,1 were pressed.
;turn on LED here
goto GetLoop
KeyLoop:
call Delay10mS ;debounce delay
movfw Keys ;keep copy of previous keys
movwf Previous
movfw GPIO ;get key state
xorlw 0xff ;1 = key pressed
andlw 0x0f ;keep only 0-3 bits <-added
movwf Keys ;save for later
xorwf Previous,W ;find keys that have changed
andwf Keys,W ;and are currently pressed
btfsc STATUS,Z
goto KeyLoop
movwf INDF ;store the key
incf FSR,f ;move pointer forward
movfw FSR ;see if we have 4 keys yet
xorlw KeyBuffer+4
btfss STATUS,Z
call LedOn
return
;here KeyBuffer will contain 4 key values.
return
LedOn:
banksel GPIO
bsf GPIO,GP5
return
Delay10mS: ;9998 cycles
movlw 0xCF
movwf d1
movlw 0x08
movwf d2
Delay_0:
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;2 cycles
goto $+1
return
end
movfw FSR ;see if we have 4 keys yet
xorlw KeyBuffer+4
btfss STATUS,Z
[COLOR="Red"] goto KeyLoop
[/COLOR] call LedOn
return
getkey
;get key as Pressed until release
movfw GPIO ;Pull-Up keypress=1
;comf GPIO,w ;Pull-Down keypress=0
andlw 0x0f
bz getkey ;loop until key press
movwf Keys ;store Key
keyon
movfw GPIO
;comf GPIO,w
andlw 0x0f
bnz keyon ;loop until key release
movfw Key ;return Key as W
return
btfss STATUS,Z
call LedOn
return
list p=12F683 ; list directive to define processor
#include <p12F683.inc> ; processor specific variable definitions
errorlevel -302 ; suppress message 302 from list file
__CONFIG _FCMEN_ON & _IESO_OFF & _CP_OFF & _CPD_OFF & _BOD_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
cblock 0x20
KeyBuffer:4
Keys
Previous
codevalue
d1
d2
endc
org 0x0000 ; org sets the origin, 0x0000
goto main ; go to beginning of program
org 0x0004 ;interrupt vector
goto main
main
movlw 07h ; Set GPIO <2:0) to
movwf CMCON0 ; digital I/O
movlw b'001111'
banksel TRISIO
movwf TRISIO
clrf ANSEL ; digital I/0
banksel GPIO
clrf GPIO
clrf Previous
GetLoop movlw KeyBuffer
movwf FSR
movlw b'1001'
movwf codevalue
call KeyLoop
movfw KeyBuffer ;test the first key press
xorlw b'0001' ;was it key 1
btfss STATUS,Z ;yes so skip
goto GetLoop ;no so go back and get new keys
movfw KeyBuffer+1 ;test the second key press
xorlw b'0010' ;2
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+2 ;test the third key press
xorlw b'0100' ;3
btfss STATUS,Z
goto GetLoop
movfw KeyBuffer+3 ;test the fourth key press
xorlw b'0001' ;1
btfss STATUS,Z
goto GetLoop
;if it get's to here then keys 1,2,3,1 were pressed.
;turn on LED here
LedOn
banksel GPIO
bsf GPIO,GP5 ;turn on a led and hang out here
goto LedOn
goto GetLoop
KeyLoop
call Delay10mS ;debounce delay
movfw Keys ;keep copy of previous keys
movwf Previous
movfw GPIO ;get key state
xorlw 0xff ;1 = key pressed
andlw 0x0f ;keep only 0-3 bits <-added
movwf Keys ;save for later
xorwf Previous,W ;find keys that have changed
andwf Keys,W ;and are currently pressed
btfsc STATUS,Z
goto KeyLoop
movwf INDF ;store the key
incf FSR,f ;move pointer forward
movfw FSR ;see if we have 4 keys yet
xorlw KeyBuffer+4
btfss STATUS,Z
goto KeyLoop
;here KeyBuffer will contain 4 key values.
return
Delay10mS ;9998 cycles
movlw 0xCF
movwf d1
movlw 0x08
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;2 cycles
goto $+1
return
end
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?