PIC16f88, 4 LED's with 3904's, 4 push switches <---sums up the hardware used.
Im on a new project, and am having some troubles sorting out my thoughts into code.
The idea of the project is to light up lights, depending on the code received. An initial 1,2,3, or 4 will determine if light 1,2,3, or 4 will light up. If there is a following number, then Light1 + Initial number will light up. . .but. . . If another digit does not follow 2,3 or 4 nothing is to light up. a 1 followed by anything will light, light 1.. The code can be upto 4 digits long, and each digit come at intervals of 30seconds...
I think i've got the basics down but I would love to get some feedback. Learning this new language is mind boggling at times. And the event order in a timed sequence is leaving me dumb founded.
Code:
@ DEVICE 11111101110100b ; Internal Osc, WDT, PWRT, BOD, MCLR reset, CCP w/ RB2, LVprog disabled,
; Flash program memory write enabled, No Code Prot., No EEPROM Prot.
; Fail-safe clock monitor enabled, Internal external switch over enabled.
'------( Symbols/ Labels )------
'
Symbol Pswitch1 = portb.0 'Pin6/RB0 is assigned as switch1
Symbol Pswitch2 = portb.1 'Pin7/RB1 is assigned as switch2
Symbol Pswitch3 = portb.2 'Pin8/RB2 is assigned as switch3
Symbol Pswitch4 = portb.3 'Pin9/RB3 is assigned as switch4
Symbol LED1 = portb.7 'Pin13/RB7 is assigned as LED1
Symbol LED2 = portb.6 'Pin12/RB6 is assigned as LED2
Symbol LED3 = portb.5 'Pin11/RB5 is assigned as LED3
Symbol LED4 = portb.4 'Pin10/RB4 is assigned as LED4
'------( Defines )------
'
Define OSC 8 'Set oscillator at 8MHz
'------( Variables )------
'
anInput var byte
'------( Registers )------
' 76543210
TRISB = %00001111 'RB0-RB3 = inputs, RB4-RB7 = outputs
TRISA = %00000000 'RA0-RA7 = outputs
PORTA = %00000000 'Turn off portA
CMCON = %00000111 'Turn comparators OFF
'------( Initialization )------
'
main:
led1 = 0 'Turn LED1 off
led2 = 0 'Turn LED2 off
led3 = 0 'Turn LED3 off
led4 = 0 'Turn LED4 off
pswitch1 = 1 'Define switch1 as not pressed
pswitch2 = 1 'Define switch2 as not pressed
pswitch3 = 1 'Define switch3 as not pressed
pswitch4 = 1 'Define switch4 as not pressed
goto inputloop
'------( Main Code )------
'
Inputloop: 'Looking for input loop
'For 1 goto routine "one", for 2 goto routine "two", for 3 goto routine "three", if 4 goto routine "four"
branch aninput, [nothing, one, two, three, four]
goto inputloop
'------( Subroutines )------
'-------------------------------- this portion is for testing on my breadboard
nothing:
goto inputloop
one:
if pswitch1 = 0 then 'If one, then do stuff
goto Ledone
endif
goto inputloop
two:
if pswitch2 = 0 then 'If two, then do stuff
goto ledtwo
endif
goto inputloop
three:
if pswitch3 = 0 then 'If three, then do stuff
goto ledthree
endif
goto inputloop
four:
if pswitch4 = 0 then 'If four, then do stuff
goto ledfour
endif
goto inputloop
'-------------------------------- end breadboard testing portion.
LEDone:
if pswitch1 = 0 then 'If switch1 is pressed light LED1
led1 = 1
else
goto continue
endif
if pswitch1 = 0 and pswitch2 = 0 then 'If switch1 and switch2 are pressed light LED1
led1 = 1
else
goto continue
endif
if pswitch1 = 0 and pswitch3 = 0 then 'If switch1 and switch3 are pressed light LED1
led1 = 1
else
goto continue
endif
if pswitch1 = 0 and pswitch4 = 0 then 'If switch1 and switch4 are pressed light LED1
led1 = 1
endif
goto main 'restart the process
LEDtwo:
if pswitch2 = 0 then 'If switch2 is pressed
led2 = 0 'Light nothing
else
goto continue
endif
if pswitch2 = 0 and pswitch1 = 0 then 'If switch2 and switch1 are pressed
led2 = 1 and led1 = 1 'Light LED2 & LED1
else
goto continue
endif
if pswitch2 = 0 and pswitch3 = 0 then 'If switch2 and switch3 are pressed
led2 = 1 and led1 = 1 'Light LED2 & LED1
else
goto continue
endif
if pswitch2 = 0 and pswitch4 = 0 then 'If switch2 and switch4 are pressed
led2 = 1 and led1 = 1 'Light LED2 & LED1
endif
goto main 'restart the process
LEDthree:
if pswitch3 = 0 then 'If switch3 is pressed
led3 = 0 'Light nothing
else
goto continue
endif
if pswitch3 = 0 and pswitch1 = 0 then 'If switch3 and switch1 are pressed
led3 = 1 and led1 = 1 'Light LED3 & LED1
else
goto continue
endif
if pswitch3 = 0 and pswitch2 = 0 then 'If switch3 and switch2 are pressed
led3 = 1 and led1 = 1 'Light LED3 & LED1
else
goto continue
endif
if pswitch3 = 0 and pswitch4 = 0 then 'If switch3 and switch4 are pressed
led3 = 1 and led1 = 1 'Light LED3 & LED1
endif
goto main 'restart the process
LEDfour:
if pswitch4 = 0 then 'If switch4 is pressed
led4 = 0 'Light nothing
else
goto continue
endif
if pswitch4 = 0 and pswitch1 = 0 then 'If switch4 and switch1 are pressed
led4 = 1 and led1 = 1 'Light LED4 & LED1
else
goto continue
endif
if pswitch4 = 0 and pswitch2 = 0 then 'If switch4 and switch2 are pressed
led4 = 1 and led1 = 1 'Light LED4 & LED1
else
goto continue
endif
if pswitch4 = 0 and pswitch3 = 0 then 'If switch4 and switch3 are pressed
led4 = 1 and led1 = 1 'Light LED4 & LED1
endif
goto main 'restart the process
cOntinue:
If you have some time, please help me get my brain around this.
Bookmarks