Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
kenmac said:Hi,
Re the RETLW table function on a 16F628A.
What is the limit for the size of a table and where is the data stored?
Does it just reside in the program memory space?
That statement may be a bit confusing... Tables can be placed almost anywhere in code memory and can straddle a 256 byte boundary (though special precautions are necessary when crossing 'pages')... Here's example table code that takes into account a table which may or may not straddle a 256 byte boundary;Nigel Goodwin said:However!, it MUST NOT cross a 256 byte boundary, as it only does an 8 bit calculation - there are methods to over come this though.
;
GetData movwf INDEX ; save index value [000..255] |B0
movlw high Table ; get table high address |B0
movwf PCLATH ; preset PCLATH |B0
movlw low Table ; get table low address |B0
addwf INDEX,W ; add index [000..255] |B0
skpnc ; skip if C=0 |B0
incf PCLATH,f ; else, increment PCLATH |B0
movwf PCL ; perform the branch |B0
;******************************************************************
;
; here's how I print in-line code strings in my programs
;
;
_Print "Bill's Particle Accelerator Demo\r\n\n"
_Print "Main Menu\r\n"
;
;******************************************************************
;******************************************************************
;
; _Print macro - print a string to the RS-232 port
;
_Print macro str ;
local String, Print
movlw low String ;
movwf PTRL ;
movlw high String ;
movwf PTRH ;
goto Print ;
String dt str,0
Print call PutString ; print string
endm
;******************************************************************
;******************************************************************
;
; PutString Subroutine
;
; - setup PTRL and PTRH to string address before entry
; - string must be terminated with a 00 byte
;
PutString
call GetTable ; get a table character |B0
andlw b'11111111' ; |B0
btfsc STATUS,Z ; a 00 byte, last character? |B0
return ; yes, return, else |B0
call Put232 ; output character |B0
incfsz PTRL,F ; increment pointer |B0
goto PutString ; |B0
incf PTRH,F ; |B0
goto PutString ; |B0
;
GetTable
movf PTRH,W ; |B0
movwf PCLATH ; |B0
movf PTRL,W ; |B0
movwf PCL ; |B0
;******************************************************************
Mike said:That statement may be a bit confusing... Tables can be placed almost anywhere in code memory and can straddle a 256 byte boundary (though special precautions are necessary when crossing 'pages')...Nigel Goodwin said:However!, it MUST NOT cross a 256 byte boundary, as it only does an 8 bit calculation - there are methods to over come this though.
Nigel Goodwin said:Mike said:That statement may be a bit confusing... Tables can be placed almost anywhere in code memory and can straddle a 256 byte boundary (though special precautions are necessary when crossing 'pages')...Nigel Goodwin said:However!, it MUST NOT cross a 256 byte boundary, as it only does an 8 bit calculation - there are methods to over come this though.
Which was why I said "there are methods to over come this though!.
Mike said:Sorry Nigel... That's the part that contradicted the first part of your statement and seemed to make the entire statement somewhat confusing...
I also politely disagree with the first part of your statement... "It MUST NOT cross a 256 byte boundary, as it only does an 8 bit calculation"... This implies that you recommend fixed location tables of 256 words or less that don't cross 256 word boundaries and while that certainly is one way to use tables, that isn't necessarily the best way or the most flexable way to use tables... I hope my examples provided a glimpse of some of the capabilities of tables...