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

Problem with writing in program flash mem

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



Joined: 28 Apr 2008
Posts: 1

View user's profile Send private message

Problem with writing in program flash mem
PostPosted: Mon Apr 28, 2008 4:02 pm     Reply with quote

HI all

i tried to write in flash program memory using CCS on pic16f887 , the compilation process give me succesful but running it not doing any thing...its my code :
Code:

#include <16F887.h>

void main(){
int i=0x1000
for(;i<=0x1fff;i++) {
   value=0x0006; 
   write_program_memory(i, value, 2);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 28, 2008 4:53 pm     Reply with quote

Where are your #fuses and #use delay() statements ? Where are your variable declarations ? How are you checking if the program memory
has been written correctly ?

Post a complete test program with all of the items listed above.
Also post your compiler version.

Is this test being done on a hardware board, or are you doing it with
a simulator in MPLAB or Proteus ?
Guest








PostPosted: Tue Apr 29, 2008 4:51 am     Reply with quote

i don't use anything need delay,
i use mplab v8.0.2
i have pickit2 so i tested with it and read mem after execution of this program

its the complete code:

#include <16F887.h>
// 16F887.h for fuse option constants.
#FUSES INTRC,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN,NOLVP
void main(){
int i=0x1000,value=0x0006;
for(;i<=0x1fff;i++) {
write_program_memory(i, value, 2);

}
}
Matro
Guest







PostPosted: Tue Apr 29, 2008 5:18 am     Reply with quote

Declaration of variables shall not be "int" but "unsigned int16".

Matro.
Matro
Guest







PostPosted: Tue Apr 29, 2008 5:22 am     Reply with quote

Moreover data shall be transmitted through a pointer.

Code:

#include <16F887.h>
// 16F887.h for fuse option constants.
#FUSES INTRC,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN,NOLVP
void main(){
unsigned int16 i,value;
value=0x0006;
for(i=0x1000;i<=0x1fff;i++) {
write_program_memory(i, &value, 2);
}
}


Matro
Guest








PostPosted: Tue Apr 29, 2008 11:42 am     Reply with quote

thank u matro;

but iam sorry to tell u that it still not working , but compilation process succed :(
Matro
Guest







PostPosted: Wed Apr 30, 2008 1:55 am     Reply with quote

Anonymous wrote:
thank u matro;

but iam sorry to tell u that it still not working , but compilation process succed :(

Be aware that this code will take about 0x1000 * 5ms = 20s to execute.
Moreover, you set the NOMCLR fuse so your device can't be programmed through ICSP. I don't how you program it, but if you use ICSP programming it will surely result in bugs.
If this is the problem, the following code should work:
Code:


#include <16F887.h>
// 16F887.h for fuse option constants.
#FUSES INTRC,NOWDT,NOPUT,MCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN,NOLVP
void main(){
unsigned int16 i,value;
value=0x0006;
for(i=0x1000;i<=0x1fff;i++) {
write_program_memory(i, &value, 2);
}
}


Matro
Blob



Joined: 02 Jan 2006
Posts: 75
Location: Neeroeteren, Limburg, Belgium

View user's profile Send private message

PostPosted: Wed Apr 30, 2008 6:06 am     Reply with quote

hello,


you declare int16.

it is 4 bytes right?

no, not right, as matro mentions in next reply a byte is 8 bits
and an int16 is then 2 bytes


then write_program_memory(adress, dataptr, count)

adress being the adress 16 bit

dataptr pointer to data

count bytes to write => int16 = 4 bytes => count should be 4

nit should be 2

Best Regards


Last edited by Blob on Wed Apr 30, 2008 6:23 am; edited 3 times in total
Matro
Guest







PostPosted: Wed Apr 30, 2008 6:12 am     Reply with quote

Blob wrote:
hello,


you declare int16.

it is 4 bytes right?

then write_program_memory(adress, dataptr, count)

adress being the adress 16 bit

dataptr pointer to data

count bytes to write => int16 = 4 bytes => count should be 4

Best Regards

When working with PIC (like most of CPUs), a byte is 8-bit long.
So an int16 is 2 bytes.
"count" shall be 2 as mentioned.

Matro
Blob



Joined: 02 Jan 2006
Posts: 75
Location: Neeroeteren, Limburg, Belgium

View user's profile Send private message

PostPosted: Wed Apr 30, 2008 6:18 am     Reply with quote

Wow, thanks Matro that will help me in my own project!!!

i will change my post to avoid misunderstandings...

thanks
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