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.

Need help with macro (very basic)

Status
Not open for further replies.
Hi Mike,
I tried this another code for macro in which I want 5 second delay and for that I used macro of 1 second delay for five times, I know why this is not working because when a macro comes the whole code in macro actually get copied so as I have used the same macro for five times all the label overlaps five times but, if I required to write the macro with different label for FIVE TIMES then what is the use of macro ?:confused:, Is there any way that I can repeat the same macro many times without overlapping it's label...
Code:
	List p=16f690
	#include <p16f690.inc>
	__CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
	ERRORLEVEL-302
;**********************************************************************
	cblock 0x20
		temp
		d1
		d2
		d3
		d4
		d5
	endc
;******************************MACRO************************************
[COLOR="Red"]seconddelay macro 
			movlw d'2'
			movwf d3
			delay:
			decfsz d1	; (256 x 1) X
			goto delay	; (2 x 1) X
			decfsz d2	; (256 x 1) X
			goto delay	; (2 x 1)  = 262144 uSec = 0.262 Sec

=262mSec X
			decfsz d3	; (2 x 1) X 
			goto delay	; (2 x 1)	= 1048mSec = 1.04Sec
			endm[/COLOR]
;***********************************************************************
	org 0x00
	goto main
;***********************************************************************
main:
portset:
	bsf STATUS,RP0
	clrf TRISC
	clrf TRISA
	clrf TRISB
	bcf STATUS,RP0
begain:
	movlw b'00000001'
	movwf PORTC
	seconddelay
	seconddelay
	seconddelay
	seconddelay
	seconddelay
	movlw b'00000000'
	movwf PORTC
	seconddelay
	seconddelay
	seconddelay
	seconddelay
	seconddelay
delayx:
	decfsz d4
	goto delayx
	decfsz d5
	goto delayx 
	goto begain
	end
 
You have to define the label as local to use it multiple times.

Code:
seconddelay	macro	 
local delay
		movlw	d'2'
		movwf	d3
delay
		decfsz	d1		; (256 x 1) X
		goto	delay		; (2 x 1) X
		decfsz	d2		; (256 x 1) X
		goto	delay		; (2 x 1)  = 262144 uSec = 0.262 Sec =262mSec	X
		decfsz	d3		; (2 x 1) X 
		goto	delay		; (2 x 1)	= 1048mSec = 1.04Sec
		endm

BTW, it is normal that labels start in the leftmost column. It took me a while to find your delay label as it was in the wrong place. You also don't need the : after the label.

Mike.
 
O.K. the "local" thing works, I knew that I need to make it "local" but, I was doing that with d1, d2 and d3 now I understand that the whole loop should be instructed to keep every label local within.
Now,here, is the main problem that I'm facing with the MACRO, I'M STILL NOT ABLE TO MAKE MACRO IN SEPARATE .ASM FILE AND THEN INCLUDE IT AND MAKE IT WORK, I write the macro without "list" and "include <16f690.inc>" and all that config. stuff and I build both successfully and load the program containing that macro .ASM file (e.g. "#include macro name ") and the error appears in PICkit2 hex loader window

"WARNING: the hex file has no configuration"

so, I tried writing "list" and all that config. before macro in macro's .ASM (I already have "list" and the config. stuff in my main project file) file then in PICkit2 loader I don't get that error message but I got all registers as 3fff( means it loads nothing, right?) and even worse is that after all this if I remove the macro's .ASM file and put the macro code in the main project's code as I have done in this 5 sec delay example then even I can not load the hex file and I have to make a new project with a new name ( with the same macro included in the main project's code) In short the modified code doesn't work even though it is right in the same project which was used with including separate macro .ASM file

Code:
List p=16f690
	#include <p16f690.inc>
	__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
	ERRORLEVEL-302
;**********************************************************************
	cblock 0x20
		temp
		d1
		d2
		d3
	endc
;***********************************************************************
	org 0x00
	goto main
;***********************************MACRO*******************************
seconddelay macro
local delay
	movlw d'4'
	movwf d3
	movlw d'250'
	movwf d1
	movlw d'250'
	movwf d2
delay
	decfsz d1	; 250x1 X
	goto delay	; 2x1 X
	decfsz d2	; 250x1 X
	goto delay	; 2x1 X
	decfsz d3	; 4x1  = 1000000uS = 1 Sec
	goto delay	; Here the delay loop start again so this should not be taken in to acount
	endm
;************************************************************************
main
portset
	bsf STATUS,RP0
	clrf TRISC
	clrf TRISA
	clrf TRISB
	bcf STATUS,RP0
;*************************************************************************
begain
	movlw b'00000001'
	movwf PORTC
	seconddelay
	seconddelay
	seconddelay
	seconddelay
	seconddelay
	movlw b'00000000'
	movwf PORTC
	seconddelay
	seconddelay
	seconddelay
	seconddelay
	seconddelay
	goto begain
	end
Sorry for starching this too long but I realy don't understand where I'm making mistake with separate file inclusion of macro.:(
Thanks for reply.
 
I can't work out what you are doing wrong so I've made a project from your file for you to look at.

Mike.
 

Attachments

  • Chriss.zip
    13.4 KB · Views: 94
I'm getting the message in MPLAB
"Unable to load the workspace because the format of the workspace has changed"
though I saw the codes its quit simple , just as I'm writing it so something must be wrong with project build, I can not open the file, using MPLAB IDE version 8.00
 
Last edited:
That must be because I'm on version 8.10

If you extract all the files to a folder you should be able to use the project wizard to create a new project in the same folder. Only add Chris.asm to the project in the wizard. You can add macro.asm later by right clicking on "other files". The attached is what you should end up with.

Mike.
 

Attachments

  • chris.png
    chris.png
    52.3 KB · Views: 133
Hey! it works:),
So fool I was that I was actually building the macro.ASM file too, so obviously, every time I was supposed get the error

"expected END"

and I put that END too:eek: , putting AN END to whole project:D:D
I noticed the "missing" END in your macro file and just had a strike, and tried writing new project without building the macro.ASM and an END ,it works.
Thank you very much for your helpful replay and standing me for so long :)
I'll try opening your project file the way you have suggested.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top