CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

#ORG help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Xavier
Guest







#ORG help
PostPosted: Sun Dec 08, 2002 7:46 am     Reply with quote

Hello,
I don't know how to place some CONST at a define Address.

#ORG 0x7F0, 0x7F2
const byte version = 1; // &version at 0x7F0
const byte tempo = 128; // &tempo at 0x7F1
const byte temp = 65; // &temp at 0x7F2

When I Look the LST file its only place the firts constant at my desired address.
Why ?

The aim is to be able to change the const values using RS232
with write_program_eeprom() :

...
car = getch();
write_program_eeprom(&version,car);
...

Is there a way to do this ?
if someone could help me ?
Thanks in advance
Xavier
___________________________
This message was ported from CCS's old forum
Original Post ID: 9862
R.J.Hamlett
Guest







Re: #ORG help
PostPosted: Sun Dec 08, 2002 8:24 am     Reply with quote

:=Hello,
:=I don't know how to place some CONST at a define Address.
:=
:=#ORG 0x7F0, 0x7F2
:=const byte version = 1; // &version at 0x7F0
:=const byte tempo = 128; // &tempo at 0x7F1
:=const byte temp = 65; // &temp at 0x7F2
:=
:=When I Look the LST file its only place the firts constant at my desired address.
:=Why ?
:=
The #ORG statement, is really aimed at placing a code 'entity' at a location. The next 'const' is seen as an 'entity' (in these terms), and gets placed at the location, but the subsequent consts, are seen as seperate entities.
There are two seperate ways of dealing with this. The first is just to use:
#ORG 0x7F0, 0x7F2
const byte version = 1; // &version at 0x7F0
#ORG 0x7F0
const byte tempo = 128; // &tempo at 0x7F1
#ORG 0x7F0
const byte temp = 65; // &temp at 0x7F2

This will give the constants in subsequent locations in the same 'segment' at 0x7F0, _but_ depending on the chip you are using, you may have to be aware that the compiler may have to add 'access' code round a byte stored this way, so 'tempo', may well end up appearing at a higher address than expected.
Annoyingly, you can't just use two '{}' brackets to make the seperate definitions into a single entity (this would be a lovely feature for your approach).

The other method, is to use the '#ROM' directive to place a block of definitions into memory, then just use defines to access these addresses. Not as nice...

:=The aim is to be able to change the const values using RS232
:=with write_program_eeprom() :
:=
:=...
:=car = getch();
:=write_program_eeprom(&version,car);
:=...
:=
:=Is there a way to do this ?
:=if someone could help me ?
:=Thanks in advance
:=Xavier

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9863
Xavier
Guest







Changing Const value using RS232
PostPosted: Mon Dec 09, 2002 5:49 am     Reply with quote

Thanks Helmett for the reply,
Here is my little program :

#if defined(__PCM__)
#include "16F877.h"
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, PARITY=N)
#endif

#define CONST_ADD 0x7D0 // Base address for Constant (PROGRAM EEPROM)
#ORG CONST_ADD, CONST_ADD+(3*3)
const byte Version = 1;
#ORG CONST_ADD
const byte Tempo = 10;
#ORG CONST_ADD
const byte Test = 5;

byte Buff_car;

#INT_RDA
void serial_isr()
{
Buff_car= getc();
if (Buff_car == 'L')
{
printf("Tempo : \%2d \r\n", Tempo);
}
else
{
write_program_eeprom (&Tempo,Buff_car);
printf("New value : \%2d \r\n",Tempo);
}
}

main() {
printf("OK \r\n");
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);

do {
} while(TRUE);
}

Compilation failed because Tempo is a const !

Is there a better way to do this ?
Thanks in advance
Xavier
___________________________
This message was ported from CCS's old forum
Original Post ID: 9877
R.J.Hamlett
Guest







Re: Changing Const value using RS232
PostPosted: Mon Dec 09, 2002 7:56 am     Reply with quote

:=Thanks Helmett for the reply,
:=Here is my little program :
:=
:=#if defined(__PCM__)
:=#include "16F877.h"
:=#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
:=#use delay(clock=20000000)
:=#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, PARITY=N)
:=#endif
:=
:=#define CONST_ADD 0x7D0 // Base address for Constant (PROGRAM EEPROM)
:=#ORG CONST_ADD, CONST_ADD+(3*3)
:=const byte Version = 1;
:=#ORG CONST_ADD
:=const byte Tempo = 10;
:=#ORG CONST_ADD
:=const byte Test = 5;
:=
:=byte Buff_car;
:=
:=#INT_RDA
:=void serial_isr()
:={
:= Buff_car= getc();
:= if (Buff_car == 'L')
:= {
:= printf("Tempo : \%2d \r\n", Tempo);
:= }
:= else
:= {
:= write_program_eeprom (&Tempo,Buff_car);
:= printf("New value : \%2d \r\n",Tempo);
:= }
:=}
:=
:=main() {
:= printf("OK \r\n");
:= enable_interrupts(INT_RDA);
:= enable_interrupts(GLOBAL);
:=
:=do {
:= } while(TRUE);
:=}
:=
:=Compilation failed because Tempo is a const !
:=
:=Is there a better way to do this ?
:=Thanks in advance
:=Xavier

