Alex_rcpilot said:Hi all,I would like to store a table of data inside the flash memory of a PIC16F877A.I'd like not to use the normal RETLW k structure to fetch data,but the slower 'read ROM word' operation instead.First I have to save the data into the flash.My text book doesn't describe how DB and DW does with a 14-bit ROM word in detail.So here are my questions:
what happens to the memory addr starting from 0x100 when I define bytes in sequence as below?
ORG 0x100
TABLE
DB 0xFD,0x35,0xDA,0xC4,0x0E........
Similarly,what would happen if I do this with DW?
ORG 0x100
TABLE
DB 0x1FFD,0x2E35,0x3DA,0x3F74,0xE0E........
BTW,is there a tutorial on MPASM pseudo instructions?I will appreciate if
someone can share a link with me.Thank you.
Alex_rcpilot said:what happens to the memory addr starting from 0x100 when I define bytes in sequence as below?
ORG 0x100
TABLE
DB 0xFD,0x35,0xDA,0xC4,0x0E........
ORG 0x100
TABLE
DB 0x1FFD,0x2E35,0x3DA,0x3F74,0xE0E........
DATA – Create Numeric and Text Data
Syntax
[<label>] data <expr>,[,<expr>,...,<expr>]
[<label>] data “<text_string>”[,“<text_string>”,...]
Description
Initialize one or more words of program memory with data. The data may be in the form of constants, relocatable or external labels, or expressions of any of the above.
The data may also consist of ASCII character strings, <text_string>, enclosed in single quotes for one character or double quotes for strings. Single character items are placed into the low byte of the word, while strings are packed two to a word with the first character in the most significant byte of the word. If an odd number of characters are given in a string, the final byte is zero.
ORG 300H
DATA 12500
DATA 12365
DATA 12232
DATA 12100
DATA 11970
Alex_rcpilot said:Hi all,I would like to store a table of data inside the flash memory of a PIC16F877A.I'd like not to use the normal RETLW k structure to fetch data,but the slower 'read ROM word' operation instead.
Joel Rainville said:Hey Alex,
There's a way for you to see what happens in program memory. In MPLAB, choose MPLAB SIM as your debugger. Assemble your code and then using the debugger tools step into your code and select View->Program Memory in MPLAB's menu.
Pay attention to what happens to 16 bits values during assembly...
Joel Rainville said:What do you mean by "pseudo instructions"? Assembler directives? They're all pretty well explained in MPLAB's help system, under the MPASM section. Or are you talking about the PIC16 instruction set? Or the mnemonics?
eblc1388 said:You will be in trouble on 16F parts. Apparantly MPASM would try to fit 0xFD,0x35 to a single program memory, ending up with 0x3D35 as the two MSB is discarded. So for 8-bit values, you have to place zero in between them like, 0,0xFD,0,0x35....
I think the same would be true. Each 16-bit word would be fitted to one 14-bit program memory word, with the higher bits chopped off.
Alex_rcpilot said:The code above will work no matter where the designated table is stored is the program memory.What should I do in PIC?
Nigel Goodwin said:Alex_rcpilot said:Hi all,I would like to store a table of data inside the flash memory of a PIC16F877A.I'd like not to use the normal RETLW k structure to fetch data,but the slower 'read ROM word' operation instead.
But why would you want to do this?.
Nigel Goodwin said:Alex_rcpilot said:The code above will work no matter where the designated table is stored is the program memory.What should I do in PIC?
I think I see what your problem is?, you're trying to force programming from other processors to a PIC?.
For a PIC you use RETLW for tables, it's really as simple as that! - don't try and use Von Neumann style programming on a Harvard architecture processor.
dt - Data Table.
Generates a series of RETLW instructions, one instruction for each expr. Each expr must be an 8-bit value. Each character in a string is stored in its own RETLW instruction.
Simple Example
dt "A Message", 0
dt FirstValue, SecondValue, EndOfValues
This directive is used when generating a table of data for the PIC12/16 device family. If you are using a PIC18 device, it is recommended that you use the table read/write (TBLRD/TBLWT) features. See the device data sheet for more information.
Jay.slovak said:Interesting to see this discusion going,
I use two ways of storing data, depending on platform. For PIC16 I use multiple RETLW instructions (computed GOTO), and for PIC18 I use TBLRD with DB or DW directives (FLASH table reads). This works fine for me.
Jay.slovak said:Actually there is an ASSEMBLER directive that makes writting RETLW style table easy!
Code:dt - Data Table. Generates a series of RETLW instructions, one instruction for each expr. Each expr must be an 8-bit value. Each character in a string is stored in its own RETLW instruction.
Code:Simple Example dt "A Message", 0 dt FirstValue, SecondValue, EndOfValues
This directive is used when generating a table of data for the PIC12/16 device family. If you are using a PIC18 device, it is recommended that you use the table read/write (TBLRD/TBLWT) features. See the device data sheet for more information.
How hard is that?
How about passing a parameter from Interrupt (remember this will not act as RETFIE, as GIE is not being enabled automatically) or other Sub-routine?Alex_rcpilot said:Anyway,I'm still curious about in how many ways RETLW can be used normally.Any clues?Thank you,again
Regards,Alex.
Jay.slovak said:There is no GOTO instruction in that subrutine, it's just called "The computed GOTO" because you change PC to "Jump - GOTO" to the line of table you want.
Alex_rcpilot said:With this there's nothing I shall be scared of while working on RETLW.
Alex_rcpilot said:Hm......actually I have read about the RETLW structure from my text book.And I think it's the most frequently used method for returning data from a table.
I don't know what you meant by force programming.Presumably you meant that I was trying to apply a program structure that doesn't fit into PIC hardware to a PIC?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?