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 External eeprom...
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
karthickiw



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

View user's profile Send private message Send e-mail

Problem with External eeprom...
PostPosted: Wed Jun 24, 2009 9:21 am     Reply with quote

Dear CCS Friends,

I write a program for write and read the string in external eeprom. After finished my code, I write the three string data in specified locations. After that I read one by one location, I received wrong data for (17*13) location and other location data are correct.
Code:

#include "2464.c"

void write_ext(long int add,char data[])
{
long int loc=0;

 for (loc = 0; loc <= strlen(data); loc++)
   {
       if ( loc < strlen(data)) write_ext_eeprom((loc+add), data[loc]);
       else write_ext_eeprom((loc+add), '\0');
    }
}

void read_ext(long int add)
{
long int loc=0;
char data[];

for (loc = 0; loc < 13; loc++)
   {   
       if (read_ext_eeprom(loc+add)=='\0')
       {
       data[loc]=read_ext_eeprom(loc+add);
       break;
       }
       else
      {
       data[loc]=read_ext_eeprom(loc+add);
      }
     }
printf("%S\n\r",data);
}



void main()
{
char name[15];
long int j=0;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
 printf("Start...\n\r");
 init_ext_eeprom();
 delay_ms(20);
.
.
.
.
.
.
sprintf(name,"%s","Programmer");
write_ext(15*13,name);
delay_ms(20);


sprintf(name,"%s","Karthic");
write_ext(16*13,name);
delay_ms(20);

sprintf(name,"%s","Welcome");
write_ext(17*13,name);
delay_ms(20);

.
.
.
.
while(true)
{
read_ext((15*13));
delay_ms(1000);
read_ext((16*13));
delay_ms(1000);
read_ext((17*13));
delay_ms(1000);
}
}


For my program I received below answer in hyper terminal.
Quote:
Start….
Programmer
Karthic
Karthic

I using PIC18LF452 controller and 24C64 EEPROM.

Please check my code and give idea for my problem... Crying or Very sad

two question regarding 24C64 IC

1) How many byte is store in 24C64 eeprom?. i see the datasheet, but have little confusion.

2) i want to store the 4MB of data, for that what type of memory is used?. Please give any suggestion .
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jun 24, 2009 11:21 am     Reply with quote

How much storage do you expect to be assigned by CCS C with this variable definition?
Code:
char data[];
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

Re: Problem with External eeprom...
PostPosted: Wed Jun 24, 2009 11:24 am     Reply with quote

The part has 64kbit or 8 kbytes of storage. You would likely address it using a number from zero to 7999. Your function declaration here is not correct:

Code:

void write_ext(long int add,char data[])


If you want a function to accept an array as an input you have to declare a pointer to the first element of the array like:

Code:

void write_ext(long int add,char* data)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 24, 2009 12:26 pm     Reply with quote

Quote:
You would likely address it using a number from zero to 7999

The size numbers in the eeprom data sheet are binary, not decimal.
It has 8192 bytes. The address range is from 0 to 8191.

Quote:
Your function declaration here is not correct:

In fact, it works fine. The test program shown below displays the
following output:
Quote:
Hello World

Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void write_ext(long int add, char data[])
{
printf("%s", data);
}

//==================================
void main()
{
int8 buffer[32];

strcpy(buffer, "Hello World");

write_ext(0, buffer);

while(1);
}
karthickiw



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

View user's profile Send private message Send e-mail

Full actual Program
PostPosted: Wed Jun 24, 2009 12:39 pm     Reply with quote

Dear Friends,

Thank you for your idea, but still I have a problem during read the 17*13 location...
Code:

#include <18F452.h>

#device adc=8
#include <string.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES XT                       //High speed Osc (> 4mhz)
#FUSES PROTECT                  //Code protected from reads
#FUSES NOOSCSEN                 //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES BORV20                   //Brownout reset at 2.0V
#FUSES PUT                      //Power Up Timer
#FUSES STVREN                   //Stack full/underflow will cause reset
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                      //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES WRT                      //Program Memory Write Protected
#FUSES WRTD                     //Data EEPROM write protected
#FUSES WRTB                     //Boot block write protected
#FUSES WRTC                     //configuration registers write protected
#FUSES CPD                      //Data EEPROM Code Protected
#FUSES CPB                      //Boot Block Code Protected
#FUSES EBTR                     //Memory protected from table reads
#FUSES EBTRB                    //Boot block protected from table reads

#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)


#include "2464.c"

