|
|
View previous topic :: View next topic |
Author |
Message |
Fabri
Joined: 22 Aug 2005 Posts: 275
|
#org and flash memory allocation |
Posted: Wed Feb 26, 2014 2:46 pm |
|
|
Hi,
In order to understand where CCS put my data table I have it as follow:
Code: |
#org 0xf8A0,0xFC00
const char table[104][8]={
/* 01 */30,28,32,30,30,28,32,30,
/* 02 */32,32,36,32,32,32,36,32,
/* 03 */37,33,48,35,37,33,48,35,
/* 04 */40,40,54,39,40,40,54,39,
/* 05 */45,45,60,45,45,45,60,45,
/* 06 */0,0,0,0,0,0,0,0,
/* 07 */60,60,60,60,0,60,60,60,
|
In flash memory I have:
Code: |
Address 00 02 04 06 08 0A 0C 0E
F8A0 0FAE 6EF6 0EF8 22F7 0009 50F5 0012 1C1E
F8B0 1E20 1C1E 1E20 2020 2024 2020 2024 2125
F8C0 2330 2125 2330 2828 2736 2828 2736 2D2D
F8D0 2D3C 2D2D 2D3C 0000 0000 0000 0000 3C3C
F8E0 3C3C 3C00 3C3C 3131 3131 3131 3131 3636
F8F0 3636 3636 3636 3B3B 3B3B 3B3B 3B3B 4040
F900 4040 4040 4040 5A5A 5A5A 5A5A 5A5A 0000
F910 0000 0000 0000 D2D2 BEC3 D2D2 BEC3 DCDC
F920 C8CD DCDC C8CD E6E6 D2D7 E6E6 D2D7 F5EB
F930 DCE1 F5EB DCE1 FFF5 E6EB FFF5 E6EB 0000
F940 0000 0000 0000 9696 9696 9696 9696 B4B4
F950 B4B4 B4B4 B4B4 BEBE BEBE BEBE BEBE C8C8
F960 C8C8 C8C8 C8C8 D7D7 D7D7 D7D7 D7D7 0101
|
Somebody can explain me why real data table start only at 0xF8AE instead of 0xF8A0 and meaning of firsts 14 bytes ?
Thanks,
Fabri |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Feb 26, 2014 2:50 pm |
|
|
are we supposed to guess the CHIP you are referring to ???
and the purpose of what you want to accomplish ?
and have you READ the ccs manual?
Quote: |
The #org preprocessor can be used to place the constant to specified address blocks.
For example:
The constant ID will be at 1C00.
#ORG 0x1C00, 0x1C0F
CONST CHAR ID[10]= {"123456789"};
Note: Some extra code will precede the 123456789. |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Wed Feb 26, 2014 2:55 pm |
|
|
also when building tables/storing data like this, it really,really helps to code in HEX not decimal numbers.
This way the data you're looking at will be in the same form and easier to see mistakes.
hth
jay |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Wed Feb 26, 2014 3:00 pm |
|
|
I'm sorry,
Pic is 18F46K22. I read CCS manual but I don't know meaning of extra code precede my data table. can you explain me ? |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Feb 26, 2014 3:05 pm |
|
|
the added code enables the compiler to retrieve the bytes at that location
in PROG memory - instead of direct static ram addressing where ordinary VARS are kept
this is Harvard architecture - so prog memory is NOT direct addressable
the extra code is needed to read-back what you stuffed there at compile time. |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Wed Feb 26, 2014 3:09 pm |
|
|
Yes temtronic but I have 104x8 variables and it's better for my application have table in decimal. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 26, 2014 3:11 pm |
|
|
You didn't post a test program, so I made one.
Code: |
#include <18F4620.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#org 0xf8A0,0xFC00
const char table[7][8]={
/* 01 */30,28,32,30,30,28,32,30,
/* 02 */32,32,36,32,32,32,36,32,
/* 03 */37,33,48,35,37,33,48,35,
/* 04 */40,40,54,39,40,40,54,39,
/* 05 */45,45,60,45,45,45,60,45,
/* 06 */0,0,0,0,0,0,0,0,
/* 07 */60,60,60,60,0,60,60,60
};
//=======================================
void main()
{
int8 i,j;
int8 value;
value = table[i][j];
while(1);
} |
Look at the code from the .LST file below. The first part is code to convert
an index into an address and then to read data at that address. That's
how the compiler reads the data.
Code: |
0F8A0: CLRF TBLPTRH
0F8A2: ADDLW B0
0F8A4: MOVWF TBLPTRL
0F8A6: MOVLW F8
0F8A8: ADDWFC TBLPTRH,F
0F8AA: TBLRD*+
0F8AC: MOVF TABLAT,W
0F8AE: RETURN 0
0F8B0: DATA 1E,1C
0F8B2: DATA 20,1E
0F8B4: DATA 1E,1C
0F8B6: DATA 20,1E
0F8B8: DATA 20,20 |
|
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Wed Feb 26, 2014 3:17 pm |
|
|
I supposed so,
I need to change data table by serial link, so I need to know how read table and rewrite it. For this reason I need to know where it start.
Have you got any possible solution to suggest me ? |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Wed Feb 26, 2014 3:30 pm |
|
|
Thanks PCM,
you are very clear. So I can assume my data table start at 0xF8AE. I can try to read it and write. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Feb 26, 2014 3:33 pm |
|
|
You cannot guarantee that the fetch routine will always have the same
size. I suggest not to do it that way. Instead, you should use a #rom
array. There is sample code on the forum for this. I just don't have
time to search for it now. Maybe later today. |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Wed Feb 26, 2014 3:38 pm |
|
|
Ok, I'll search in forum possible solution with #rom array.
Thanks again,
Regards,
Fabri |
|
|
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Wed Feb 26, 2014 5:06 pm |
|
|
I solved in this way:
Quote: |
#org 0xf8A0,0xFC00 default{}
#ROM int8 0xf8A0={
/* 01 */30,28,32,30,30,28,32,30,
/* 02 */32,32,36,32,32,32,36,32,
/* 03 */37,33,48,35,37,33,48,35,
/* 04 */40,40,54,39,40,40,54,39,
/* 05 */1,2,3,4,5,6,7,8,
/* 06 */0,0,0,0,0,0,0,0,
/* 07 */60,60,60,60,0,60,60,60,
------------------------------------
|
After I read rom table as follow:
Quote: |
int read_table(int x,int y){
long index;
int temp;
index = y*8;
index += x;
read_program_memory(index+0xF8A0,&temp,1);
return temp;
}
|
So, in this way, I can get back column and row values. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Feb 28, 2014 1:45 am |
|
|
Just 'FYI', the way to find the actual address of the table when using 'const', is 'label_address'.
So with PCM_programmers example:
Code: |
#include <18F4620.h>
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4M)
#org 0xf8A0,0xFC00
const char table[7][8]={
/* 01 */30,28,32,30,30,28,32,30,
/* 02 */32,32,36,32,32,32,36,32,
/* 03 */37,33,48,35,37,33,48,35,
/* 04 */40,40,54,39,40,40,54,39,
/* 05 */45,45,60,45,45,45,60,45,
/* 06 */0,0,0,0,0,0,0,0,
/* 07 */60,60,60,60,0,60,60,60
};
//=======================================
void main()
{
int8 i,j;
int8 value;
int16 address;
value = table[i][j];
address=label_address(table);
while(1);
}
|
The const is coded as:
Code: |
0F8A0: CLRF FF7
0F8A2: ADDLW B0
0F8A4: MOVWF FF6
0F8A6: MOVLW F8
0F8A8: ADDWFC FF7,F
0F8AA: TBLRD*+
0F8AC: MOVF FF5,W
0F8AE: RETURN 0
0F8B0: DATA 1E,1C
0F8B2: DATA 20,1E
0F8B4: DATA 1E,1C
0F8B6: DATA 20,1E
0F8B8: DATA 20,20
|
and you will see that 'address' is loaded with f8B0:
Code: |
.................... address=label_address(table);
00046: MOVLW 00
00048: MOVLW F8
0004A: MOVWF 01
0004C: MOVLW B0
0004E: MOVFF 01,09
00052: MOVWF 08
|
as required.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|