Parrallel Tasking 20M2

Jaden

Senior Member
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
Code:
symbol outbyte = b3
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:
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

Jaden

Senior Member
The second part, toooooo long for this forum.

Code:
Start1:

 ' PICAXE-20M2
 ' Shotclk.bas
 ' Count down a given number to zero on a two digit 7-segment display
 ' using a 74HC595 Shift Register.
 ' pin 11 SH_CP Shift register clock input
 ' pin 12 ST_CP Storage register clock input
 ' pin 14 DS Serial data input
 '
 ' pin 11 - C.2 SH-CP (20M2 pin 8)
 ' pin 12 - C.1 ST_CP (20M2 pin 9)
 ' pin 14 - C.0 DS (20M2 pin 10)
 '
 
 ;DS = C.0  pin 10 Picaxe / Serial data input pin 14 595
 ;STCP = C.1 pin 9 Picaxe /  Storage register pin 12 595
 ;SHCP = C.2  pin 8 Picaxe / Shift register pin 11 595
 
 
 ;General Purpose Bytes Used
 ;b0, b1, b3, b4, b5, b6, b20 
 symbol dataout = C.0
 symbol clk = C.2
 symbol latchout = C.1
 symbol outbyte = b3
 symbol status = b20 
startsc:

	outbyte = %00111111					'Send 0 to units Segment
 	gosub out595 						'send this b5 value to register, DS
 	outbyte = %01001111					'Send 3 to Tens Segment
 	gosub out595
 	pulsout latchout,1 					'Display 2 new digits once both are loaded into their 595s
 		if pinB.1 = 1 then 				'if startgc button then return to countdown
 	       goto main
 	endif
	if pinC.5 = 1 then 					'if startsc button then return to countdown
 	       goto main
 	endif
 	if pinC.4 = 1 then 					'if siren button pressed restart countdown
 	       gosub siren
 	endif
 	goto startsc							'loop until it is, if it is, start countdown

main: 
	 	
'------------------------------------------------  count down from 29 to 20  ------------------------------------------------	
 	for b8 = 0 to 9
 		
 	gosub loop_1sec						'call up 1 second delay with button watch loop
 	lookup b8,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte 'tens segment turn on 9
 		gosub out595	
 	outbyte = %01011011					'Send 2 to tens segment
 		gosub out595	
 	pulsout latchout,1 
 	next b8
 	
 	
 		
'------------------------------------------------  count down from 19 to 10  ------------------------------------------------ 
		
 	
 	for b4 = 0 to 9

 	
 	gosub loop_1sec						'call up 1 second delay with button watch loop
 	lookup b4,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte 'tens segment turn on 9
 		gosub out595
 	outbyte = %00000110					'Send 1 to tens segment
 		gosub out595
 	pulsout latchout,1
 	next b4	
 	
 	
 
'------------------------------------------------  count down from 9 to 00  ------------------------------------------------	
	
 	for b5 = 0 to 9

 
 	gosub loop_1sec						'call up 1 second delay with button watch loop
 	lookup b5,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte 'tens segment turn on 9
 		gosub out595
 	outbyte = %00000000					'blank tens segment
 		gosub out595
 	pulsout latchout,1  
 	next b5 
 	  
'---------------------------------------------  Flash digits and Siren  ---------------------------------------------	
	
	for b6 = 1 to 2						'2 cycle loop for buzzer
	outbyte = %00111111					'Send 0 to units Segment
 	gosub out595 						'send this b5 value to register, DS
 	outbyte = %00111111					'Send 0 to Tens Segment
 	gosub out595
 	pulsout latchout,1					'Display 2 new digits once both are loaded into their 595s 	
	High C.3							'high to buzzer and light
 	pause 300							'slight pause between siren
 	outbyte = %00000000					'blank units Segment
 	gosub out595 						'send this b5 value to register, DS 
 	outbyte = %00000000					'blank Tens Segment
 	gosub out595
 	pulsout latchout,1					'Display "00" once both are loaded into their 595s 
 	low C.3
 	pause 300
 	next b6
 	goto startsc							'go back to start of count
 	
 	'---------------------------------------------  THE END  -----------------------------------------------------
'
' **** Subroutines ****
'
out595:
 	b0 = %10000000 						'We want to look at the left most bit(MSB) first
 	for b1 = 0 to 7 						'loop 8 times to get all bits
	 	b2 = outbyte&b0 					'Look at the MSB
	 	if b2 = b0 then 					'if the MSB is high output high
			high dataout
	 	else
	 		low dataout 				'else if the MSB is low output low
	 	endif
		pulsout clk, 1 					'pulse the clock line to move the output bit into the register
	 	b0 = b0 / 2 					'clock the next bit out
 	next b1
 	return
 	 	
