Jump to content

Recommended Posts

Hi,

 

I wanted to make a macro for the PIC16F1824 but since the ADC unit does have an error I wanted to put the code fix for the hardware bug is asm code. All is working fine without the loopi goto. I am not able to make a goto or bra since I get a compiler error.. How to do this ?.

//Make a 16 bit long value from adresh:adresl registers
#define ReadADC( dst )	asm bsf 	_adcon0,1 	\
					asm movlw	0x01		\
loopi:											\
					asm addlw	0x01		\
					asm btfss	_status,0	\
					asm	bra		_loopi		\
					asm bcf 	_adcon0,1	\
					asm comf 	_adresl, W	\
					asm movwf	_##dst		\
					asm comf 	_adresh, W 	\
					asm andlw	0x03		\
					asm movwf 	_##dst##+1

 

PaulHolland.

Link to post
Share on other sites
I wanted to make a macro for the PIC16F1824 but since the ADC unit does have an error I wanted to put the code fix for the hardware bug is asm code. All is working fine without the loopi goto. I am not able to make a goto or bra since I get a compiler error.. How to do this ?.

Looks like the problem is cause by the continuation character which combines all the ASM lines into one.

For the compiler the label needs to be at the start of a line, so the macro fails.

 

The work around is to split the macro into two:

#define ReadADC1( dst )  asm bsf	 _adcon0,1	 \
					asm movlw	0x01 \

#define ReadADC2( dst ) loopi: \
					asm addlw	0x01		\
					asm btfss	_status,0	\
					asm	bra		loopi		\
					asm bcf	 _adcon0,1	\
					asm comf	 _adresl, W	\
					asm movwf	_##dst		\
					asm comf	 _adresh, W	 \
					asm andlw	0x03		\
					asm movwf	 _##dst##+1\

Regards

Dave

Link to post
Share on other sites
I wanted to make a macro for the PIC16F1824 but since the ADC unit does have an error I wanted to put the code fix for the hardware bug is asm code. All is working fine without the loopi goto. I am not able to make a goto or bra since I get a compiler error.. How to do this ?.

Looks like the problem is cause by the continuation character which combines all the ASM lines into one.

For the compiler the label needs to be at the start of a line, so the macro fails.

 

The work around is to split the macro into two:

#define ReadADC1( dst )  asm bsf	 _adcon0,1	 \
					asm movlw	0x01 \

#define ReadADC2( dst ) loopi: \
					asm addlw	0x01		\
					asm btfss	_status,0	\
					asm	bra		loopi		\
					asm bcf	 _adcon0,1	\
					asm comf	 _adresl, W	\
					asm movwf	_##dst		\
					asm comf	 _adresh, W	 \
					asm andlw	0x03		\
					asm movwf	 _##dst##+1\

Regards

Dave

 

Thanks dave.

 

Would it not be possible to do it different ?. Maybe grouping all asm code in one ?. Like: asm { .... } I tried myself but it did also fail .

I also have a question !. In MPASM and many other assemblers you can use the $ sign for current address so: goto $+1 is jumping at the current address + 1. How can I use this in your compiler ?. Its very handy since you can use nop for 1 cycle delay and goto for 2 cycle delay while using only 1 word address space. saving 50%.

 

regards, PaulHolland

Edited by PaulHolland
Link to post
Share on other sites
I wanted to make a macro for the PIC16F1824 but since the ADC unit does have an error I wanted to put the code fix for the hardware bug is asm code. All is working fine without the loopi goto. I am not able to make a goto or bra since I get a compiler error.. How to do this ?.

 

You need to prefix labels with asm keyword like:

 

#define ReadADC2( dst ) asm loopi: \
					asm addlw	0x01		\
					...

 

Regards,

Pavel

Link to post
Share on other sites

Hi,

 

Its not my question you replied !.

 

1: Would it not be possible to do it different ?. Maybe grouping all asm code in one ?. Like: asm { .... } I tried myself but it did also fail .

2: I also have a question !. In MPASM and many other assemblers you can use the $ sign for current address so: goto $+1 is jumping at the current address + 1. How can I use this in your compiler ?. Its very handy since you can use nop for 1 cycle delay and goto for 2 cycle delay while using only 1 word address space. saving 50%.

 

thanks for your help.

 

This code example works in your compiler but not in a macro !!!..

			
			asm {
							movwf	FSR			;
			clrf	aux4		; Reset pointer.

Copy_FLLoop;		call	Key_table	; W input is address, W output is byte from FLASH.
			movwf	INDF		; Save byte into RAM pointed by FSR pointer.
			incf	FSR,f		; Inc. pointer.
			incf	aux4,f		;	
			decfsz	aux,f		;
			goto	Copy_FLLoop	;
			return				;
					 }

