• AVR Freaks

Locked[FAQ]Program Memory / Internal EEPROM Reads and Writes

Page: < 1234 > Showing page 3 of 4
Author
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/02/28 19:50:06 (permalink)
0
so any 1 can ans my qn abt using programmer instead of debugger? wad do i hav to change so that i can still save data in the program memory yet runs on programmer mode
#41
kalpak
Super Member
  • Total Posts : 3265
  • Reward points : 0
  • Joined: 2004/03/12 23:01:40
  • Location: India
  • Status: offline
RE: Program Memory / Internal EEPROM Reads and Writes 2006/02/28 20:04:45 (permalink)
0
What have you not understood in the replies by DavidP5 and I? The program runs on the chip, not the programmer or debugger. It will run the same way no matter how you program.
#42
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/02/28 20:47:57 (permalink)
0
all program uses debugger or programmer rite? if you run on dubugger, u will need to connect up the power supply and ICD2 in-circuit dubugger. for programmer u won need to connect up the supply and ICD2 after u program the program into the chip. thus wad i wan koe is that using david's program, wad can i change to use it in programmer and yet able to save the data into chip's memory
#43
DavidP5
Super Member
  • Total Posts : 472
  • Reward points : 0
  • Joined: 2006/02/01 23:23:40
  • Location: New Zealand
  • Status: offline
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/01 01:36:49 (permalink)
0
I don't understand why you write your messages in that odd mangled form of English. How can you expect anyone to take the trouble to decipher it? The idea of written communication is to make it easy for people to understand you. You have not said what your problem is. Perhaps you should post your code and say what is not performing as expected.
#44
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/02 18:41:10 (permalink)
0
sorrie to cause so much misunderstanding, i am using david's program, my prob is that i wan to use it on the chip using programmer. but i don't get the data at 0x5000 as david said.
#45
kalpak
Super Member
  • Total Posts : 3265
  • Reward points : 0
  • Joined: 2004/03/12 23:01:40
  • Location: India
  • Status: offline
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/02 19:19:55 (permalink)
0
Did you run the program? And how did you check the locations to which the code is supposed to write?
#46
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/02 23:42:16 (permalink)
0
i run the program. the data appear on 0x5000 of file register. i was using debugger to run. when i try programmer, no data was shown.
#47
kalpak
Super Member
  • Total Posts : 3265
  • Reward points : 0
  • Joined: 2004/03/12 23:01:40
  • Location: India
  • Status: offline
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/03 00:15:22 (permalink)
0
How did you run the program after you programmed the chip using the programmer? Are you using the ICD2?
post edited by kalpak - 2006/03/03 10:23:47
#48
DavidP5
Super Member
  • Total Posts : 472
  • Reward points : 0
  • Joined: 2006/02/01 23:23:40
  • Location: New Zealand
  • Status: offline
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/03 04:44:53 (permalink)
0
I tested it in debug mode by loading the program memory from the device into MPLAB. In "normal" mode I disconnected the ICD altogether and checked that I could save and load my data into flash by communicating with the device over the serial port to a terminal screen on a pc. Then I disconnected the power for a while, reconnected and used the serial terminal again to check that the data was still there in flash.
 
I'm not sure if you can load the program memory into MPLAB when not in debug mode.
 
Sorry, I can't see what is not working for you. Post your code and tell us more exactly what you are doing.
#49
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/08 15:07:07 (permalink)
0
Thanks, David! Your code helped me figure out this problem (well, half..) as well.
 
But for the other half, I have a question.. How do you read the string data back out of memory once it's been placed there? I tried a few approaches, but I feel that my understanding of the PIC18 is limited.  I'm working with a PIC18F4455/4550, and basically, I'm trying to get each PIC unit to have a unique serial number.
 
I tried first to define a

  const rom char sernum[64] = "0000...."

and then modify it directly via addressof(sernum) but for some reason memcpyram2flash() corrupts several bytes outside of the string boundary (below it, to be exact) when I try this:

  unsigned char sample[10] = "TESTNSTR\0";
  write_flash( &sernum, sample );

plus, I don't think this would be considered a safe method of manipulating variables within a program. grin  The resulting corruption causes the firmware to crash most of the time.
 
Next, I tried both of these:

  memcpypgm2ram( sernum, 0x5000, 10 )
  memcpypgm2ram( foo, 0x5000, 10 )

but they keep returning gibberish or nothing at all.
 
I suspect there is a ridiculously easy way to implement this that I am simply overlooking. Can someone please offer any suggestions?
 