loop_1sec:
	
	for w0 = 1 to 150
	gosub buttonck
		next w0
	return
	
	
buttonck:
	pause 10
	if pinC.6 = 1 then 					'if pausesc button then return to countdown
 	       gosub pausesc
 	endif
 	if pinC.7 = 1 then 					'if resetsc button pressed restart countdown
 	       goto startsc
 	endif
 	 	if pinB.0 = 1 then 				'if resetgc button pressed restart countdown
 	       goto startsc
 	endif 
 	 return



pausesc:
							
	if pinC.5 = 1 then 					'if pausesc button then resume to countdown
 	       return
 	endif
 	if pinC.7 = 1 then 					'if resetsc button pressed then go back to start
 	       goto startsc
 	endif
 	if pinB.0 = 1 then 					'if resetgc button pressed restart countdown
 	       goto startsc
 	endif 
 		 	if pinC.4 = 1 then 			'if siren button pressed then goto siren:
 	       gosub siren
 	endif	       
 	goto pausesc
 	


siren:
do
	high C.3
	if pinC.4 = 0 then
	low C.3
	return
	endif
	
loop
 

Jaden

Senior Member
OK found two outbyte's in Start0: & Start1: , was hopiong they would ignore each other? Just labeled the second one outbyte2.
 

Renegade605

New Member
The important thing to remember is that picaxe is only running two tasks in parallel, not actually running two separate programs anything and everything you define applies to the whole program (ie. all tasks). I always make a point to use the task number when defining labels, symbols, etc. that only apply to one task. In thi case: outbyte0 and outbyte1. It's a good habit to get in to.

Edit: sorry didn't see your last post. After you fixed your symbol error, what error message are you getting?
 

westaust55

Moderator
Anybody able to help as to why I cannot parallel task on the 20M2? Should work?

Some additional information might help folks here to better understand what the specific problem is and where to look.

Back at post 1 you say that you ran each program separately in the PE simulator and they worked.
Have you tried each separately in the actual 20M2 and project hardware to test operation and communication with the MAX7219 and the 74HC595’s?

Can you be more clear as to what does not work when you parallel task.
Is this in the PE simulator or in hardware?
Any error messages from the PE or observations from the hardware when code is downloaded?
Does one part seem to hang but the other part continues to run?
 

Renegade605

New Member
The one thing that jumps out at me without more info is that you capitalized the "startX" labels. I don't know if that matters or not but I have successfully run multitasking before on a 20M2 without capitalizing those labels, and it worked just fine.
 

Jaden

Senior Member
Ok, I have renamed the second outbyte to outbyte2 and I do not get any more errors, I have also taken the capitals out of the start flags. I can run both programs independently in VSM with no problems, put them both together (with no errors from the programming editor) and I get no display on the 4 x SS and just all segments on the 2 x SS. I have labeld program 1 start0: and two start1: .

I have the 4 x SS showing correct numbers and counting down on the circuit boards, I am yet to hook up the large 2 x SS for the 30 second count down. In VSM I can start the 30 second count down but the numbers are all over the place. I will print out the program(s) and check if I am using the same terminology somewhere? I was hoping they would be treated as two different sand box type situations.

I will try running both displays tomorrow seperatly on the bench and then try the combined programs in the 20M2.

Thansk so far.
 

Jaden

Senior Member
OK, I have sent the combined program to the 20M2 and my 4 x SS's (all I have connected so far), will count down but the 1st digit is showing 0 and should be blanked, seems to point to duplicate values in both programs! Will print out and check.
 
Last edited:

thomasfoltz

New Member
Basic is a language that doesn't have distinguish between local variables and global variables, as C does. So, both tasks share the same variables, and basic switches all characters to lower case before it uses them, or defines them.
 

Jaden

Senior Member
This is where I am at, hopefully someone can see where I have a problem? I am still using VSM to run this on my PC. I get no display on the RHS 4 x SS's and all segments on for the LHS x 2 SS's. I get the same on the bench with the actual circuit.

Thanks

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 delay   = w1 					' 
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

let pinsC = %00000000
let pinsB = %00000000

' === Directives ====
	#picaxe 20M2 					' specify PICAXE processor

' ============================== Begin Main Program =============================

'*************** Work in progress **********************************
	'Serin B.2,N2400, bcd

 
	
	
	
'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===============================
		
'*** Until serin is working make game start at 7:00
'*** a few look @ pinB.1 here to ensure it cathes the button press!		
		
