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...
Thanks Joel,I tried it and found out what would happen.
It's interesting with the DB directive.In 16F877A where there's 14 bit in a program word,DB stores the first byte in the higher byte of a 16-bit word.Which means the 2 MSB are chopped off.If there's a second byte,it will fill the lower byte of the same word.
The DW stores a 14-bit word in each program word,and I don't have a problem with it now.
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?
Well,please forgive me for being confusing."Pseudo instruction"is a poor translation found in an interpreter software.I'm a Chinese college student.Just not being professional enough to know all such technical terms.I was actually mentioning something like ORG,DW,_CONFIG,INCLUDE etc.They call them assembler directives?This will explain why I didn't find anything while I was searching for related issues in the MPLAB help file.I will search for "assembler directives" this time.Thank you!
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.
Yes eblc1388,You were talking about the same thing as I observed.It's absolutely correct.Thank you.
to motion:
Thanks,I tried DATA directive and found it handy
.Thank you for the advice.
The next thing I would like to know is how people usually get data from these data tables.What I'm trying to do is simple : store multiple tables in the flash memory,and write a subroutine to read any of these tables.And I just need to tell the subroutine the starting address of target table & the index to get the right data byte.
I used to do it in 8051 structure as following:
Get_table_data:
MOV DPTR,#TABLE
MOV A,INDEX
MOVC A,@A+DPTR
MOV DBYTE,A
RET
TABLE:
DB D5H,33H,8EH
..........
And for AVR microcontrollers where a program word has 16bits,I can do this:
Get_table_data:
LDI R30,low(CharTab)
LDI R31,high(CharTab)
CLC
ROL R30
ROL R31
ADD R30,R16 ;Index stored in R16
LDI R16,0
ADC R31,R16 ;2 byte addition
LPM ;Returned byte is stored in R0
RET
CharTab:
'Table content is a string of ASCII codes'
The code above will work no matter where the designated table is stored is the program memory.What should I do in PIC?
Regards,Alex.