john green
Member
Another two questions from a struggling learner.
I am using a 28X1 (Why? Because it’s what came fitted to my starter pack!)
With comparative ease, I managed to write a program to control a two way traffic light sequence but on trying to introduce a pedestrian crossing, found myself pulling hair out in clumps in trying to include a latched signal such that pressing a button would hold a notification in abeyance until the sequence reaches a logical point to give the pedestrians right of way, ie. when both roads have a red light.
I discovered how to use an interrupt which almost achieved this end but which failed the test of being a workable solution because, as might well be expected, it interrupted the ongoing sequence at the moment of the pedestrian request.
A functional solution, used just to prove the reminder of the program, was using an external logic gate as a latch and this works perfectly.
So, question 1). Is there a way of getting an input that may appear at anytime during a sequence, to latch without disturbing the ongoing program or using external components? This of course also has to be cancelled after each operational cycle.
This is the working code using the external latch.
Question 2).
Wanting to identify the latch being ‘high’ and a digital rather than analogue input being needed, I tried to re configure the C1 port to be an input rather than output and get a value to store at b1. Having tried and failed with let dirsc = %00000010, I copied and pasted directly from the manual;
To convert all the pins to inputs
let dirsc = %00000000
However, then using
read pinc.1,b1
…the instruction was accepted by the simulator but was unaffected by trying to simulate any value on the input and I could not get b1 to change from 0.
Not surprisingly, it also failed to achieve anything when run in the real circuit.
I also tried
readadc C.1,b1
…but even though this was copied and pasted direct from the manual, the simulator responds with Error: Unknown symbol - C.1
Can you please advise how to achieve both configuring those pins to inputs and then, how best to get that value stored somewhere useful - like b1?
Thanks....
I am using a 28X1 (Why? Because it’s what came fitted to my starter pack!)
With comparative ease, I managed to write a program to control a two way traffic light sequence but on trying to introduce a pedestrian crossing, found myself pulling hair out in clumps in trying to include a latched signal such that pressing a button would hold a notification in abeyance until the sequence reaches a logical point to give the pedestrians right of way, ie. when both roads have a red light.
I discovered how to use an interrupt which almost achieved this end but which failed the test of being a workable solution because, as might well be expected, it interrupted the ongoing sequence at the moment of the pedestrian request.
A functional solution, used just to prove the reminder of the program, was using an external logic gate as a latch and this works perfectly.
So, question 1). Is there a way of getting an input that may appear at anytime during a sequence, to latch without disturbing the ongoing program or using external components? This of course also has to be cancelled after each operational cycle.
This is the working code using the external latch.
Code:
;traffic lights with single ped crossing
;RYGRYGRYleds on Bout0-7
;latch 14066 on from +5v push button
;off from pull down port c7
;latch high = green man LED read on ADC3
main:
readadc 3,b1
one:
high 1
high 7 ;red A
high 4 ;red B
pause 1000
high 7 ;red A
high 6 ;yellow A
high 4 ;red B
pause 1500
low 7 ;off red A
low 6 ;off yellow A
high 5 ;green A
high 4 ;red B
pause 5000
low 5 ;off greenA
high 6 ;yellow A
high 4 ;red B
pause 2000
low 6 ;off yellow A
high 7 ;red A
high 4 ;red B
pause 500
readadc 3,b1
if b1 >100 then goto cross1:
if b1 <100 then goto two:
two:
high 1
high 4 ;red A
high 7 ;red B
pause 1000
high 4 ;red B
high 3 ;yellow B
high 7 ;red A
pause 1500
low 4 ;off red B
low 3 ;off yellow B
high 2 ;green B
high 7 ;red A
pause 5000
low 2 ;off greenB
high 3 ;yellow B
high 7 ;red A
pause 2000
low 3 ;off yellow B
high 7 ;red A
high 4 ;red B
pause 500
readadc 3,b1
if b1 > 100 then goto cross2:
if b1 <100 then goto main:
cross1:
high 4 ;red B
high 7 ;red A
pause 1000
low 1 ;off red man
high portc 7 ;turn latch off
pause 100
low portc 7 ;off cancel latch
high 0 ;on walk signal
pause 4000
low 0 ;off walk signal
for b0 = 1 to 10 ;flash walk signal,loop 10 times
high 0 ;switch on output 0
pause 200 ;wait 0.2 seconds
low 0 ;switch off output 0
pause 200 ;wait 0.2 seconds
next b0 ;end of loop
low 0 ;off walk signal
high 1 ;on red man
pause 2000
goto two:
cross2:
high 7 ;red A
high 4 ;red B
pause 1000
low 1 ;off red man
high portc 7 ;cancel latch
pause 100
low portc 7 ;off cancel latch
high 0 ;on walk signal
pause 4000
low 0 ;off walk signal
for b0 = 1 to 10 ;flash walk signal,loop 10 times
high 0 ; switch on output 0
pause 200 ; wait 0.2 seconds
low 0 ; switch off output 0
pause 200 ; wait 0.2 seconds
next b0 ; end of loop
high 1 ;on red man
low 0
pause 2000
goto main:
Question 2).
Wanting to identify the latch being ‘high’ and a digital rather than analogue input being needed, I tried to re configure the C1 port to be an input rather than output and get a value to store at b1. Having tried and failed with let dirsc = %00000010, I copied and pasted directly from the manual;
To convert all the pins to inputs
let dirsc = %00000000
However, then using
read pinc.1,b1
…the instruction was accepted by the simulator but was unaffected by trying to simulate any value on the input and I could not get b1 to change from 0.
Not surprisingly, it also failed to achieve anything when run in the real circuit.
I also tried
readadc C.1,b1
…but even though this was copied and pasted direct from the manual, the simulator responds with Error: Unknown symbol - C.1
Can you please advise how to achieve both configuring those pins to inputs and then, how best to get that value stored somewhere useful - like b1?
Thanks....