[nutshell] I need to read an 8-char serial number from unused Program Memory (at 0x5000) into a string which the runtime can recognize. [/nutshell]
 
I may just be confused about the typecasting/pointers usage, but if I can see a working example then I will be able to understand it better. Thanks again for all the great info, everyone!
 
Regards,
  Adrian
 
#50
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/08 16:31:45 (permalink)
0
Hello again all,

Never mind! I successfully implemented it this way:


void read_serial(void)
{

unsigned char foo;  // bar
unsigned loc = 0;  // My nifty counter

strcpy( sernum, "" );  // Blank out the current value

while( 1 )
{
memcpypgm2ram( foo, 0x5000 + loc, 1 );  // Get 1 tedious byte at a time..

if( loc >= 8 ) break;  // Got all 8 digits, thank you, goodbye.

strcat( sernum, foo );  // append the char to the global for all to enjoy

loc++;  // Increment the counter..
}

// All is well. unsigned char sernum[] is now holding the value I read from 0x5000..
}


Thanks again (and again-- I have learned a lot since starting this project!) everyone!

Regards,
Adrian

PS: I have since simplified it to this:


void read_serial(void)
{
unsigned char foo;
unsigned loc = 0;

strcpy( sernum, "" );

for( loc = 0; loc < 9; loc++ )
{
   memcpypgm2ram( foo, 0x5000 + loc, 1 );
   strcat( sernum, foo );
}
}

 
Smile
post edited by Adrian512 - 2006/03/08 16:37:24
#51
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/13 23:39:43 (permalink)
0
to adrian, wads does ya program do? how does it work? does it get a value from the serial port and store in in memory?
#52
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/19 05:23:06 (permalink)
0
ppl i have a question, wher can i find the libraries for memcpyram2flash as used by david's program?
#53
DavidP5
Super Member
  • Total Posts : 472
  • Reward points : 0
  • Joined: 2006/02/01 23:23:40
  • Location: New Zealand
  • Status: offline
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/19 16:11:32 (permalink)
0
ORIGINAL: boi^boi

ppl i have a question, wher can i find the libraries for memcpyram2flash as used by david's program?

 
It doesn't use any libraries. All the variables are defined in the program or in the pic18f452 header file.
#54
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/29 22:28:18 (permalink)
0
david, for the program you posted regarding the memcpyram2flash, is there other options? like other commands which works the same way?
 
#55
DavidP5
Super Member
  • Total Posts : 472
  • Reward points : 0
  • Joined: 2006/02/01 23:23:40
  • Location: New Zealand
  • Status: offline
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/30 21:27:39 (permalink)
0
What do you mean "other options", or "other commands which work the same way"?
I have not got a clue what you are asking here.
#56
kalpak
Super Member
  • Total Posts : 3265
  • Reward points : 0
  • Joined: 2004/03/12 23:01:40
  • Location: India
  • Status: offline
RE: Program Memory / Internal EEPROM Reads and Writes 2006/03/30 21:43:47 (permalink)
0
Amen!
#57
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/04/02 22:49:07 (permalink)
0
i saw in the MPLAB C18 C compiler libraries tat there is also memcpypgm2ram etc. does these command works the same way as the memcpyram2flash u used?
 
#58
DavidP5
Super Member
  • Total Posts : 472
  • Reward points : 0
  • Joined: 2006/02/01 23:23:40
  • Location: New Zealand
  • Status: offline
RE: Program Memory / Internal EEPROM Reads and Writes 2006/04/02 23:03:12 (permalink)
0
ORIGINAL: boi^boi

i saw in the MPLAB C18 C compiler libraries tat there is also memcpypgm2ram etc. does these command works the same way as the memcpyram2flash u used?


 
Unfortunately the answer is NO, which is why I had to figure out how to write memcpyram2flash(). I presume that the reason there is no memcpyram2flash() in the libraries is that different chips handle this task differently (eg different number of bytes written at a time), but I'm not too sure about this. Perhaps someone more knowledgable than either of us newbies could tell us why there is no library function for writing to flash?
 
You have been asking questions about this for a while. What are you actually trying to do?
#59
Guest
Super Member
  • Total Posts : 80500
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
RE: Program Memory / Internal EEPROM Reads and Writes 2006/04/05 20:34:38 (permalink)
0
wad i gt here is a program tat receive characters from the hyper terminal, i m using PICDEM 2 PLUS DEMO BOARD. and this runs in either debbuger or programmer mode. wad my problem is how to save the characters i received into PIC's memory so tat i can double check on what is received. the data stored must b able to remain in the memory even when there is no power supply.i was hopin to use programmer mode rather den debugger mode. below is my program.