void write_ext(long int add,char* data)
{
long int loc=0;

 for (loc = 0; loc <= strlen(data); loc++)
   {
       if ( loc < strlen(data)) write_ext_eeprom((loc+add), data[loc]);
       else write_ext_eeprom((loc+add), '\0');
    }
}

void read_ext(long int add)
{
long int loc=0;
char data[];

for (loc = 0; loc < 13; loc++)
   {   
       if (read_ext_eeprom(loc+add)=='\0')
       {
       data[loc]=read_ext_eeprom(loc+add);
       break;
       }
       else
      {
       data[loc]=read_ext_eeprom(loc+add);
      }
     }
printf("%S\n\r",data);
}

void main()
{
char name[15];
long int j=0;
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
//Setup_Oscillator parameter not selected from Intr Oscillotar Config tab
 printf("Start...");
 init_ext_eeprom();
 delay_ms(20);
////////////////////////12 character size without null///////////////////////
sprintf(name,"%s","Erode");
write_ext(0,name);
delay_ms(100);

sprintf(name,"%s","Savitha");
write_ext(1*13,name);
delay_ms(100);

sprintf(name,"%s","PS Park");
write_ext(2*13,name);
delay_ms(100);

sprintf(name,"%s","GH");
write_ext(3*13,name);
delay_ms(100);

sprintf(name,"%s","Sathiyam Hos");
write_ext(4*13,name);
delay_ms(100);

sprintf(name,"%s","Collector of");
write_ext(5*13,name);
delay_ms(100);

sprintf(name,"%s","Kumalan kutt");
write_ext(6*13,name);
delay_ms(100);

sprintf(name,"%s","palayapalaya");
write_ext(7*13,name);
delay_ms(100);

sprintf(name,"%s","Veer Palayam");
write_ext(8*13,name);
delay_ms(100);

sprintf(name,"%s","Sengotampala");
write_ext(9*13,name);
delay_ms(100);

sprintf(name,"%s","Thindal");
write_ext(10*13,name);
delay_ms(100);

sprintf(name,"%s","Thindal medu");
write_ext(11*13,name);
delay_ms(100);

sprintf(name,"%s","Pavalathan p");
write_ext(12*13,name);
delay_ms(100);

sprintf(name,"%s","Veppanpalaya");
write_ext(13*13,name);
delay_ms(100);

sprintf(name,"%s","Mettukadai");
write_ext(14*13,name);
delay_ms(100);

sprintf(name,"%s","Vannankattu");
write_ext(15*13,name);
delay_ms(100);

sprintf(name,"%s","Moolakkarai");
write_ext(16*13,name);
delay_ms(100);

sprintf(name,"%s","Sathiramput");
write_ext(17*13,name);
delay_ms(100);

sprintf(name,"%s","Koorapalayam");
write_ext(18*13,name);
delay_ms(100);

sprintf(name,"%s","Vaaikkalmedu");
write_ext(19*13,name);
delay_ms(100);

sprintf(name,"%s","Maharaja col");
write_ext(20*13,name);
delay_ms(100);

sprintf(name,"%s","Kanthampalay");
write_ext(21*13,name);
delay_ms(100);

sprintf(name,"%s","Police stati");
write_ext(22*13,name);
delay_ms(100);


sprintf(name,"%s","Perundurai");
write_ext(23*13,name);
delay_ms(100);

   while(True)
   {

    read_ext((j*13));
    output_high(pin_a0);
    delay_ms(500);
     output_low(pin_a0);
     delay_ms(500);
     j++;
if (j==24) j=0;
   }// while

}



output from hyper terminal

Quote:
Start...Erode
Savitha
PS Park
GH
Sathiyam Hos
Collector of
Kumalan kutt
palayapalaya
Veer Palayam
Sengotampala
Thindal
Thindal medu
Pavalathan p
Veppanpalaya
Mettukadai
Vannankattu
Moolakkarai
Moolakkarai --->This is problem string (actual here present Sathiramput)
Koorapalayam
Vaaikkalmedu
Maharaja col
Kanthampalay
Police stati
Perundurai
Crying or Very sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 24, 2009 12:41 pm     Reply with quote

Quote:

For my program I received below answer in hyper terminal.

Start….
Programmer
Karthic
Karthic

So apparently your complaint is that it's repeating "Karthic" instead
of displaying "Welcome" ? Post some more of the output. Does it
only display "Karthic" after the initial lines ?

Post your #fuses statement.
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Wed Jun 24, 2009 12:59 pm     Reply with quote

That and he is getting the same string at 17*13 as 16*13 for some reason. Going back this looks a bit fishy:

