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

Write_Program_Memory command:)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

Write_Program_Memory command:)
PostPosted: Wed Aug 04, 2004 9:33 am     Reply with quote

Now i am pursueing a project for RF link. There is a large amount of data to store, and there is no external EEprom on my board. So i want to store those data into the program memory of PIC16F873.

I try to use the built-in function Write_program_memory(),but it can not work. So could someone give out some sample code for write_program_memory() function which can work. thank you!
bdavis



Joined: 31 May 2004
Posts: 86
Location: Colorado Springs, CO

View user's profile Send private message

PostPosted: Wed Aug 04, 2004 11:41 am     Reply with quote

Did you try disabling all interrupts? I heard this was an issue - if interrupts are enabled, then it won't work. I saw a post on this not too long ago.
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

thank you, but i still have some question :)
PostPosted: Wed Aug 04, 2004 2:05 pm     Reply with quote

1) If i want to write the data into program memory, that means i had to enable the "Flash memery Writable" in configuration bits. --is it (the #fuse NoProtect ) flag that enable the "flash memory write"?

2)low voltage programming---did i need to enable the low voltage programming during the data writing procession into program memory? because when we use ICD2 to burn the program into chip, the program voltage is 9V, but the common usage for PIC MCU is only 5V.

3) So when i use the function write_program_memory, what is the #fuse flag?



//****************************
char rx_buffer[32];
int *pointer;
pointer = rx_buffer;

while(index<11)
{

write_program_memory(0x0e00+index,pointer[index],2);
index++;
}
//*****************************
part of my code, for writing the data from rx_buffer (RS232) into program memory.

anyone could told me whether there is something wrong with it:)

4) The difference between write_program_eeprom and write_program_memory. From the CCS manual, it looks can achieve the same function, write the data into program memory, but whether there is some difference?

Thank you!!
bdavis



Joined: 31 May 2004
Posts: 86
Location: Colorado Springs, CO

View user's profile Send private message

PostPosted: Wed Aug 04, 2004 4:26 pm     Reply with quote

Sorry - I can't help you on that one - I haven't directly tried it, but may try it in a few days. You may want to look at the bootloader.c and other bootloaders, and look at their fuse settings since they need to program the memory. Of course it can't be protected, but I believe the PROTECT fuse pertains to externally being able to read the program memory.
jpa
Guest







Re: thank you, but i still have some question :)
PostPosted: Thu Aug 05, 2004 5:47 am     Reply with quote

garyzheng wrote:
1) If i want to write the data into program memory, that means i had to enable the "Flash memery Writable" in configuration bits. --is it (the #fuse NoProtect ) flag that enable the "flash memory write"?

2)low voltage programming---did i need to enable the low voltage programming during the data writing procession into program memory? because when we use ICD2 to burn the program into chip, the program voltage is 9V, but the common usage for PIC MCU is only 5V.

3) So when i use the function write_program_memory, what is the #fuse flag?



//****************************
char rx_buffer[32];
int *pointer;
pointer = rx_buffer;

while(index<11)
{

write_program_memory(0x0e00+index,pointer[index],2);
index++;
}
//*****************************
part of my code, for writing the data from rx_buffer (RS232) into program memory.

anyone could told me whether there is something wrong with it:)

4) The difference between write_program_eeprom and write_program_memory. From the CCS manual, it looks can achieve the same function, write the data into program memory, but whether there is some difference?

Thank you!!


1) I didn't try yet, so I can't help you on this; reading Microchip datasheet should give you the answer

2) I don't think it is necessary but didn't try it yet

3) Second argument to Write_program_memory is a pointer to data byte; however pointer[index] is not a pointer... the second argument could be "pointer+index"or &(pointer[index])

4) Difference between functions is the 3rd argument of write_program_memory which indicates the number of bytes to be written. write_program_eeprom writes only two bytes.

Hope it can help you.
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

thank you for tips
PostPosted: Thu Aug 05, 2004 8:35 am     Reply with quote

