|
|
View previous topic :: View next topic |
Author |
Message |
[email protected]
Joined: 08 Jul 2007 Posts: 6
|
#org an const variable ROM placement |
Posted: Tue Mar 15, 2016 12:19 am |
|
|
Hi to all.
In order to optimize the time to program (and debug) my application I try to place some constant at beginning of the ROM.
Due the fact that compiler place constant at end of rom, the programming require a lot of time each time I need to debug application (I use ICD2).
The code is:
Code: | #include "18F46K22.H" //Microcontroller
....
#DEVICE CONST=ROM
#org 0x0200, 0x02FF
const char MyString[] = "Hello Word";
rom int Var = 5;
#org default |
The program memory after compiling is:
Quote: | ...
256 01FE FFFF NOP
257 0200 FFFF NOP
258 0202 FFFF NOP
259 0204 FFFF NOP
260 0206 FFFF NOP
261 0208 FFFF NOP
.....
383 02FC FFFF NOP
384 02FE FFFF NOP
385 0300 C107 MOVFF 0x107, 0x101
.....
32761 FFF0 FFFF NOP
32762 FFF2 FFFF NOP
32763 FFF4 6548 CPFSGT 0x48, BANKED
32764 FFF6 6C6C NEGF 0xf6c, ACCESS
32765 FFF8 206F ADDWFC 0xf6f, W, ACCESS
32766 FFFA 6F57 MOVWF 0x57, BANKED
32767 FFFC 6472 CPFSGT 0xf72, ACCESS
32768 FFFE FF00 NOP
|
Variables aren't located where I expected !
Any suggestion?
My primary goal is to reduce programming time ...
Many thanks |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 15, 2016 10:36 am |
|
|
The test program below places the 'const' data and rom data in the
specified addresses in program memory. Here is the text at the end
of the .LST file which shows this. Also, I viewed the program memory
in MPLAB and the data is in the specified locations. I tested this with
compiler vs. 5.055 and MPLAB vs. 8.92.
Code: | ROM data:
000200: 48 65 6C 6C 6F 20 57 6F 72 6C 64 00 Hello World.
000300: 05 .
|
Test program:
Code: | #include "18F46K22.H"
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)
#DEVICE CONST=ROM
#org 0x0200
const char MyString[] = "Hello World";
#org default
#org 0x0300
rom int Var = 5;
#org default
//=====================================
void main()
{
while(TRUE);
} |
|
|
|
[email protected]
Joined: 08 Jul 2007 Posts: 6
|
|
Posted: Tue Mar 15, 2016 3:23 pm |
|
|
Hi,
I've try with your suggestion
I'm using V4 version compiler.
Code: |
#include "18F46K22.H"
#include "DEF_18(L)F2X_4XK22.h"
#fuses INTRC_IO, NOPLLEN, PRIMARY_ON, NOFCMEN, NOIESO
#fuses NOPBADEN, NOHFOFST
#fuses PUT, WDT
#DEVICE *=16, ADC=10
#DEVICE CONST=ROM
#use delay(clock=64000000,RESTART_WDT)
#USE FAST_IO(A)
#USE FAST_IO(B)
#USE FAST_IO(C)
#USE FAST_IO(D)
#USE FAST_IO(E)
#org 0x0200
const char MyString[] = "Hello World";
#org default
#pragma ZERO_RAM
void main()
{
while(TRUE);
} |
Compiler generate this error an compiling fail:
Quote: |
Executing: "C:\Program Files\PICC\Ccsc.exe" +FH "Main.c" out="..\0_output\" #__DEBUG=1 +ICD +DF +LN I+="Y:\Fw\Pic\18x\" +T +A +M -Z +Y=9 +EA #__18F46K22=TRUE
--- Info 300 "Main.c" Line 129(1,7): More info: Segment at 00000-0FFFE (0000 used)
--- Info 300 "Main.c" Line 129(1,7): More info: Attempted to create: 00200-00000 for #org
*** Error 126 "Main.c" Line 129(1,7): Invalid ORG range
1 Errors, 0 Warnings.
Build Failed.
Halting build on first failure as requested.
BUILD FAILED: Tue Mar 15 22:12:17 2016 |
if I modify #org stantement
Code: |
#org 0x0200,0x0250
const char MyString[] = "Hello World";
#org default |
The program memory is:
Quote: |
....
254 01FA EF46 GOTO 0x268c
255 01FC F013 NOP
256 01FE FFFF NOP
257 0200 FFFF NOP
258 0202 FFFF NOP
259 0204 FFFF NOP
260 0206 FFFF NOP
261 0208 FFFF NOP
....
295 024C FFFF NOP
296 024E FFFF NOP
297 0250 FFFF NOP
298 0252 C107 MOVFF 0x107, 0x101
....
32761 FFF0 FFFF NOP
32762 FFF2 FFFF NOP
32763 FFF4 6548 CPFSGT 0x48, BANKED
32764 FFF6 6C6C NEGF 0xf6c, ACCESS
32765 FFF8 206F ADDWFC 0xf6f, W, ACCESS
32766 FFFA 6F57 MOVWF 0x57, BANKED
32767 FFFC 6C72 NEGF 0xf72, ACCESS
32768 FFFE 0064
|
.....like the first message.
Bye |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Mar 24, 2016 1:49 pm |
|
|
Quote: | I'm using V4 version compiler. |
You sent me a PM asking for more help, but you never read my PM reply,
which is:
Go to the thread and post your exact compiler version.
The version will be a 4-digit number such as 4.068, or 4.135, or 4.141, etc.
Here are three ways to find the CCS compiler version:
1. Compile a test source file and look at the top of the .LST file, which will
be in your project folder. It will show the version. However, to get
the .LST file to be generated, the source file must compile with no errors.
2. Click on the Start button in Windows, then go to Programs, and then
find the entry for CCS, which will be called "PIC-C". Then click on the icon
for "Compiler Version". It will display a box which shows the compiler
version.
3. Open a Command Prompt window and go to c:\Program Files\Picc
(or to whatever directory CCS is installed in) and run this command line:
CCSC.exe +v
This method should always work. |
|
|
[email protected]
Joined: 08 Jul 2007 Posts: 6
|
Compiler version |
Posted: Thu Mar 24, 2016 3:39 pm |
|
|
I've checked on .lst file.
Quote: |
CCS PCH C Compiler, Version 4.135, 23-mar-16 06:48 |
Bye _________________ Fabio |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Mar 25, 2016 2:28 am |
|
|
I don't think 'rom' and #org work as well in your version as they do
in vs. 5.xxx. So with vs. 4.135, I used 'const' and #org to place the
"Hello World" data in the 0x200 address range.
The program below has the following output in MPLAB vs. 8.92 simulator:
Quote: |
addr of text = 0210
Hello World
|
Test program:
Code: | #include <18F46K22.H>
#fuses INTRC_IO, NOPLLEN, PRIMARY_ON, NOFCMEN, NOIESO
#fuses NOPBADEN, NOHFOFST
#fuses PUT, WDT
#use delay(clock=64000000,RESTART_WDT)
#use rs232(baud=9600, UART1, ERRORS)
#org 0x0200, 0x220
const char MyString[12] = "Hello World";
#org default
//==================================
void main()
{
int16 addr;
int8 value;
int8 i;
addr = label_address(MyString);
printf("addr of text = %lx \r", addr);
i = 0;
for(i = 0; i < sizeof(MyString); i++)
{
value = MyString[i];
printf("%c", value);
}
while(TRUE);
} |
Here is part of the Program Memory window in MPLAB, showing the
address of the data:
Code: | Addr Opcode Label Disassembly
0200 6AF7 @const80 CLRF TBLPTRH, ACCESS
0202 0F10 ADDLW 0x10
0204 6EF6 MOVWF TBLPTRL, ACCESS
0206 0E02 MOVLW 0x2
0208 22F7 ADDWFC TBLPTRH, F, ACCESS
020A 0009 TBLRD*+
020C 50F5 MOVF TABLAT, W, ACCESS
020E 0012 RETURN 0
// "Hello World" data starts below:
0210 6548 CPFSGT 0x48, BANKED
0212 6C6C NEGF SSP2CON1, ACCESS
0214 206F ADDWFC SSP2BUF, W, ACCESS
0216 6F57 MOVWF 0x57, BANKED
0218 6C72 NEGF TXSTA2, ACCESS
021A 0064
021C FFFF NOP
021E FFFF NOP |
|
|
|
[email protected]
Joined: 08 Jul 2007 Posts: 6
|
|
Posted: Fri Mar 25, 2016 3:31 am |
|
|
The only differences from my code and your code is the dimension, for my isnt declared
Code: |
#org 0x0200
const char MyString[] = "Hello World";
#org default
|
On your
Code: |
#org 0x0200, 0x220
const char MyString[12] = "Hello World";
#org default
|
I will test it, but, do you think that this is the reason that my program put the data on end of memory and your where you define?
Thanks and bye _________________ Fabio |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19566
|
|
Posted: Fri Mar 25, 2016 5:08 am |
|
|
The first thing to remove, is the const=ROM line.
Compile your code without this, and it will place the data in ROM.
CCS mode is the default, and for some reason, specifying this causes it to go wrong on your version.
Then you need _one_ size specified.
If you modify your program so it gives an address 'range'
#org 0x200, 0x220
for example, it'll then compile as is.
The problem here is that when the 'pre-processor' (not really a pre-processor in CCS, but the initial pass which starts trying to lay the memory 'out'), arrives at the ORG, it tries to allocate the whole of memory for the ORG......
Now, you also have to realise that with a const, CCS places the program to access the const, in front of the data. This is what PCM_Programmer is showing, with the 'label_address' code. So your 12 character string, actually needs 22 bytes of ROM to be stored.
So with your code changed to:
Code: |
#include "18F46K22.H"
//#include "DEF_18(L)F2X_4XK22.h"
#fuses INTRC_IO, NOPLLEN, PRIMARY_ON, NOFCMEN, NOIESO
#fuses NOPBADEN, NOHFOFST
#fuses PUT, WDT
#DEVICE ADC=10 //*=16 does nothing on a PIC18
//#DEVICE CONST=ROM
#use delay(clock=64000000,RESTART_WDT)
#USE FAST_IO(A)
#USE FAST_IO(B)
#USE FAST_IO(C)
#USE FAST_IO(D)
#USE FAST_IO(E)
#org 0x0200,0x220
const char MyString[] = "Hello World";
#org default
#pragma ZERO_RAM
void main()
{
while(TRUE);
}
|
The listing shows:
Code: |
*
00200: CLRF FF7
00202: ADDLW 10
00204: MOVWF FF6
00206: MOVLW 02
00208: ADDWFC FF7,F
0020A: TBLRD*+
0020C: MOVF FF5,W
0020E: RETURN 0
00210: DATA 48,65
00212: DATA 6C,6C
00214: DATA 6F,20
00216: DATA 57,6F
00218: DATA 72,6C
0021A: DATA 64,00
0021C: RETURN 0
|
|
|
|
|
|
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
|