Code:

void read_ext(long int add)
{
long int loc=0;
char data[];

}


I don't know whether you can allocated memory for an array without telling the compiler how big the array is. I would try something like:

Code:

char data[23]; //is that how many names you have there?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 24, 2009 1:03 pm     Reply with quote

Quote:
Going back this looks a bit fishy:

void read_ext(long int add)
{
long int loc=0;
char data[];

data[loc]=read_ext_eeprom(loc+add);

I agree. He's writing to an array which doesn't have any RAM allocated
for it, because the size was not specified. He is likely to be over-writing
other RAM locations.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jun 24, 2009 4:45 pm     Reply with quote

Yes, it's been said, but he doesn't hear.
karthickiw



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

View user's profile Send private message Send e-mail

Problem not solve...
PostPosted: Wed Jun 24, 2009 8:49 pm     Reply with quote

Thank you PCM,FvM and mkuang. now i specified the array size in read_ex function, then also my problem is not solved..

Code:
void read_ext(long int add)
{
long int loc=0;
char data[15];

for (loc = 0; loc < 13; loc++)
   {   
       if (read_ext_eeprom(loc+add)=='\0')
       {
       data[loc]=read_ext_eeprom(loc+add);
       break;
       }
       else
      {
       data[loc]=read_ext_eeprom(loc+add);
      }
     }
printf("%S\n\r",data);
}



my output is

Code:
Start...Erode
Savitha
PS Park
GH
Sathiyam Hos
Collector of
Kumalan kutt
palayapalaya
Veer Palayam
Sengotampala
Thindal
Thindal medu
Pavalathan p
Veppanpalaya
Mettukadai
Vannankattu
Moolakkarai
Moolakkarai --->This is probelm string( actual here present Sathiramput)
Koorapalayam
Vaaikkalmedu
Maharaja col
Kanthampalay
Police stati
Perundurai


[quote="PCM programmer"]
Quote:
Going back this looks a bit fishy:

void read_ext(long int add)
{
long int loc=0;
char data[];

data[loc]=read_ext_eeprom(loc+add);


Quote:

I agree. He's writing to an array which doesn't have any RAM allocated
for it, because the size was not specified. He is likely to be over-writing
other RAM locations.
Crying or Very sad Crying or Very sad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 24, 2009 9:55 pm     Reply with quote

Are you running this test in actual hardware or are you running it in
Proteus or ISIS or something like that ?
karthickiw



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

View user's profile Send private message Send e-mail

response
PostPosted: Thu Jun 25, 2009 5:50 am     Reply with quote

PCM programmer wrote:
Are you running this test in actual hardware or are you running it in
Proteus or ISIS or something like that ?


im running program in hardware and when i add printf statement like below code means, im get correct output....




Code:

.
.
.
.
.
sprintf(name,"%s","Mettukadai");
write_ext(14*13,name);
delay_ms(100);

sprintf(name,"%s","Vannankattu");
write_ext(15*13,name);
delay_ms(100);

sprintf(name,"%s","Moolakkarai");
write_ext(16*13,name);
delay_ms(100);
printf("%s",name); ---> when add this line, my result is correct.when remove means i get wrong result

sprintf(name,"%s","Sathiramput");
write_ext(17*13,name);
.
.
.
.
.



Code:
Start...Erode
Savitha
PS Park
GH
Sathiyam Hos
Collector of
Kumalan kutt
palayapalaya
Veer Palayam
Sengotampala
Thindal
Thindal medu
Pavalathan p
Veppanpalaya
Mettukadai
Vannankattu
Moolakkarai
Sathiramput --->this is correct result, when remove the printf i get Moolakkarai for this sathiramput
Koorapalayam
Vaaikkalmedu
Maharaja col
Kanthampalay
Police stati
Perundurai


please give correct solution for this probelm.. Crying or Very sad
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Jun 25, 2009 7:06 am     Reply with quote

The text should be printed twice now. Is the second copy (from read_ext)also correct?
karthickiw



Joined: 09 Aug 2007
Posts: 82
Location: TN, India

View user's profile Send private message Send e-mail

thank you
PostPosted: Thu Jun 25, 2009 8:23 am     Reply with quote

FvM wrote:
The text should be printed twice now. Is the second copy (from read_ext)also correct?


Text printed twice time. Second copy also correct.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 25, 2009 1:56 pm     Reply with quote

You said "Thank You". Does that mean the problem is solved ?
Is it working OK ?

If not, then post your compiler version.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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