![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
lovlylion
Joined: 28 Apr 2008 Posts: 1
|
Problem with writing in program flash mem |
Posted: Mon Apr 28, 2008 4:02 pm |
|
|
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);
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 28, 2008 4:53 pm |
|
|
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 ? |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Apr 29, 2008 4:51 am |
|
|
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);
}
} |
|
![](templates/subSilver/images/spacer.gif) |
Matro Guest
|
|
Posted: Tue Apr 29, 2008 5:18 am |
|
|
Declaration of variables shall not be "int" but "unsigned int16".
Matro. |
|
![](templates/subSilver/images/spacer.gif) |
Matro Guest
|
|
Posted: Tue Apr 29, 2008 5:22 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Tue Apr 29, 2008 11:42 am |
|
|
thank u matro;
but iam sorry to tell u that it still not working , but compilation process succed :( |
|
![](templates/subSilver/images/spacer.gif) |
Matro Guest
|
|
Posted: Wed Apr 30, 2008 1:55 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
|
Posted: Wed Apr 30, 2008 6:06 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Matro Guest
|
|
Posted: Wed Apr 30, 2008 6:12 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Blob
Joined: 02 Jan 2006 Posts: 75 Location: Neeroeteren, Limburg, Belgium
|
|
Posted: Wed Apr 30, 2008 6:18 am |
|
|
Wow, thanks Matro that will help me in my own project!!!
i will change my post to avoid misunderstandings...
thanks |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|