time7:


	maxReg = 1 							' 1st LED from left = "Blank"
	outByte = 15
	gosub shout16
		
		if pinB.1 = 1 then  				' Wait for startgc to be pressed.
	 goto time6 
	 endif
	
	maxReg = 2 							' 2nd LED from left = "0"
	outByte = 7
	gosub shout16
	 
	 	if pinB.1 = 1 then  				' Wait for startgc to be pressed.
	 goto time6 
	 endif
	 
	maxReg = 3 							' 3nd LED from left = "0"
	outByte = 0
	gosub shout16
	
	 	if pinB.1 = 1 then  				' Wait for startgc to be pressed.
	 goto time6 
	 endif
	 
	maxReg = 4 							' 4th LED from left = "0"
	outByte = 0
	gosub shout16
	
		if pinB.1 = 1 then  				' Wait for startgc to be pressed.
	 goto time6 
	 endif
	 
	 
	goto time7	
	

time6:
'==== 1 second pause from 7:00 to 6:59. Remove when serin working

	for delay = 1 to 450 step 1			' 1 second delay
		if pinB.0 = 1 then goto start0		' watch for reset button to be pressed
	next delay						' back to delay
	
	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 oneseccount
	
	

	
'==========================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
	  						'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
	
'==================================End Of Siren==================================

goto start1							' 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
	
	
	for delay = 1 to 450 step 1			' 1 second delay
		if pinB.0 = 1 then goto start0		' watch for reset button to be pressed
	next delay						' back to delay
	
	next x
	next y
	
	return
	
	
oneseccount:

' This bit willcount from 59 to 0 and dblank the 3rd SS at 9 to 0
	for y = 5 to 1 step -1			'3rd SS count from 5 to 1
	maxReg = 3
	outbyte = y
	gosub shout16
	
	for x = 9 to 0 step -1			' 4th SS count 9 to 0
	maxReg = 4
	outByte = x
	gosub shout16 
	for delay = 1 to 450 step 1
		if pinB.0 = 1 then goto start0
	next delay
	
	next x
	next y
	
	maxReg = 3 					' 3nd LED from left = "0"
	outByte = 15
	gosub shout16
	
	for b9 = 9 to 0 step -1			' Only 4 SS will show a count
	maxReg = 4
	outByte = b9
	gosub shout16
	for delay = 1 to 450 step 1
		if pinB.0 = 1 then goto start0
	next delay
	next b9
	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
	
	return
	



end
'===========================================END OF PROGRAM 1===========================================================
'====================================================================================================================
 
Last edited:

Jaden

Senior Member
Second part, too big for one post.

Code:
start1:
 ' PICAXE-20M2 
 ' Shotclk.bas
 ' Count down a given number to zero on a two digit 7-segment display
 ' using a 74HC595 Shift Register.
 ' pin 11 SH_CP Shift register clock input
 ' pin 12 ST_CP Storage register clock input
 ' pin 14 DS Serial data input
 '
 ' pin 11 - C.2 SH-CP (20M2 pin 8)
 ' pin 12 - C.1 ST_CP (20M2 pin 9)
 ' pin 14 - C.0 DS (20M2 pin 10)
 '
 
 ;DS = C.0  pin 10 Picaxe / Serial data input pin 14 595
 ;STCP = C.1 pin 9 Picaxe /  Storage register pin 12 595
 ;SHCP = C.2  pin 8 Picaxe / Shift register pin 11 595
 
 
 ;General Purpose Bytes Used
 ;b0, b1, b3, b4, b5, b6, b20 
 
 'Pin 18 - B.0 - resetgc
 'Pin 17 - B.1 - startsc
 'Pin 6 - C.4 - siren
 'Pin 5 - C.5 - startsc
 'Pin 4 - C.6 - pausesc
 'Pin 3 - C.7 - resetsc   
 
 symbol dataout = C.0
 symbol clk = C.2
 symbol latchout = C.1
 symbol out = b0
 symbol loop1 = b1
 symbol loop2 = b2
 symbol outbyte2 = b3
 symbol status = b20 
 
 let pinsC = %00000000
 let pinsB = %00000000

startsc:

	outbyte2 = %00111111					'Send 0 to units Segment
 	gosub out595 						'send this b5 value to register, DS
 	outbyte2 = %01001111					'Send 3 to Tens Segment
 	gosub out595
 	pulsout latchout,1 					'Display 2 new digits once both are loaded into their 595s
 		if pinB.1 = 1 then 				'if startgc button then return to countdown
 	       goto main
 	endif
	if pinC.5 = 1 then 					'if startsc button then return to countdown
 	       goto main
 	endif
 	goto startsc						'loop until it is, if it is, start countdown

main: 
	 	
