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 instruction!

Status
Not open for further replies.
My aversion to the use of even my (more efficient) macro was the fact it makes the source unreadable. In effect you need a banksel before every memory access. Much better to learn which registers are in which bank and use a single bsf etc to switch banks at the appropriate time. Microchip, in their wisdom, removed all the register addresses from the data sheet sections - EG, timer 1 section.:confused:

On a 16F876, using banksel, writing to a tris register can take 6 instructions. This is supposed to be an efficient chip.:rolleyes:

I thought your improved macro just inserted the single required BSF? - perhaps I was thinking of someone elses?.
 
I have no problem memorizing the banks, and if I forget I just check the memory block diagram on the datasheet.

This makes the code more efficient when you know which bank the code is selecting. You can group items in the same bank and perform a function on them before switching back instead of continuous switching between banks.
My macro throws a message in the listing anytime it switches banks, and a different message when it leaves the bank unchanged. That way, once my code is stable, I can make it more efficient by rearranging things to put operations in a common bank together, and I don't have to memorize which bank has what register.
 
I thought your improved macro just inserted the single required BSF? - perhaps I was thinking of someone elses?.

It does, however, if I don't know which bank something is in I have to do,
Code:
	mysel	TRISA
	movwf	TRISA
	mysel	ANSEL
	clrf	ANSEL
	mysel	ANSELH
	clrf	ANSELH
Yes, the above will assemble efficiently but is just ugly.

Mike.
 
It does, however, if I don't know which bank something is in I have to do,
Code:
	mysel	TRISA
	movwf	TRISA
	mysel	ANSEL
	clrf	ANSEL
	mysel	ANSELH
	clrf	ANSELH
Yes, the above will assemble efficiently but is just ugly.

Mike.
Next time I am up for macro hacking I plan to create macros corresponding to all the register-oriented instructions (e.g. movf/movfw/movwf/bsf/bcf etc.) which will set the bank bits (skipping this if they're already set correctly) and assemble in the instruction in question.

So, instead of Pommie's code above, I could code:

Code:
	mymovwf	TRISA
	myclrf	ANSEL
	myclrf	ANSELH
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top