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.

Computed GOTO jumps back one byte

Status
Not open for further replies.

AGCB

Member
I have a 18F program with several computed GOTOs. When the second one is called, the PCL jumps backward one full byte (I.E. PCL = 174, on 1st table entry PCL should jump to 176 but instead jumps to 76.

I'm only using the access bank, so this could have something to do with it.

I've read on another forum that it is possible to place subroutines in a bank (not in access bank). But I do not understand how to do that. I have read the datasheet over and over and searched this and other forums, but it's still not clear to me how to use anything outside the access bank.
I do see how to place registers in a bank by stating address of CBLOCK at bank starting address.

Then again, I may be way off on this as I'm fairly new to 18F so your input will be appreciated.
 
I'd like to see your examples! Thanks Nigel

Here are the text strings from Tutorial 3.2 modified for 18F.

Code:
Text	movwf 		taboff 			; save table offset
		bcf 		STATUS,	C 		; clear STATUS bit
		rlcf 		taboff,	F 		; multiply by 2, save in taboff
		movlw 		HIGH(String1) 	; get high byte of table start
		btfsc 		STATUS,	C 		; test carry bit
		incf 		WREG,	W
		movwf 		PCLATH 			; modify PCLATH if required
		movlw 		LOW(String1) 	; get low byte of table address
		addwf 		taboff,	W 		; add in offset
		btfsc 		STATUS,	C 		; test for overflow
		incf 		PCLATH,	F 		; increment if needed
		movwf 		PCL 			; make jump, PCLATH and PCLATU are
									; written to PCH and PCU
String1	
		retlw	'1'
		retlw	'6'
		retlw	' '
		retlw	'B'
		retlw	'i'
		retlw	't'
		retlw	' '
		retlw	'C'
		retlw	'o'
		retlw	'u'
		retlw	'n'
		retlw	't'
		retlw	'e'
		retlw	'r'
		retlw	'.'
		retlw	0x00

HEX_Table	movwf 		taboff 			; save table offset
			bcf 		STATUS,	C 		; clear STATUS bit
			rlcf 		taboff,	F 		; multiply by 2, save in taboff
			movlw 		HIGH(HexStr) 	; get high byte of table start
			btfsc 		STATUS,	C 		; test carry bit
			incf 		WREG,	W
			movwf 		PCLATH 			; modify PCLATH if required
			movlw 		LOW(HexStr) 	; get low byte of table address
			addwf 		taboff,	W 		; add in offset
			btfsc 		STATUS,	C 		; test for overflow
			incf 		PCLATH,	F 		; increment if needed
			movwf 		PCL 			; make jump, PCLATH and PCLATU are
										; written to PCH and PCU
HexStr  	
            RETLW   0x30
            RETLW   0x31
            RETLW   0x32
            RETLW   0x33
            RETLW   0x34
            RETLW   0x35
            RETLW   0x36
            RETLW   0x37
            RETLW   0x38
            RETLW   0x39
            RETLW   0x41
            RETLW   0x42
            RETLW   0x43
            RETLW   0x44
            RETLW   0x45
            RETLW   0x46
 
Hi Aaron,

There are a couple other table access methods mentioned in this thread; Memory & Table Lookup Questions.

One method mentioned in this post allows you to store the tables in-line with your code (with much less memory overhead), like this (below);

Have fun... Mike

Code:
cm_disp
        call    Lcd_clr         ; clear display
        movlw   .3              ;
        call    LCD_line1w      ; line 1, tab 3
        PutStr  "! Warning !"   ;
        movlw   .3              ;
        call    LCD_line2w      ; line 2, tab 3
        PutStr  "Mismatch"      ;
        bcf     flags,cm        ; clear 'cm' flag
        return                  ;
 
Last edited:
Aaron,

Here's a generic PutHex routine that doesn't use a table and works on both 16F and 18F devices.

Regards, Mike

Code:
;
;  Print byte in W as ASCII hex -> '00'..'FF'
;
PutHex
        movwf   TEMP            ; save byte
        swapf   TEMP,W          ; swap nibbles in W
        call    Hex2Asc         ; process left nibble
        movf    TEMP,W          ; process right nibble
Hex2Asc andlw   b'00001111'     ; mask off left nibble
        addlw   '0'+6           ; 0-9 -> 36-3F, A-F -> 40-45
        btfsc   STATUS,DC       ; A..F? no, skip, else
        addlw   0x07            ; 40-45 -> 47-4C ('A'..'F' + 6)
        addlw   -6              ; 36-3F -> 30-39, 47-4C -> 41-46 
        goto    Put232          ; print ASCII nibble
;
 
Last edited:
Hi Aaron,

One method mentioned in this post allows you to store the tables in-line with your code (with much less memory overhead), like this (below);

Have fun... Mike

[/code]

Mike WOWWW!!! That putstr macro makes 18F strings soooo easy. I told my wife I'm going to make her a homemade Kindle LOL. Thank you for that.

I haven't studied the code Nigel sent yet but I will for the knowledge base if nothing else.
Thanks to all who replied.

Again I learned more than I bargained for!
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top