i will try and look what will happen. But if some one had example code, give me some hints or post some part of code here:)
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

OK, i think i achieve the goal!
PostPosted: Thu Aug 05, 2004 9:32 am     Reply with quote

So hehe, after reading some assemble code, i found that we should disable all the interrupts before write the ROM. Thank you for some hints!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 05, 2004 11:18 am     Reply with quote

Quote:

Did you try disabling all interrupts? I heard this was an issue - if interrupts are enabled, then it won't work. I saw a post on this not too long ago.


The first response to you post told you that!
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

thanks, mark, but i think i meet another problem!
PostPosted: Fri Aug 06, 2004 8:25 am     Reply with quote

when I write the data sentence by sentence into ROM, it can work. But when i write the data like a stream, it can only wirte the first sentence, after that , it can not work?

because the data is transmitted by RS232(BAUD RATE= 9600) from PC
I wonder whether the Writing procession into ROM should consume some time, but the data stream transmission from RS232 is too faster than the writing procession of ROM, so that cause the error:)

so someone meet that problem before, and could some one told me how many time the Write_program_memory will take:)

thank you!
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri Aug 06, 2004 8:40 am     Reply with quote

Why not write a test program that writes to program memory without the serial link. Break the problem down. If you can write a series of constants to program memory you can be sure the problem is or is not the function to write to program memory. You can read the HEX file from the chip after it runs and see if it is working.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Fri Aug 06, 2004 10:45 am     Reply with quote

Yes writing to the flash takes some time. Look at the datasheet for the time required.
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

thanks, mark and neutone:)
PostPosted: Fri Aug 06, 2004 11:59 am     Reply with quote

i will try to delay the package transmission from PC
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

new problem:)
PostPosted: Mon Aug 09, 2004 1:10 pm     Reply with quote

Now my program can work by receiving and store the data into program memory package by package. But now I found a weird problem.


**************part of my program*************
if( (rx_preamble[0]=='S') && (rx_preamble[2]=='1')) // screen 1Smile
{
if( (rx_preamble[5]=='A') && (rx_preamble[7]=='1'))
{
storecount=11;
startadd=0x0d00;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='A') && (rx_preamble[7]=='2'))
{
storecount=11;
startadd=0x0d10;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='A') && (rx_preamble[7]=='3'))
{
storecount=5;
startadd=0x0d20;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='A') && (rx_preamble[7]=='4'))
{
storecount=15;
startadd=0x0d30;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='B') && (rx_preamble[7]=='1'))
{
storecount=11;
startadd=0x0d40;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='B') && (rx_preamble[7]=='2'))
{
storecount=10;
startadd=0x0d50;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='B') && (rx_preamble[7]=='3'))
{
storecount=10;
startadd=0x0d60;
store16(storecount,startadd);
return;
}
if ( (rx_preamble[5]=='B') && (rx_preamble[7]=='4'))
{
storecount=10;
startadd=0x0d70;
store16(storecount,startadd);
return;
}
else
{
return;
;
}
}
**********************************************

I store several different infomation into program memory from address 0x0d00 to 0x0df0. Every time I store one of the infomation(such as I store the info into address 0x0db0), the infomation stored in the lower address(such as 0x0dc0,0x0dd0,0x0de0) will change. Some strange character will shift from the upper address.

some one met this problem before, give me some idea:)

another question is for the write procession time. I know that the flash memory writing time is about 4ms to 8ms for one word. During the writing procession , MCU should shut down the interrupts. my method is to give out 100ms delay before enable the global interrupts. But sometimes it can work, but sometimes, i can not work.

can some one give out some good ideas, thank you:)
garyzheng



Joined: 22 Jul 2004
Posts: 25

View user's profile Send private message

some one met this problem before?:)please give me a hint:)
PostPosted: Tue Aug 10, 2004 8:28 am     Reply with quote

thank you!
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Tue Aug 10, 2004 9:09 am     Reply with quote

Are you by chance attempting to write across page boundries? You may only write one page at a time and your packet size should be based on the page size.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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