#include <p18f452.h>
void Init_LCD(void);       // Initialize the LCD
void W_ctr_4bit(char);    // 4-bit Control word for LCD
void W_data_4bit(char);  // 4-bit Text Data for LCD
void Delay_1kcyc(void);   // 1000 cycles delay
void Delay_100kcyc(void);   // 100,000 cycles delay
void Init_com(void);  // Initialize the Computer

#define LCD_DATA PORTD
#define LCD_RW    PORTAbits.RA2    // RW signal for LCD
#define LCD_RS    PORTAbits.RA3    // RS signal for LCD
#define LCD_E     PORTAbits.RA1    // E signal for LCD
unsigned char LCD_TEMP;
unsigned char USART_TEMP;

void main(){
ADCON1  = 0x07;   // Set Port A & E as digital I/O
TRISA   = 0b11110001;  // bit 1, 2 & 3 of Port A as output
 TRISD   = 0;   // Port D as output
Init_LCD();           // Init LCD 4-bit interface, multiple line
 Init_com();           // Init Com

while (1)            //finite loop
{
if (PIR1bits.RCIF)         //if PIR1 bit is RCIF
{
W_data_4bit(RCREG); //get char from hyper term and display
}
}
}
void Init_com(){
TRISC=0b10111111;  // RX as input,TX as output
SPBRG=12;   // Baud rate is 19200
TXSTA=0b00100100;  // Asyn mode, 8-bit data
RCSTA=0b10010000;  // serial port enable, 8-bit data
}
void Init_LCD(){  /* LCD display initialization */
//Sequence a) to d) required for 4-bit interface 
for(i = 0; i < 15; i++) Delay_1kcyc();  //   a) 
W_ctr_4bit(0x03);    //   b) 
for(i = 0; i < 5; i++) Delay_1kcyc();  //   c) 
W_ctr_4bit(0x02);    //   d) 
W_ctr_4bit(0b00101000);  
W_ctr_4bit(0b00001101);    // Display on, cursor on
W_ctr_4bit(0b00000110);   
W_ctr_4bit(0b00000001);    // Clear display & home position
}
void W_ctr_4bit(char x){
/* Write control word in term of 4-bit at a time to LCD */
LCD_RW = 0;     // Logic ‘0’
LCD_RS = 0;     // Logic ‘0’
LCD_TEMP  = x;     // Store control word
LCD_TEMP >>= 4;     // send upper nibble of control word
LCD_E = 1;     // Logic ‘1’
LCD_DATA  = LCD_TEMP;
Delay_1kcyc();     // 1ms delay
LCD_E = 0;     // Logic ‘0’
Delay_1kcyc();     // 1ms delay
LCD_TEMP = x;     // Store control word
LCD_TEMP &= 0x0f;    // Send lower nibble of control word
LCD_E = 1;     // Logic ‘1’
LCD_DATA  = LCD_TEMP;
Delay_1kcyc();     // 1ms delay
LCD_E = 0;     // Logic 0’
Delay_1kcyc();     // 1ms delay
}
void W_data_4bit(char x){
/* Write text data in term of 4-bit at a time to LCD */
LCD_RW  = 0;     // Logic ‘0’
LCD_RS  = 1;     // Logic ‘1’
LCD_TEMP  = x;     // Store text data
LCD_TEMP  >>= 4;     // Send upper nibble of text data
LCD_E  = 1;     // Logic ‘1’
LCD_DATA = LCD_TEMP;
Delay_1kcyc();     // 1ms delay
LCD_E  = 0;     // Logic ‘0’
Delay_1kcyc();     // 1ms delay
LCD_TEMP  = x;     // Store text data
LCD_TEMP &= 0x0f;     // Send lower nibble of text data
LCD_E  = 1;     // Logic ‘1’
LCD_DATA = LCD_TEMP;
Delay_1kcyc();     // 1ms delay
LCD_E  = 0;     // Logic ‘0’
Delay_1kcyc();     // 1ms delay
}
void Delay_1kcyc(){
/* 1,000 cycles delay routine.  For 1 4MHz crystal, it is 1ms delay */
  unsigned int j;
for(j=0; j<65; j++);
}
post edited by boi^boi - 2006/04/05 20:37:34
#60
Page: < 1234 > Showing page 3 of 4
Jump to:
© 2019 APG vNext Commercial Version 4.5