|
|
View previous topic :: View next topic |
Author |
Message |
syeda amna
Joined: 28 Dec 2012 Posts: 21
|
strange problem regarding internal EEPROM |
Posted: Mon Apr 08, 2013 2:46 am |
|
|
I am facing a strange problem. I want to test the internal eeprom of the controller. I made a test program. When i entered a number which is less than 11 digits like 1233456 it works well. if the entered data is greater than 11 digits then the eeprom value changes. there is no command for writing eeprom.
example:
entered quantity=123456
chg=Null
entered quantity=01234567890123456789
chg=123456789
plzz help me. where is the problem?
Code: |
#include <18F452.h>
#fuses HS,NOWDT,NOLVP,PUT,NOPROTECT,BROWNOUT
#use delay(clock=16M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <string.h>
#include <input.c>
void main()
{
char chg=" ";
char pass[24] = {""};
chg=read_eeprom(0);
puts(chg);
get_string(pass, 24);
puts("\n");
puts(chg);
} |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Apr 08, 2013 3:52 am |
|
|
This line is wrong, you cannot assign a string to single character variable.
Because of weak type checking in the CCS compiler you are not warned, but this is an error in your program.
A string is an array of characters, terminated by a zero. So, the shortest string you can make consists of 1 character + a zero, total 2 bytes.
Try: Code: | #include <18F452.h>
#fuses HS,NOWDT,NOLVP,PUT,NOPROTECT,BROWNOUT
#use delay(clock=16M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <string.h>
#include <input.c>
void main()
{
char chg[2];
char pass[24] = {""};
chg[0]=read_eeprom(0);
chg[1]=0; // Add string terminating zero
puts(chg);
get_string(pass, 24);
puts("\n");
puts(chg);
while(1); // loop forever. Prevent the processor from going to sleep and
// not sending the last characters in the UART buffer.
} | Note that in this example the variable chg has changed from a 'char' to an 'array of char'. This is a huge difference to the compiler, the variable chg is not just a single byte in memory any more but has changed to a pointer, i.e. a variable holding an address to data stored somewhere else in memory. |
|
|
|
|
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
|