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.

Weird code execution

Status
Not open for further replies.

kyru27

New Member
I've the following code:


Code:
	LIST	p=18F4620	;Tipo de PIC



	#include <p18F4620.inc>

;	CONFIG DEBUG = ON

	CONFIG OSC = INTIO67
		
;**************************************************************
;Define la posición del resultado
CONTADOR EQU 0x22

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

	ORG 0x0000			;Comando que indica al Ensamblador
						;la dirección de la memoria de programa
							;donde situar la siguiente instrucción
;**************************************************************
	
	MOVLW 0x06
	MOVWF ADCON1
MOVLW 0x10
MOVWF TRISA
MOVLW 0x00
MOVWF TRISC


MOVLW 0x3F

MOVWF PORTC
	
INICIO		CLRF CONTADOR

P1			BTFSC PORTA,4

			GOTO P1

P0			BTFSS PORTA,4

			GOTO P0


INCF CONTADOR,F

MOVLW 0xA

SUBWF CONTADOR,W

BTFSC STATUS,C


CLRF CONTADOR

MOVF CONTADOR,W



CALL CD7SEG


MOVWF PORTC

GOTO P1



CD7SEG

ADDWF PCL, F




            retlw    06h

            retlw    5bh


            retlw    4fh

            retlw    66h

            retlw    6dh

            retlw    7dh

            retlw    07h

            retlw    7fh

            retlw    67h

			retlw    3fh

END

That works in an awkward way, I mean, when CD7SEG is called the following values are returned according to the value of CONTADOR:

When CONTADOR=1 ->"1". OK

When CONTADOR=2 ->""2. OK

When CONTADOR=3 ->"2".

When CONTADOR=4 ->"3".

When CONTADOR=5 ->"3".

When CONTADOR=6 ->"4".

When CONTADOR=7 ->"4".

When CONTADOR=8 ->"5".

After this the program stops recognizing that the button which allows to jump to INCF CONTADOR,F is being pressed and the program cannot be executed properly anymore.

Any idea of what might be happening? It's pretty strange that the code works right for the first two numbers, and later it doesn't work.

Thanks.
 
Last edited:
This is because tables work a different way on the pic18's The table call requires a high and low address

MIKEK8LH is the man to ask he explains it here https://www.microchip.com/forums/m100230.aspx. Read this and you will be enlightened.
 
hi,
[Ian beat me too it.!:rolleyes:]

Look at this extract from the d/s when using the Computed Goto with a 18F PIC
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top