' ------------------------------------------
' ------------------------------------------
' (c) DE0508
' ------------------------------------------
' Version 1.0
'
' 2009-01-19 start code
' ------------------------------------------
'---------------------------------------
' system settings
'---------------------------------------
#picaxe 18x
#gosubs 256
'setfreq m8
'---------------------------------------
' Define
'---------------------------------------
'---------------------------------------
' Konstanten
'---------------------------------------
symbol TRUE=1
symbol FALSE=0
symbol InputPush=0 ' Taster sind low aktiv
symbol InputNotPush=1 ' Taster ist nicht gedrückt
'---------------------------------------
' Pinbelegung PICAXE-18X
'---------------------------------------
' Input 2/ADC2 :
' Serial Out : *RS-2332 In
' Serial In : *RS-2332 Out
' Reset : *Pull-Up +5V
' 0V : *GND
' Output 0 : LED_0
' Output 1/i2c data :
' Output 2 :
' Output 3/ pwm 3 :
' Output 4/i2c scl :
' Output 5 :
' Output 6 :
' Output 7 :
' Vdd : *+5V
' Input 6/keyb clock :
' Input 7/keyb data :
' Input 0/ADC0/Infrain : INPUT_0
' Input 1/ADC1 :
'---------------------------------------
'---------------------------------------
' Ausgänge festlegen
'---------------------------------------
symbol LED_0 = 0
'---------------------------------------
' Eingänge festlegen
'---------------------------------------
symbol INPUT_0 = Pin0
'---------------------------------------
' Variable Belegung
'---------------------------------------
' w0 := b1:b0
symbol i = b0 ' Arbeitsregister
symbol j = b1 ' Arbeitsregister
symbol bButton = b1
'---------------------------------------
' w1 := b3:b2
symbol iLED = b2
'---------------------------------------
' w2 := b5:b4
'---------------------------------------
' w3 := b7:b6
'---------------------------------------
' w4 := b9:b8
'---------------------------------------
' w5 := b11:b10
'---------------------------------------
' w6 := b13:b12
symbol iBlinkCnt = b12
symbol iMode_Select = b13
'---------------------------------------
'---------------------------------------
' Variables - Storage PICAXE-18X
'---------------------------------------
' 80 to 127 ($50 to $7F)
' 192 to 239 ($C0 to $EF)
'---------------------------------------
'---------------------------------------
' EEPROM PICAXE-18X
' 0 to 255
'---------------------------------------
symbol PROG_VERSION = 0
EEPROM PROG_VERSION, ("1.0",0) ' wichtig '0' am Ende !
'---------------------------------------
' Symbole
'---------------------------------------
symbol WAIT_PUSH_TIME = 100
symbol WAIT_LOOSE_TIME = 50
'---------------------------------------
' Init
'---------------------------------------
init_var:
; clear vars
iMode_Select = 0
init_output:
outpins = %00000000 ' alle Ausgänge auf low
main:
gosub check_button0
if bButton = TRUE then
' we count from 0, 1, 2, 3, 4=0, ...
BRANCH iMode_Select, (prog_1, prog_2, prog_3, prog_4 )
main_0:
inc iMode_Select
if iMode_Select > 3 then
iMode_Select = 0
endif
endif
goto main
end
prog_1:
iBlinkCnt = 1
goto blink_loop:
prog_2:
iBlinkCnt = 2
goto blink_loop:
prog_3:
iBlinkCnt = 3
blink_loop:
iLED = LED_0
for i = 0 to iBlinkCnt
gosub Blink_LED
next i
goto main_0
prog_4:
' NOP
goto main_0
'---------------------------------------
' Blink_LED:
'---------------------------------------
Blink_LED:
' get : iBlinkCnt, iLED
' change: j
' return: -
for j = 1 to iBlinkCnt
HIGH iLED
pause 500 ' 500 ms
LOW iLED
next j
return
'---------------------------------------
' TASTER abfragen
'---------------------------------------
check_button0:
' change: bButton bool
' return: bButton bool
bButton = FALSE
check_b0:
' Taster gedrückt?
if INPUT_0 = InputPush then
pause WAIT_PUSH_TIME
if Pin0 = InputNotPush then
' Taster nicht mehr gedrückt?
goto check_b0
endif
do
' warte bis die Taste wieder losgelassen wird
pause WAIT_LOOSE_TIME
loop until Pin1 = InputNotPush
' Zustand wechseln
bButton = TRUE
endif
return