SCHEMATIC DIAGRAM
Source Code in SPIN LANGUAGE
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
LEDs_START = 5 ' East/West Lights ( 5,4,3 ) Start of I/O pin group for on/off signals
LEDs_END = 0 ' End of I/O pin group for on/off signals
PUSHBUTTON1 = 18 ' For N/S
PUSHBUTTON2 = 30 ' For E/W
var
long i
PUB TrafficLightsSimulaion3
dira[LEDs_START..LEDs_END]~~ ' Setting up 6 LED's for the output.
repeat
i := 0 ' %0,0,0,0,0,0 = R1,Y1,G1,R2,Y2,G2 = LEDS off
outa[LEDs_END..LEDs_START] := %100001 ' Starting with direction East / West turns Green and North / South turns Red
repeat until i == 12 OR ina[PUSHBUTTON1] == 1 ' Immediate change to ****** on East/ West street
waitcnt(clkfreq / 2 + cnt ) ' 7.50 sec
++ i
outa[LEDs_END..LEDs_START] := %100010 ' East/ West is yellow && North / South is red
waitcnt(clkfreq * 2 + cnt) ' 2 sec
outa[LEDs_END..LEDs_START] := %100100 ' East / West and North / South both are Red
waitcnt(clkfreq * 1 + cnt) ' For 1 sec
i := 0
outa[LEDs_END..LEDs_START] := 1100 ' East/ West is Red && North / South is Green
repeat until i == 12 OR ina[PUSHBUTTON2] ==1 ' Immediate change to ****** North / South street
waitcnt(clkfreq / 2 + cnt )
++ i
outa[LEDs_END..LEDs_START] := %010100 'East/ West is Red and North / South is Yellow
waitcnt(clkfreq * 2 + cnt) ' 2 sec
outa[LEDs_END..LEDs_START] := %100100 ' East/ West is Red and North / South is Red
waitcnt(clkfreq * 1 + cnt) ' For 1 sec
No comments:
Post a Comment