OT: PIC program not working..

000202080108010907080108 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit

Well back again to CALL . Docs say the program counter will be set to the subroutine location after being incremented and pushed to the stack. With just that, a table cannot work. So, the "fix" is supposed to be the use of an add to the PCL: ORG 0x0200 RANDUMB ADDWF PCL,W ; doc sez PCL=0x00 + [W]

Reply to
Robert Baer
Loading thread data ...

A portion of an old Ramtest I did many years ago. Heres how I used a table. I believe you can declare it as dt 0x02, 0x03, 0x04

The piclist has other examples for page boundry checking.

Getstr:: ; 1/28/2004 ; Retlw Table read method, no page checking ; Passed params: W index ; strptrl is PCL ; strptrh is PCLATH ; Returns: ; W - Table data 8bit ; ; Pop the data out of rom at index W, and return ; addwf strptrl btfsc STATUS,C incf strptrh movf strptrh,w movwf PCLATH movf strptrl,w movwf PCL

Reply to
Martin Riddle

[snip]

I used MPLABX to assemble your code and ran it using the simulator. Here is code that works:

******** This is a clearer way to set/reset the banks BANKSEL TRISB or even: BSF STATUS,RP ; Bank 1 command comes next STATUS RP0 set

MOVLW 0x02 ; table location MOVWF PCLATH MOVLW d'13' ; ************ NOTE the use of d'nn' for decimals CALL RANDUMB MOVWF 6 ; set Port B to table value seen ************* Why not use the mnemonic PORTB? CALL DELAY ; "freeze" LEDs

MOVLW 0x02 ; table location MOVWF PCLATH MOVLW d'5' ; ************* NOTE the use of d'nn' for decimals CALL RANDUMB MOVWF 6 ; set Port B to table value seen CALL DELAY ; "freeze" LEDs

GOTO BEG

COUNT1 EQU 0x60 COUNT2 EQU 0x61 COUNT3 EQU 0x62

DELAY CLRF COUNT1 ; ; 1 CLRF COUNT2 ; ; 1 CLRF COUNT3 ; ; 1

LOOPIE INCFSZ COUNT3 GOTO LUPOTR RETURN

LUPOTR INCFSZ COUNT2 ; 1*255 + 2 GOTO LUPINR ; COUNTed once,do inner loop ; 2 GOTO LOOPIE ; 2

LUPINR INCFSZ COUNT1 ; race inside inner loop ; 1*255 + 2 GOTO LUPINR ; high speed count ; 2 (259) GOTO LUPOTR ; go for another outer count ; 2

ORG 0x0200 ;************** Note that I removed the ,W from the ADDWF PCL,W command RANDUMB ADDWF PCL ; doc sez PCL=0x00 + [W] --> PCL == 0x13 RETLW 0xAA ;0x01 LEDS SHOW VALUE FROM HERE RETLW 0x02 RETLW 0x04 RETLW 0x08 RETLW 0x10 RETLW 0x20 RETLW 0x40 RETLW 0x80 RETLW 0x03 ;0x09 RETLW 0x06 RETLW 0x0C RETLW 0x18 ;0x0C RETLW 0x30 RETLW 0x60 RETLW 0xC0 ;0x0F

More information on tables:

formatting link

Paul

Reply to
P E Schoen

You have W as the destination for the ADD, for the computed jump to work the destination should be the "file" in this case pcl.

piglet

Reply to
piglet

Sneaky! a faked CALL to table. BUT...with nothing in the stack, where does the program go after the RETLW?

Reply to
Robert Baer

Thanks. Is the problem caused by my use of the ,W in ADDWF PCL,W?

If i remove the ADDWF completely, table lookup also does not work and it was supposed to work (but the docs imply that it cannot).

Will check this and variants out. Thanks again.

Reply to
Robert Baer

Thanks.

Reply to
Robert Baer

I believe back to the original call to Getstr. Theres no ret in the function, its in the table. So you call Getstr and the return value is from the table at index W

Its been a while but thats how I remember it.

Cheers

Reply to
Martin Riddle

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.