Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic Assembler #define / undefine

Status
Not open for further replies.

Wp100

Well-Known Member
Hi,

Am using the code below to simply read from a sensor on PortA,2 then move to another sensor on PortA,3

The first sensor is read fine, but the second sensor which should have been redefined to PortA,3 is still being read from PortA,2 .

Have used debugger etc but nothing I look at can show me that the undefine and define to PortA,3 has actually worked.

Is there something that does show the defines ? or have I coded them incorrectly ?

thanks

Code:
#define  DS18PORT	PORTA, 2	; set up for sensor1 on portA 2	
#define	 DS18TRIS	TRISA, 2

	call	DS18B20_convert	

; more main loop code etc
			
		
#undefine  	 DS18PORT				; set up for sensor2 on portA,3
#undefine	 DS18TRIS	
#define  DS18PORT	PORTA, 3
#define	 DS18TRIS	TRISA, 3

	call	DS18B20_convert				

; more main loop code etc

#undefine DS18PORT					; restore ports for sensor1 
#undefine DS18TRIS
#define  DS18PORT	PORTA, 2		
#define	 DS18TRIS	TRISA, 2

; go to start of main loop
 
Hi,

The Called subroutine uses a lot of Port and Tris changes so it seemed reasonable to simply redefine those strings, the Assembler Help gives this example.

Just that it would save a lot of coding making several subroutines each with their unique port address.
( don't want to daisy chain several sensors to the one pin)

Assembler Help example
#undefine lngth ;Undefine label 'lngth'.
#undefine wdth ;Undefine label 'wdth'
#define lngth 0 ;Define label 'lngth' to '0'.
 
Hi,

Did some further simple switch input tests and able to prove the redefines worked ok.

Must be a problem with my code later on - probably due to a Banking error - not used to using more than 256 bytes / one bank of 18f memory !
 
Hi,

The Called subroutine uses a lot of Port and Tris changes so it seemed reasonable to simply redefine those strings, the Assembler Help gives this example.

Just that it would save a lot of coding making several subroutines each with their unique port address.
( don't want to daisy chain several sensors to the one pin)

I don't see how it can?, 'define' is an assembler instruction, so you can't redefine code in the same subroutine as it has no effect at run time.
 
I don't see how it can?, 'define' is an assembler instruction, so you can't redefine code in the same subroutine as it has no effect at run time.


Hi,

Though my redefine and simple hardware test worked ok, it was, of course, not calling that same DS1820 subroutine.

So Yes, many thanks, I DO see my misconception now :eek:
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top