First post - First programme

johnrelph

New Member
Hi
I have written this programme to control the indicators by push buttons on the steering wheel of my kitcar, but I have a small problem that I have been unable to solve, if indicating right or left when the hazards activated the programme returns to indicate when the hazards are cancelled.
Also I would appriciate any comments on my programme (but please keep it simple).
Code:
'MK indicators + hazards + sound & nc switches.

				
main:	
		let b2 = 0
		let b3 = 0
		
		setint %00000000,%00110000		'enable the interrupt 
		button c.5,1,255,0,b2,0,prc_RIGHT
		button c.4,1,255,0,b3,0,prc_LEFT		
		let b0 = 0  	
		let b1 = 0  	
		goto main

	
prc_RIGHT:	'right indicator	
		high 1
		pause 500	      'Wait command
		low 1					
		pause 500				

		do while pinC.4 = 1 and pinC.5 = 1	' repeat		
		let b0 = b0 + 1	      'Inc command
		high 1
		pause 300	      'Wait command
		low 1		
		pause 250	      'Wait command
		sound 6,(90,10)
		if b0 >= 12 then main:   'Compare command		
		loop		     'End of repeat loop 

		low 1,2	
		wait 2	         'Wait command
		goto main
	 

 
prc_LEFT:	'left indicator
		high 2	'set output 2 on				
		pause 500	'Wait command		
		low 2				
		pause 500
		
		do while pinC.4 = 1 and pinC.5 = 1	' repeat		
		let b1 = b1 + 1		'Inc command
		high 2	'set output 2 on				
		pause 300	'Wait command		
		low 2
		pause 250
		sound 6,(106,10)
		if b1 >= 12 then main:	'Compare inputs
		loop		'End of repeat loop 

		low 1,2		
		wait 2	'Wait command
		goto main




interrupt:	'Hazards
		high 1,2		
		pause 400	'Wait command
		low 1,2					
		pause 400
		
		do while pinC.4 = 1 and pinC.5 = 1	' repeat
		high 1,2			
		pause 400	'Wait command
		low 1,2		
		sound 6,(90,10,100,20)		
		loop		'End of repeat loop 
		
		wait 2
		low 1,2	'Wait command
		return


#no_data			'reduce download time
sorry and thankyou
 
Last edited:

westaust55

Moderator
@John,

Welcome to the PICAXE forum.

In line with another recent post, when you are posting program code listings of more than a few lines,
it is good forum etiquette as described in the sticky read me first post here:
http://www.picaxeforum.co.uk/showthread.php?7679-Read-Me-First!

to place your code within [code] and [/code] tags so that it appears in a sub window within your post.
this will also retain any indenting tyou have so the code is more readable. To demonstrate here is you code with indenting included for the program lines and loop nesting etc.

Code:
'MK indicators + hazards + sound & nc switches.
#no_data 'reduce download time

main: 
	let b2 = 0
	let b3 = 0

	setint %00000000,%00110000 'enable the interrupt 
	button c.5,1,255,0,b2,0,prc_RIGHT
	button c.4,1,255,0,b3,0,prc_LEFT 
	let b0 = 0 
	let b1 = 0 
	goto main


prc_RIGHT: 'right indicator 
	high 1
	pause 500 'Wait command
	low 1 
	pause 500 

	do while pinC.4 = 1 and pinC.5 = 1 ' repeat 
		let b0 = b0 + 1 'Inc command
		high 1
		pause 300 'Wait command
		low 1 
		pause 250 'Wait command
		sound 6,(90,10)
		if b0 >= 12 then main: 'Compare command 
	loop 'End of repeat loop 

	low 1,2 
	wait 2 'Wait command
	goto main



prc_LEFT: 'left indicator
	high 2 'set output 2 on 
	pause 500 'Wait command 
	low 2 
	pause 500

	do while pinC.4 = 1 and pinC.5 = 1 ' repeat 
		let b1 = b1 + 1 'Inc command
		high 2 'set output 2 on 
		pause 300 'Wait command 
		low 2
		pause 250
		sound 6,(106,10)
		if b1 >= 12 then main: 'Compare inputs
	loop 'End of repeat loop 

	low 1,2 
	wait 2 'Wait command
	goto main




interrupt: 'Hazards
	high 1,2 
	pause 400 'Wait command
	low 1,2 
	pause 400

	do while pinC.4 = 1 and pinC.5 = 1 ' repeat
		high 1,2 
		pause 400 'Wait command
		low 1,2 
		sound 6,(90,10,100,20) 
	loop 'End of repeat loop 

	wait 2
	low 1,2 'Wait command
	return

I am a little confused with respect to your interrupt routine operation based upon the setup and comments provided.
you have the line
setint %00000000,%00110000 'enable the interrupt​
which will interrupt when C.4 and C.5 are both taken low

but in the interrupt you have the line
do while pinC.4 = 1 and pinC.5 = 1 ' repeat​

And with respect to your "problem", yes, when the hazard state is cancelled, the program will return to the next instruction after the that which was being executed when the interrupt occurred.
In the real world, if you have indicators on and turn on the hazard lamps, then cancel the hazard lamps, the turn indicators will continue functioning.

If you do not want this situation, then You may need to implement a flag that can be used to cancel turn indication following a cancelling of hazard lamps.

Edit:
Further, in your two code sections for both left and right indication your are looping only if both direction inputs are high ( as if in hazard mode) whereas left and right should only monitor the state of one input.
 
Last edited:

johnrelph

New Member
Hi westaust55

I am using two normally closed push buttons, if i push both together C.4 and C.5 are both taken low and
the interupt opperated, by which time the buttons are released & pins C4 & C5 are high again and the interpt will continue until either button is pressed.

Re your edit, this is done on perpose so I can cancel the indicators or hazards by pushing either button.

Thanks for your intrest / help, I will look into using a flag to solve my problem.
 
Top