Edited by PaulHolland
Link to post
Share on other sites

I dont think BoostC supports the MPASM $ operator (or most other complex MPASM expressions) :-(

That's why a number of us are agitating for the capability to write library functions for BoostC in MPASM/GPASM.

 

To get it 'all in one' why not try:

//Make a 16 bit long value from adresh:adresl registers
   #define ReadADC( dst ) asm base: /* only legal place for a label */ \
				asm bsf	_adcon0,1   \
				asm movlw  0x01		   \
	/*loopi:*/  asm addlw  0x01		 \
				asm btfss  _status,0	\
				asm bra	_base+2  /*_loopi*/ \
				asm bcf	_adcon0,1   \
				asm comf   _adresl, W   \
				asm movwf  _##dst	   \
				asm comf   _adresh, W  \
				asm andlw  0x03		   \
				asm movwf  _##dst##+1

Edited by IanM
Link to post
Share on other sites

Hi, Ian,

 

Its a pitty. But $ is not only a MPASM statement I have used it and seen it on many assemblers starting with the 8748/49 from Intel :-)

 

It would be more usefull if boostC would be able to use obj files generated with other compilers or assemblers since this would make it all possible even without re-inventing the weel. Most obj file formats follow one of two standards, following this would open a complete new world. Improving the *.lst file would also be usefull since this would enable real men to optimize the code they write in C.

 

PaulHolland.

Link to post
Share on other sites

Yes '$' has been around a while. IIRC I first met it in the early '80s in Hisoft GENS3 - a Z80 assembler:

2.3. Location Counter

The assembler maintains a location counter so that a symbol in the label field can be associated with an address and

entered into the symbol table. This location counter may be set to any value via the ORG assembler directive (see Section

2.7).

The symbol '$' can be used to refer to the current value of the location counter e.g. LD HL,5 would generate code

that would load the register pair HL with a value 5 greater than the current location counter value.

 

I dont expect to see MPASM object files used internally, because BoostLink does some special stuff that the Microchip linker doesn't handle. For similar reasons HiTech provide their own linker for PICC, however it would be nice to be able to 'import' MPASM format object files.

 

Also you don't need a better list file, just open the .casm file! :(

Edited by IanM
Link to post
Share on other sites
Its not my question you replied !.

 

1: Would it not be possible to do it different ?. Maybe grouping all asm code in one ?. Like: asm { .... } I tried myself but it did also fail .

 

No asm{} block can not be used inside a pre-processor macro. The reason for this is that when continuation operation used inside a macro

 

#define TEST() asm \
				   { \
				   movlw 3 \
				   movlw 4 \
				   movlw 5 \
				   }

 

pre-processor removes end of lines and puts all instructions on one line:

 

asm { movlw 3 movlw 4 movlw 5 }

 

while compiler expects every assembly instruction to be on a separate line.

 

I suggest to wrap your assembly code into an inline function and call this function instead of macros. Because function is inline compiler will embed code from it into every call so the effect will be same as if macros were used.

 

Regards,

Pavel

Link to post
Share on other sites

Paul,

I wanted to make a macro for the PIC16F1824 but since the ADC unit does have an error I wanted to put the code fix for the hardware bug is asm code. All is working fine without the loopi goto. I am not able to make a goto or bra since I get a compiler error.. How to do this ?.

//Make a 16 bit long value from adresh:adresl registers
#define ReadADC( dst )	asm bsf 	_adcon0,1 	\
					asm movlw	0x01		\
loopi:											\
					asm addlw	0x01		\
					asm btfss	_status,0	\
					asm	bra		_loopi		\
					asm bcf 	_adcon0,1	\
					asm comf 	_adresl, W	\
					asm movwf	_##dst		\
					asm comf 	_adresh, W 	\
					asm andlw	0x03		\
					asm movwf 	_##dst##+1

 

The way to make this work is as Pavel pointed out:

 

//Make a 16 bit long value from adresh:adresl registers
#define ReadADC( dst )	asm bsf 	_adcon0,1 	\
					asm movlw	0x01		\
					asm loopi:	\
					asm addlw	0x01		\
					asm btfss	_status,0	\
					asm	bra		_loopi		\
					asm bcf 	_adcon0,1	\
					asm comf 	_adresl, W	\
					asm movwf	_##dst		\
					asm comf 	_adresh, W 	\
					asm andlw	0x03		\
					asm movwf 	_##dst##+1

 

Regards

Dave

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...