PIC10f222 Calls Must Be In Lower Half of Page

Status
Not open for further replies.
With assembler not being my native language , how do you make your calls to be in the lower half of the page. Would you start your program code at say 0x100, then what? The code has been abbreviated, so please ignore the unused memory locations for now.

Code:
 LIST p=10F222, r=DEC
#include <P10F222.inc>
 __CONFIG _IOSCFS_4MHZ & _MCPU_ON & _WDT_ON & _MCLRE_OFF

;********************************************************************************

;Set aside memory locations for variables
COLOR	EQU	9
COUNT	EQU	10
DELAY	EQU	11
DELAY2	EQU	12
FRACTION255	EQU	13
FVRPT6V	EQU	14
ON_TIME	EQU	15
OPTION_REG	EQU	16
SysIFTemp	EQU	17

;********************************************************************************

;Vectors
;Start of program memory page 0
	ORG	256
BASPROGRAMSTART
;Call initialisation routines
	call	INITSYS

;Start of the main program
	movlw	B'00001000'
	tris	GPIO
	movlw	207
	movwf	OPTION_REG
MAIN
	clrf	GPIO
	;clrf	COUNT
	bsf	GPIO,0
	movlw	255
	movwf	FRACTION255
	call	DELAY1S
	bcf	GPIO,0
	movlw	255
	movwf	FRACTION255	
	call	DELAY1S
	goto	MAIN

BASPROGRAMEND
	sleep
	goto	BASPROGRAMEND

;********************************************************************************
DELAY1S
	clrf	TMR0
	clrf	DELAY
	movlw	1
	subwf	FRACTION255,W
	btfss	STATUS, C
	goto	SysForLoopEnd5
SysForLoop5
	incf	DELAY,F
	clrf	DELAY2
SysForLoop6
	incf	DELAY2,F
DELAY3
	btfss	TMR0,7
	goto	DELAY3
	clrf	TMR0
	movlw	29
	subwf	DELAY2,W
	btfss	STATUS, C
	goto	SysForLoop6
SysForLoopEnd6
	movf	FRACTION255,W
	subwf	DELAY,W
	btfss	STATUS, C
	goto	SysForLoop5
SysForLoopEnd5
	retlw	0

;********************************************************************************
INITSYS
	bcf	ADCON0,ADON
	bcf	ADCON0,ANS0
	bcf	ADCON0,ANS1
	movlw	B'11001111'
	option
	clrf	GPIO
	retlw	0

;********************************************************************************


 END
 
You could define the location the subroutine is located so you could intentionally place it in the lower half of the page.

Or if it must be in the upper half, you could use a goto jump.
Basically you call a goto instruction that points to the subroutine

The goto is placed in the lower half of the page and only takes one line while the actual subroutine it jumps to is located in the upper half.
 
Alright, using the goto trick does the job, thanks! I saw earlier in the datasheet that the goto's can address the whole page.

As far as the subs go, I'm a little dense on how you define code, or call location. I moved the subs up before Main, if that's what you mean? The disassembler listing seems to show the subs starting at 0x001, which is what I wanted. After a little fiddling with the simulator, the project builds O.K. now, and the blinky program is now working on the 10f222.

Any other comments regarding where ORG and goto 0x100 are in the program?

Code:
 LIST p=10F222, r=DEC
#include <P10F222.inc>
 __CONFIG _IOSCFS_4MHZ & _MCPU_ON & _MCLRE_OFF ;& _WDT_ON 

;********************************************************************************

;Set aside memory locations for variables
COLOR	EQU	9
COUNT	EQU	10
DELAY	EQU	11
DELAY2	EQU	12
FRACTION255	EQU	13
FVRPT6V	EQU	14
ON_TIME	EQU	15
OPTION_REG	EQU	16
SysIFTemp	EQU	17

;********************************************************************************

;Vectors
;Start of program memory page 0
goto	0x100
;********************************************************************************
INITSYS	
	bcf	ADCON0,ADON
	bcf	ADCON0,ANS0
	bcf	ADCON0,ANS1
	movlw	B'11001111'
	option
	clrf	GPIO
	retlw	0

;********************************************************************************
DELAY1S
	clrf	TMR0
	clrf	DELAY
	movlw	1
	subwf	FRACTION255,W
	btfss	STATUS, C
	goto	SysForLoopEnd5
SysForLoop5
	incf	DELAY,F
	clrf	DELAY2
SysForLoop6
	incf	DELAY2,F
DELAY3
	btfss	TMR0,7
	goto	DELAY3
	clrf	TMR0
	movlw	29
	subwf	DELAY2,W
	btfss	STATUS, C
	goto	SysForLoop6
SysForLoopEnd6
	movf	FRACTION255,W
	subwf	DELAY,W
	btfss	STATUS, C
	goto	SysForLoop5
SysForLoopEnd5
	retlw	0


	ORG	256
BASPROGRAMSTART
;Call initialisation routines
	call	INITSYS
;Start of the main program
	movlw	B'00001000'
	tris	GPIO
	movlw	207
	movwf	OPTION_REG
MAIN
	clrf	GPIO
	clrf	COUNT
	bsf	GPIO,0
	movlw	255
	movwf	FRACTION255
	call	DELAY1S
	bcf	GPIO,0
	movlw	255
	movwf	FRACTION255	
	call	DELAY1S
	goto	MAIN
BASPROGRAMEND
	sleep
	goto	BASPROGRAMEND
;********************************************************************************
 END
 
Last edited:
That looks about right.

I would just say that line 256 is referred to as

0x100
256
BASPROGRAMSTART

It can be confusing to call one thing, in this case an address, by three different names.

If you want to start the code at 256 you should just put

goto BASPROGRAMSTART

(subroutines)

Org 256
BASPROGRAMSTART

but really there is no need for the Org 256

You can just write

goto BASPROGRAMSTART

(subroutines)

BASPROGRAMSTART

and as long as your subroutines are short enough that the start of the last one is at an address <256, and there is room after the subroutines for the main code, you don't need to worry about where they are. If you don't keep the code or the subroutines short enough, the compiler will tell you anyhow.
 
Last edited:
Got it, thanks a bunch. The light bulb finally went off. I've got a couple of short subs, and one pretty long one (over 256 words), so now I know how to line things up.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…