'------------------------------------------------  count down from 29 to 20  ------------------------------------------------
	
	
 	for b8 = 0 to 9
 		
 	gosub loop_1sec						'call up 1 second delay with button watch loop
 	lookup b8,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte2 'tens segment turn on 9
 		gosub out595	
 	outbyte2 = %01011011					'Send 2 to tens segment
 		gosub out595	
 	pulsout latchout,1 
 	next b8
 	
 	
 		
'------------------------------------------------  count down from 19 to 10  ------------------------------------------------ 
		
 	
 	for b4 = 0 to 9

 	
 	gosub loop_1sec						'call up 1 second delay with button watch loop
 	lookup b4,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte2 'tens segment turn on 9
 		gosub out595
 	outbyte2 = %00000110					'Send 1 to tens segment
 		gosub out595
 	pulsout latchout,1
 	next b4	
 	
 	
 
'------------------------------------------------  count down from 9 to 00  ------------------------------------------------	
	
 	for b5 = 0 to 9

 
 	gosub loop_1sec						'call up 1 second delay with button watch loop
 	lookup b5,(%01100111, %01111111, %00000111, %01111100, %01101101, %01100110, %01001111, %01011011, %00000110, %00111111),outbyte2 'tens segment turn on 9
 		gosub out595
 	outbyte2 = %00000000					'blank tens segment
 		gosub out595
 	pulsout latchout,1  
 	next b5 
 	  
'---------------------------------------------  Flash digits and Siren  ---------------------------------------------	
	
	for b6 = 1 to 2						'2 cycle loop for buzzer
	outbyte2 = %00111111					'Send 0 to units Segment
 	gosub out595 						'send this b5 value to register, DS
 	outbyte2 = %00111111					'Send 0 to Tens Segment
 	gosub out595
 	pulsout latchout,1					'Display 2 new digits once both are loaded into their 595s 	
	High C.3							'high to buzzer and light
 	pause 300							'slight pause between siren
 	outbyte2 = %00000000					'blank units Segment
 	gosub out595 						'send this b5 value to register, DS
 	outbyte2 = %00000000					'blank Tens Segment
 	gosub out595
 	pulsout latchout,1					'Display "00" once both are loaded into their 595s 
 	low C.3
 	pause 300
 	next b6
 	goto startsc							'go back to start of count
 	
 	'---------------------------------------------  THE END  -----------------------------------------------------
'
' **** Subroutines ****
'
out595:
 	b0 = %10000000 						'We want to look at the left most bit(MSB) first
 	for b1 = 0 to 7 						'loop 8 times to get all bits
	 	b2 = outbyte2 & b0 					'Look at the MSB
	 	if b2 = b0 then 					'if the MSB is high output high
			high dataout
	 	else
	 		low dataout 				'else if the MSB is low output low
	 	endif
		pulsout clk, 1 					'pulse the clock line to move the output bit into the register
	 	b0 = b0 /2 					'clock the next bit out
 	next b1
 	return
 	 	
loop_1sec:
	
	for w1 = 1 to 450						' 150 seems to take 1 second
	;gosub buttonck
		next w1
	return
	
	
buttonck:
	
	if pinC.6 = 1 then 					'if pausesc button then goto to pause
 	       goto pausesc
 	endif
 	if pinC.7 = 1 OR pinB.0 = 1 then 					'if resetsc button pressed restart countdown
 	       goto startsc
 	endif
  	 return



pausesc:
	
	pause 10						
	if pinC.5 = 1 then 					'if pausesc button then resume to countdown
 	       return
 	endif
 	if pinC.7 = 1 OR pinB.0 = 1 then 					'if resetsc button pressed then go back to start
 	       goto startsc
 	endif
 		 
 	goto pausesc
 

Jaden

Senior Member
OK, seems to have a lot to do with the two programs start labels. I call the first start0: & the second start:, I can now get both lot of SS's to show something but controls do not do as they do for individual programs running on the 20M2. I will keep digging.
 

Jaden

Senior Member
So with start0 and start I can get the first program to run but not the second! Is there some other command I have to use to tell the 20M2 to multitask? If I use start0 & start1 (or any other number) it will not work.


mmmm. Ok I will shut up for a while as I am still trying all this using VSM and posibly it cannot multitask? I will finsdih hooking up the circuit and try it then.........
 
Last edited:

hippy

Ex-Staff (retired)
You seem to have a "Goto Start1" in the "Start0:" code which will probably cause problems.

Both "Start0:" and "Start1:" code uses the same 'b' and 'w' variables which will likely cause unwanted interaction between the two tasks.

Perhaps take a slight detour and get familiar with the multitasking capabilities of the chips with simpler and easier to follow code before trying to mash two separate programs together with the hope it will work.
 
Top