Can someone explain 28x2 port syntax

MrSandman

New Member
Hi all. I've been a lurker on this forum for about 5 years and have built many 08, 08m, 18A and 18x projects and always found the results to my problems here.

My programs are wanting more I/O pins so the 28X2 is the next chip to play with.

When I run a syntax check, I get an error when using the following code. Can someone help me get my head around the configuring of Ports A,B, & C on the 28x2. Any help is apreciated.
Im using PE 5.2.7 the 28X2 FW is B.1

Thanks
Murray from NZ

Code:
#picaxe 28X2				'Compile with 28X2

'***** Inputs Port A  *****
symbol	ADC0	= 0			'ADC - 0
symbol	ADC1	= 1			'ADC - 1
symbol 	PA2	= A.2			'PortA pin2 - Active Low)
symbol	PA3	= A.3			'PortA pin3 - Active Low)

symbol 	Temp	= b1			'Temp Val
symbol 	Temp1	= b2			'Temp Val

'***********************************************************

Init:
	let dirsA = %00000000		'Set port A as Inputs
	let dirsB = %11111111		'Set port B as Outputs
	let dirsC = %11111111		'Set port C as Outputs
	let adcsetup = 2		             'Setup ADC on A.0 and A.1

Main:
	readADC ADC0,TEMP		'Read ADC value
	readADC ADC1,TEMP1		'Read ADC value
	sertxd ("ADC0 = ",#TEMP,"     ADC1 = ",#Temp1,CR,LF)
'				The above works as expected	
	
' Both the next two lines give syntax errors
	
	if PA2 = 0 then Blah1		'If PA2 goes LOW >Blah1
	if PA3 = 0 then Blah2		'If PA3 goes LOW >Blah2

	pause 100
	goto Main
	
	
Blah1:
	sertxd ("Port A.2 = Low",CR,LF)
	pause 100
	goto Main
	
Blah2:
	sertxd ("Port A.3 = Low",CR,LF)
	pause 100
	goto Main
 

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

The problem is in -

Symbol PA2 = A.2
If PA2 = 1 Then ...

What you are doing is using a 'pin number' rather than a pin variable. That expands to the equivalent of "If A.2 = 1 Then" and gives a syntax error.

What you probably want is -

Symbol PA2 = pinA.2
If PA2 = 1 Then ...

which expands to "If pinA.2 = 1 Then"
 
Last edited:

iGull

New Member
Code:
#picaxe 28X2				'Compile with 28X2

'***** Inputs Port A  *****
symbol	ADC0	= 0			'ADC - 0
symbol	ADC1	= 1			'ADC - 1
symbol 	PA2	= A.2			'PortA pin2 - Active Low)
symbol	PA3	= A.3			'PortA pin3 - Active Low)

symbol 	Temp	= b1			'Temp Val
symbol 	Temp1	= b2			'Temp Val

'***********************************************************
Greetings from sunny Scotland :)

I've had similar issues recently with the 28X2 - here's the fixed code ...
Code:
#picaxe 28X2

'***** Inputs Port A  *****
symbol	ADC0	= 0			'ADC - 0 - leg 2
symbol	ADC1	= 1			'ADC - 1 - leg 3
symbol 	PA2	= pinA.2		'PortA pin2 - Active Low) leg 4
symbol	PA3	= pinA.3		'PortA pin3 - Active Low) leg 5

symbol 	Temp	= b1			'Temp Val - legless :-)
symbol 	Temp1= b2		        'Temp Val

'***********************************************************
Remove any comments after the # compiler directive, that will fail in Axepad (certainly in my Mac version which I would assume is a bug although it may be a feature :)). Change A.2 to pinA.2/pinA.3 - all compiles fine. I tend to mark the leg numbers in the comments to clarify things a few weeks down the line :0(
Hope I've helped.

Cheers

Neil
 

eclectic

Moderator
Welcome to the forum, at last. :)

I've made a couple of changes, marked with ******

I'm sure there'll be a more erudite explanation posted soon.

Code:
#picaxe 28X2				'Compile with 28X2

'***** Inputs Port A  *****
symbol	ADC0	= 0			'ADC - 0
symbol	ADC1	= 1			'ADC - 1
symbol 	PA2	= PinA.2	;******'PortA pin2 - Active Low)
symbol	PA3	= PinA.3	;******'PortA pin3 - Active Low)

symbol 	Temp	= b1			'Temp Val
symbol 	Temp1	= b2			'Temp Val

'***********************************************************

Init:
	let dirsA = %00000000		'Set port A as Inputs
	let dirsB = %11111111		'Set port B as Outputs
	let dirsC = %11111111		'Set port C as Outputs
	let adcsetup = 2		             'Setup ADC on A.0 and A.1

Main:
	readADC ADC0,TEMP		'Read ADC value
	readADC ADC1,TEMP1		'Read ADC value
	sertxd ("ADC0 = ",#TEMP,"     ADC1 = ",#Temp1,CR,LF)
'				The above works as expected	
	
' Both the next two lines give syntax errors
	
	if PA2 = 0 then Blah1		'If PA2 goes LOW >Blah1
	if PA3 = 0 then Blah2		'If PA3 goes LOW >Blah2

	pause 100
	goto Main
	
	
Blah1:
	sertxd ("Port A.2 = Low",CR,LF)
	pause 100
	goto Main
	
Blah2:
	sertxd ("Port A.3 = Low",CR,LF)
	pause 100
	goto Main
e

Talk about simultaneity! :)
 
Last edited:

MrSandman

New Member
Thanks

Thanks for the prompt replies.:)
Now I can carry on with the bigger program.
No doubt I'll be back. :p
Murray
 
Top