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

strange problem regarding internal EEPROM

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



Joined: 28 Dec 2012
Posts: 21

View user's profile Send private message

strange problem regarding internal EEPROM
PostPosted: Mon Apr 08, 2013 2:46 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Apr 08, 2013 3:52 am     Reply with quote

Code:
char chg=" ";
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.
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