Sorry for the long code below..... I am trying to parallel task on a 20M2, the 20M2 gets highs/lows and serial from a 14M2. The 14M2 handles serial in signals and then passes high/lows to this one. When I Simulate it I get an error 'Symbol is already defined' at the line
after Start1:. Both programs ran OK by them self’s. I have also read that it is not recommended to put a Serin as I have in the first program? As it is waiting to see what the state of the BCD switch it is the first thing it does before it starts anything. I am wanting to look at this BCD code set by a switch and this seemed the best way to pass the data from one chip to the last? If push comes to shove I can free up 4 lines into the 20M2 and do it with highs/lows, eg, 0001 = 9 minutes, 0010 = 8 minutes, etc.
Thanks
Jaden
Code:
symbol outbyte = b3
Thanks
Jaden
Code:
Start0:
' ================================== MAX7219_Countdown.bas =================================
' This program uses a PICAXE-20M2 to manually shift-out SPI data to
' a MAX7219 LED display driver. The 7219 is connected to a 4-digit,
' It also send a serial count down out to a large 2 Segment LED display
' === Constants ===
' Hardware interface to the MAX7219
symbol sData = B.5 ' data out line to Max7219
symbol clock = B.7 ' clock line
symbol sLoad = B.6 ' pulse briefly to load data onto LEDs
symbol Led = B.4
symbol Relay = C.3
' Switch commands
symbol resetsc = C.7
symbol resetgc = B.0
symbol startgc = B.1
' Register addresses for the MAX7219
symbol decode = 9 ' decode register; specify digits to decode
symbol brite = 10 ' intensity (brightness) register; 15 = 100%
symbol scan = 11 ' scan-limit register; specify # of LEDs
symbol on_off = 12 ' 1 = display on; 0 = display off
' === Variables =====
symbol outByte = b0 ' data byte to be transmitted to the LED
symbol maxReg = b1 ' MAX register that receives the data byte
symbol forMax = w0 '
symbol index = b2 ' used in for-next loop
symbol y = b6
symbol x = b4
symbol z = b5
symbol bcd = b21 ' value from BCD Rotary Switch on Control Panel
' === Directives ====
#picaxe 20M2 ' specify PICAXE processor
' ============================== Begin Main Program =============================
'Serin B.2,N2400, bcd
'If pinC.4 = 1 then goto begin
'pause 10
'goto start
'=========84210000===========
'if bcd = %00000000 then goto time0 ' BCD Rotary Switch selected to '0'
'if bcd = %00010000 then goto time10 ' BCD Rotary Switch selected to '1'
'if bcd = %00100000 then goto time9 ' BCD Rotary Switch selected to '2'
'if bcd = %00110000 then goto time3 ' BCD Rotary Switch selected to '3'
'if bcd = %11000000 then goto time4 ' BCD Rotary Switch selected to '4'
'if bcd = %10100000 then goto time5 ' BCD Rotary Switch selected to '5'
'if bcd = %01100000 then goto time6 ' BCD Rotary Switch selected to '6'
'if bcd = %01110000 then goto time7 ' BCD Rotary Switch selected to '7'
'if bcd = %10000000 then goto time8 ' BCD Rotary Switch selected to '8'
'if bcd = %10010000 then goto time9 ' BCD Rotary Switch selected to '9'
' Initialize MAX7219
high Led
LOW SLoad ' set B.5 (SLoad) low
LOW Clock ' set B.7 (Clock) low
LOW SData ' set B.6 (SData) low
maxReg = scan ' set scan limit for digits 0-3
outByte = 3
gosub shout16
maxReg = brite ' set brightness to 5 (15 = 100%)
outByte = 15
gosub shout16
maxReg = decode ' set BCD decoding for digits 0-3
outByte = 15
gosub shout16
maxReg = on_off ' turn display on
outByte = 1
gosub shout16
'==========================start countdown===============================
time8:
maxReg = 1 ' 2nd LED from left = "9"
outByte = 15
gosub shout16
maxReg = 2 ' 2nd LED from left = "9"
outByte = 8
gosub shout16
maxReg = 3 ' 2nd LED from left = "9"
outByte = 0
gosub shout16
maxReg = 4 ' 2nd LED from left = "9"
outByte = 0
gosub shout16
pause 1000 ' give it a second.
time7:
maxReg = 2 ' 2nd LED from left = "7"
outByte = 7
gosub shout16
gosub seccount
time6:
maxReg = 2 ' 2nd LED from left = "6"
outByte = 6
gosub shout16
gosub seccount
time5:
maxReg = 2 ' 2nd LED from left = "5"
outByte = 5
gosub shout16
gosub seccount
time4:
maxReg = 2 ' 2nd LED from left = "4"
outByte = 4
gosub shout16
gosub seccount
time3:
maxReg = 2 ' 2nd LED from left = "3"
outByte = 3
gosub shout16
gosub seccount
time2:
maxReg = 2 ' 2nd LED from left = "2"
outByte = 2
gosub shout16
gosub seccount
time1:
maxReg = 2 ' 2nd LED from left = "1"
outByte = 1
gosub shout16
gosub seccount
time0:
maxReg = 2 ' 2nd LED from left = "BLANK"
outByte = 15
gosub shout16
gosub seccount
'==========================sound siren & flash segments==========================
buz:
for z = 1 to 4step 1
maxReg = 1 ' 1st LED from left = "0"
outByte = 0
gosub shout16
maxReg = 2 ' 2nd LED from left = "0"
outByte = 0
gosub shout16
maxReg = 3 ' 3rd LED from left = "0"
outByte = 0
gosub shout16
maxReg = 4 ' 4th LED from left = "0"
outByte = 0
gosub shout16
high Relay
high Led 'send relay closed
pause 250 'make segments flash
maxReg = on_off ' turn display off
outByte = 0
gosub shout16
pause 250
maxReg = on_off ' turn display on
outByte = 1
gosub shout16
next z
low Relay
low Led
'==================================End Of Siren==================================
goto start0 ' go back and do it again!
' ==================== End Main Program - Subroutines follow =====================
seccount:
for y = 5 to 0 step -1
maxReg = 3
outbyte = y
gosub shout16
for x = 9 to 0 step -1
maxReg = 4
outByte = x
gosub shout16
pause 950
next b4
next b6
return
shout16:
for index = 15 to 0 step -1 ' MAX7219 requires a 16-bit word
if bit15 = 1 then ' set sdata to correspond to bit15
high sData
else
low sData
endif
pulsout clock, 2 ' briefly pulse the clock line
forMax = forMax * 2 ' shift char left for next MSB
next index
pulsout sLoad,2 'briefly pulse the load line
'goto buttonstate
return
buttonstate:
for x = 1 to 2 step 1
if pinB.0 = 1 AND pinC.7 = 1 then goto start0 'if resetgc = hight then reset game clock
pause 5 'short button debounce
next x
return
'===========================================END OF PROGRAM 1===========================================================
'====================================================================================================================
Attachments
-
122.4 KB Views: 45