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 support@ccsinfo.com

word address or byte address?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
santosh.manicka



Joined: 11 Aug 2008
Posts: 16

View user's profile Send private message

word address or byte address?
PostPosted: Thu Aug 14, 2008 1:16 pm     Reply with quote

I am using a PIC18F6722 and PCW compiler.
In the function, write_program_memory( address, dataptr, count );
is 'address' a word-address or a byte-address?

I know it's an int32 and table read/writes between program memory and data memory happen in bytes, but they don't necessarily imply that the above function uses a word-address.

Gurus, please respond!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 14, 2008 1:44 pm     Reply with quote

The CCS manual makes it clear that the function writes bytes.
Quote:
Syntax: write_program_memory( address, dataptr, count );
Parameters: address is 16 bits on PCM parts and 32 bits on PCH parts.
dataptr is a pointer to one or more bytes.
count is a 8 bit integer.
Returns: undefined
Function: Writes count bytes to program memory from dataptr to address.
santosh.manicka



Joined: 11 Aug 2008
Posts: 16

View user's profile Send private message

PostPosted: Thu Aug 14, 2008 2:00 pm     Reply with quote

Well, assume that 'address' is a word-address. For instance,

address = 0x0000; //address points to the 0th byte
int8 data = 1; //&data points to 1 byte
write_program_memory(address, &data, 1);

address++; // Now, address points to the 2nd byte because it points to a wrd
write_program_memory(address, &data, 1);

Therefore, the 0th byte and the 2nd byte contain the value one but the 1st byte has been skipped.

Since the above is also possible, it does not seem obvious to me that 'address' has to be a byte-address.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Aug 14, 2008 2:03 pm     Reply with quote

The sure-fire way to tell is to write a trivial program and look at the assembly code it creates. That will answer all questions.
_________________
The search for better is endless. Instead simply find very good and get the job done.
gribas



Joined: 21 Feb 2008
Posts: 21

View user's profile Send private message

PostPosted: Thu Aug 14, 2008 2:43 pm     Reply with quote

I think you're mixing things up. Do you understand the difference between:
Code:

 int16 addr16;    // 16 bit variable
 int32 addr32;    // 32 bit variable
 int8* addr8p;    // pointer to a byte
 int16* addr16p;  // pointer to a word
 int32* addr32p;  // pointer to a dword
 


the result of address++; depends on the variable type. For int16, int32 and int8* it adds one, for int16* it adds 2 and for int32* it adds 4. Notice that the size of the pointer variables is the same, you can check how many bits they have in the .sym file, in the compiler settings.
Code:

Compiler Settings:
    Processor:      PIC18F4525
    Pointer Size:   16
    ADC Range:      0-255
    Opt Level:      9
    Short,Int,Long: UNSIGNED: 1,8,16
    Float,Double:   32,32
santosh.manicka



Joined: 11 Aug 2008
Posts: 16

View user's profile Send private message

PostPosted: Thu Aug 14, 2008 2:52 pm     Reply with quote

I had mentioned the data type in my first post...may be I didn't emphasize enough on that.

In my example, address in int32.
So, address++ will increment it by 1, I understand. The function where I am using this variable is write_program_memory which will write into the program memory and NOT the RAM.

So, if the processor's addressing mode is word rather than byte, then the next address will point to the next word...OR may be the compiler sees it as a byte-address and handles the word-addressing mode on its own with the processor. That's what I want to clarify.
gribas



Joined: 21 Feb 2008
Posts: 21

View user's profile Send private message

PostPosted: Thu Aug 14, 2008 4:05 pm     Reply with quote

Sorry, I misunderstood your question.

You're right, the PC is always even, which means it can never point to an address like 0x0001. But that doesn't imply that word addressing is used for all access to the program memory.

According to my datasheet (18f4525), the program memory is addressed in bytes and you can read and write wherever you see fit. You have to write in chunks of 64 bytes but that's another issue...

So, the PIC is capable and the docs state that the compiler is capable of byte addressing. I've never used that function so I cannot vouch for it.

Do as SherpaDoug said and you'll have your unassailable answer =). Just comment the line #nolist in your "18F6722.h" so you can see all the code for the function.

hope it helps,
santosh.manicka



Joined: 11 Aug 2008
Posts: 16

View user's profile Send private message

PostPosted: Fri Aug 15, 2008 10:13 am     Reply with quote

Thank you for the suggestions. I wrote the following piece and concluded that successive addresses(int32 values) refer to the successive bytes and not words.
Code:

         int8 i;
         int16 j;
         Addr = FlashProfileStart[0];
         fprintf(SECONDARY_STREAM,"Addr = %ld\n",Addr);
         i = 191;
         write_program_memory(Addr, &i, 1);
         Addr++;
         i = 56;
         write_program_memory(Addr, &i, 1);
         Addr = FlashProfileStart[0];
         j = 0;
         read_program_memory(Addr, &j, 2);
         i = j & 0x00FF;
         fprintf(SECONDARY_STREAM,"LSB = %u\n",i);
         j = j & 0xFF00;
         j = j>>8;
         i = j & 0x00FF;
         fprintf(SECONDARY_STREAM,"MSB = %u\n",i);



Results:
MSB = 191;
LSB = 56;
Ttelmah
Guest







PostPosted: Mon Aug 18, 2008 9:09 am     Reply with quote

I agree the manual is not exactly 'explicit' about this.
It is clear in the function that give 16bit writes - write_program_eeprom, where the manual says that when writing these 16bit values, the LSB of the address, must always be '0', which tells you that the address is in bytes, and because you are writing whole words, you can only access the even addresses.

Best Wishes
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