The reason that failed, is you cannot take the address of a constant. The address operator only applies to variables stored in RAM. Just use 'CONST_ADD+1', instead of the address instruction (&Tempo).

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9878
Xavier
Guest







Re: Changing Const value using RS232
PostPosted: Mon Dec 09, 2002 11:28 am     Reply with quote

:=:=Thanks Helmett for the reply,
:=:=Here is my little program :
:=:=
:=:=#if defined(__PCM__)
:=:=#include "16F877.h"
:=:=#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
:=:=#use delay(clock=20000000)
:=:=#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, PARITY=N)
:=:=#endif
:=:=
:=:=#define CONST_ADD 0x7D0 // Base address for Constant (PROGRAM EEPROM)
:=:=#ORG CONST_ADD, CONST_ADD+(3*3)
:=:=const byte Version = 1;
:=:=#ORG CONST_ADD
:=:=const byte Tempo = 10;
:=:=#ORG CONST_ADD
:=:=const byte Test = 5;
:=:=
:=:=byte Buff_car;
:=:=
:=:=#INT_RDA
:=:=void serial_isr()
:=:={
:=:= Buff_car= getc();
:=:= if (Buff_car == 'L')
:=:= {
:=:= printf("Tempo : \%2d \r\n", Tempo);
:=:= }
:=:= else
:=:= {
:=:= write_program_eeprom (&Tempo,Buff_car);
:=:= printf("New value : \%2d \r\n",Tempo);
:=:= }
:=:=}
:=:=
:=:=main() {
:=:= printf("OK \r\n");
:=:= enable_interrupts(INT_RDA);
:=:= enable_interrupts(GLOBAL);
:=:=
:=:=do {
:=:= } while(TRUE);
:=:=}
:=:=
:=:=Compilation failed because Tempo is a const !
:=:=
:=:=Is there a better way to do this ?
:=:=Thanks in advance
:=:=Xavier
:=
:=The reason that failed, is you cannot take the address of a constant. The address operator only applies to variables stored in RAM. Just use 'CONST_ADD+1', instead of the address instruction (&Tempo).
:=
:=Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9888
Xavier
Guest







Oups !
PostPosted: Mon Dec 09, 2002 12:54 pm     Reply with quote

Sorry for the empty previous post !
I tried to replace
write_program_eeprom (&Tempo,Buff_car);
with
write_program_eeprom (CONST_ADD+1,Buff_car);
But the printf result is unchanged ?!
Its always give me the original value 10

Any idea ?
Maybe there is another way to do my little program ?
Thanks
___________________________
This message was ported from CCS's old forum
Original Post ID: 9896
R.J.Hamlett
Guest







Re: Oups !
PostPosted: Mon Dec 09, 2002 1:50 pm     Reply with quote

:=Sorry for the empty previous post !
:=I tried to replace
:=write_program_eeprom (&Tempo,Buff_car);
:=with
:=write_program_eeprom (CONST_ADD+1,Buff_car);
:=But the printf result is unchanged ?!
:=Its always give me the original value 10
:=
:=Any idea ?
:=Maybe there is another way to do my little program ?
:=Thanks
Now I suspect you are running into the other problem I mentioned!...
The problem is that storing a variable like 'const int8 fred=10', doesn't necessarily result in a single byte value in memory. The actual code generated, depends on the chip being used. On the 18F for instance, each location in memory, can actually store two bytes, so 'tempo', may well be in the high 'half' of the 0x7F1 location. Conversely on older chips without the read_program_eeprom capability, the code will instead result in a 'retlw' instruction, that again can't be replaced with the simple number.
Personally, I'd go for the 'defined names' approach instead. Something like:

#ROM 0x7F0 = { 1, //Version number
128, //Tempo value
65 //Temp
}
#define VERSION 0x7F0
#define TEMPO 0x7f1
#define TEMP 0x7F2

//Note that each location can store a 16 bit value on a 18
//chip.

#define getval(val) read_program_eeprom(val)
#define putval(val,cont) write_program_eeprom(val,cont)

#INT_RDA
void serial_isr()
{
Buff_car= getc();
if (Buff_car == 'L')
{
printf("Tempo : \%2d \r\n", getval(TEMPO));
}
else
{
putval(TEMPO,Buff_car);
printf("New value : \%2d \r\n",getval(TEMPO));
}
}

As a seperate comment, if you want to have other interrupt driven tasks running (like RS232), in general, I'd avoid using the 'write_program_eeprom' function inside the interrupt routine, since it is relatively slow, setting a flag to indicate that an update is required, and handling the 'nitty gritty' in the main program loop.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 9905
Xavier
Guest







Many thanks for your help (no txt)
PostPosted: Mon Dec 09, 2002 5:29 pm     Reply with quote


___________________________
This message was ported from CCS's old forum
Original Post ID: 9916
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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