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 12F508 Call & Goto

Status
Not open for further replies.

Suraj143

Active Member
How can I achieve the "Call" instruction above 256 boundary in program memory?

The "Goto" instruction works in all 512 locations.
But "Call" instruction only works in upper 256.
 
Last edited:
Place it in the lower 256 bytes of program ROM like so -

Code:
		org		0x000		;reset vector
		goto		START

		<place subroutines here>

START		<place main code here>
 
Last edited:
Hi Jon thanks for your input.But see according to your method if I want to use "Call" instruction above 256th location it will not work.

Code:
		org	0x100		; 256 program memory
Main_Loop	nop
Do_Pattern_1	movlw	b'00010101'
		movwf	GPIO
		call	Delay
		movlw	b'00001010'
		movwf	GPIO
		call	Delay
		movlw	b'00000100'
		movwf	GPIO
		call	Delay
		movlw	b'00001000'
		movwf	GPIO
		call	Delay
 
It doesn't matter where the call instruction itself resides. It matters where the subroutine that you are calling resides.

On the 12F508, the address that the program counter gets modified with on a call or a goto instruction come from the lower 9 bits of the instruction itself (bits 0-8). However, on a call instruction, bit 8 is always clear. This means that you can only place subroutines in the lower 256 bytes of program ROM.

However, with the page access bit in the STATUS register (bit PA0), you can also place them in the lower 256 addresses of the upper half of memory.

So if you plan to place them in the lower half of program ROM, you have to type out your code as I illustrated above. If you plan to place your subroutines in the lower half of the upper half of program ROM, then you can do this instead -

Code:
		org		0x000		;reset vector
		goto		START

START		<place main code here>

		org		0x200
		<place subroutines here>

However, if you place your subroutines between addresses 0x200 - 0x2FF, you have to use a bsf instruction to set bit PA0 in the STATUS register prior to calling the subroutine.

Code:
		bsf		STATUS,PA0
		call		SubroutineName

Hope this helps.
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top