I dont think my orginal explanation of this project was clear enough.
Digits come at intervals of 30 seconds. Total digits per input = 1. Total inputs per code = 4 So I need to scan for 2 minutes, then once I have all four digits, I need to send an output based on the input received.
Look for input1 for 30seconds = TS1
Look for input2 for 30seconds = TS2
Look for input3 for 30seconds = TS3
Look for input4 for 30seconds = TS4
so if I get a 1 as my first input, then the other 3 inputs dont matter, LED1 lights up.
If my first input is a 2 but the other inputs are all zero's, then no LED's light up
If my first input is a 2 and any other input is 1-4, then LED2 + LED1 light up
my examples of the first inputs being 2 correspond with the first inputs being 3 or 4 aswell.
Example of 5 different codes received and their output operation:
ts1---ts2---ts3---ts4
1-----0-----1-----0---= HIGH LED1
2-----0-----0-----0---= NO LED'S HIGH
2-----1-----0-----0---= HIGH LED1 and LED2
3-----0-----0-----0---= NO LED'S HIGH
3-----0-----2-----0---= HIGH LED1 and LED3
hopefully this will help clarify the operation. i've changed my code a bit, I "think" its starting to get to where it needs to be, but I still dont know how to assign 30seconds per input received.
Code:
'Code Development / Debug Device Setting
' DCBA9876543210
@ 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
'------( Constants )------
'
'------( Defines )------
'
Define OSC 8 'Set oscillator at 8MHz
'------( Variables )------
'
GotInfo var byte
GotInfo1 var byte
GotInfo2 var byte
GotInfo3 var byte
empty var byte 'Time variable not used
tS1 var byte 'Time variable for 1st digit
tS2 var byte 'Time Variable for 2nd digit
tS3 var byte 'Time Variable for 3rd digit
tS4 var byte 'Time Variable for 3th digit
'------( Registers )------
' 76543210
OSCCON = %01110110 'Set Osc for 8Mhz
TRISB = %00001111 'RB0-RB3 = inputs, RB4-RB7 = outputs
TRISA = %00000000 'RA0-RA7 = outputs
PORTA = %00000000 'Turn off portA
CMCON = %00000111 'Turn comparators OFF
ANSEL = %00000000 'A/D converter set as Digital I/0
'------( Disable Interrupts/Registers )------
' 76543210
INTCON = %00000000
PIE1 = %00000000
PIR1 = %00000000
OPTION_REG = %00000000
'------( 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: 'Wait here for input
if pswitch1 = 0 then 'If switch1 is pressed
led1 = 1 'Light LED1
pause 3000 'Pause 3 seconds
led1 = 0 'Turn LED1 off
goto inputloop 'check for more inputs
endif
if pswitch2 = 0 then 'If Switch2 is pressed
tS1 = gotinfo 'rename Switch2, tS1
while ts1 = gotinfo '
'----------------------------
if pswitch1 = 0 then '
ts2 = Gotinfo1
else
ts2 = empty
'----------------------------
if pswitch3 = 0 then
ts2 = gotinfo1
else
ts2 = empty
'----------------------------
if pswitch4 = 0 then
ts2 = gotinfo1
else
ts2 = empty
'----------------------------
if ts2 = empty then
goto checkTs3
endif
endif
endif
endif
wend
endif
checkTS3:
while ts1 = gotinfo and ts2 = empty
if pswitch1 = 0 then
ts3 = gotinfo2
else
ts3 = empty
'----------------------------
if pswitch3 = 0 then
ts3 = gotinfo2
else
ts3 = empty
'----------------------------
if pswitch4 = 0 then
ts3 = gotinfo2
else
ts3 = empty
'----------------------------
if ts3 = empty then
goto checkts4
endif
endif
endif
endif
wend
checkTS4:
WHILE TS1 = gotinfo and ts2 = empty and ts3 = empty
if pswitch1 = 0 then
ts4 = gotinfo3
else
ts4 = empty
'----------------------------
if pswitch3 = 0 then
ts4 = gotinfo3
else
ts4 = empty
'----------------------------
if pswitch4 = 0 then
ts4 = gotinfo3
else
ts4 = empty
'----------------------------
if ts4 = empty then
goto nothing
endif
endif
endif
endif
wend
if ts1 = gotinfo then
led1 = 0
led2 = 0
led3 = 0
led4 = 0
goto inputloop
endif
if ts1 = gotinfo and ts2 = gotinfo1 then
led2 = 1
led1 = 1
pause 3000
led2 = 0
led1 = 0
goto inputloop
endif
if ts1 = gotinfo and ts3 = gotinfo2 then
led2 = 1
led1 = 1
pause 3000
led2 = 0
led1 = 0
goto inputloop
endif
if ts1 = gotinfo and ts4 = gotinfo3 then
led2 = 1
led1 = 1
pause 3000
led2 = 0
led1 = 0
goto inputloop
endif
Bookmarks