Pushbutton operated LED chase...
Code:
@ DEVICE pic12F675, INTRC_OSC_NOCLKOUT
' System Clock Options (Internal)
@ DEVICE pic12F675, WDT_ON
' Watchdog Timer
@ DEVICE pic12F675, PWRT_ON
' Power-On Timer
@ DEVICE pic12F675, MCLR_OFF
' Master Clear Options (Internal)
@ DEVICE pic12F675, BOD_ON
' Brown-Out Detect
@ DEVICE pic12F675, CPD_OFF
' Data Memory Code Protect
@ DEVICE pic12F675, PROTECT_OFF
' Program Code Protection
'
' Hardware Defines
' ----------------
PressButton var GPIO.3
LED1 var GPIO.0
LED2 var GPIO.1
LED3 var GPIO.2
LED4 var GPIO.4
LED5 var GPIO.5
'
' Software Defines
' ----------------
CounterA var BYTE
'
' Initialise PIC
' --------------
TRISIO=%00001000
CMCON=%00000111
ANSEL=%00000000
'
' Main Program Starts Here
' ------------------------
CounterA=0
Gosub LightLEDs
Loop:
If PressButton=1 then goto Loop
CounterA=CounterA+1
If CounterA>4 then CounterA=0
Gosub LightLEDs
Pause 50 ' Debounce Delay
While PressButton=0:Wend ' Wait for finger OFF the Button
Goto Loop
'
' Subroutine Lights the LEDs
' --------------------------
LightLEDs:
High LED1
High LED2
High LED3
High LED4
High LED5
If CounterA=0 then Low LED1
If CounterA=1 then Low LED2
If CounterA=2 then Low LED3
If CounterA=3 then Low LED4
If CounterA=4 then Low LED5
Return
End
Pressbutton on GPIO.3 connected between PIC pin and Vss. Resistor (10K) goes between PIC pin and Vdd.
Each LED connected between Vdd and pic pin via 330R Resistor.
Not tested (what do you expect for free and less than five minutes!!!) but should work. You can work out what the code does yourself from the PBP Manual and the PICs Datasheet.
Bookmarks