Below is what I was working on today. It's only for 1 switch and set of LEDs, but it was working well for 2 if you repeat everything, give the variables new names, and assign things to new I/Os. Because of physical implementation, I'll most likely need to use something like the 6 pin 10F202. This will also make the next problem easier to deal with. If I were to use 1 PIC to read n number of switches, it would need to be able to allow one switch to perform its operation even if another switch was being pressed and held.
Code:
#config
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _CPD_OFF
#endconfig
Define OSCCAL_1K 1 ' PIC12F675, Calibrate internal oscillatordefine MCLRE_OFF
LED1 var GPIO.0 ' Alias GPIO.0 to LED1
LATCH1 var GPIO.1 'Alias GPIO.1 to LATCH1
PB1 Var GPIO.3 ' Alias GPIO.2 to push button
LED1on var word
LED1off var word
ANSEL = 0 ' Set all digital
CMCON = 7 ' Analog comparators off
TRISIO = %11001100
LED1 = 0
LATCH1 = 1
LED1off = LED1
LED1on = LATCH1
pause 10
LATCH1 = 0
main:
switchpress1:
if PB1 = 0 then
pause 40
gosub LED1status
LED1on = 1
LED1off = 0
pause 5
LATCH1 = 0
gosub switchrelease1
pause 40
endif
goto main
End
LED1status:
if LED1 = 1 then
LATCH1 = LED1on
LED1 = LED1off
elseif LED1 = 0 then
LED1 = LED1on
LATCH1 = LED1off
endif
return
switchrelease1:
do until PB1 = 1
pause 5
loop
return
Bookmarks