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]
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
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
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
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.