incorrect external eeprom data is displayed...help the error..

Status
Not open for further replies.

jaya krishna

Member level 1
Joined
May 10, 2012
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
India,coimbatore
Activity points
1,770
any body help for my problem....eeprom cannot write and read the exact value....
PHP:
#include <16F877a.H> 
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP 
#use delay (clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS) 
#use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW)


#define EEPROM_SDA  PIN_C4 
#define EEPROM_SCL  PIN_C3 
#include <24256.c> 


#define rs PIN_C0
#define rw PIN_C1
#define en PIN_C2

 void lcdcmd(unsigned char cmd);
 void lcddata(unsigned char volt);
 void lcddata1(char *dat);
 init_ext_eeprom(); 
 
 
char line1[]= {"Hello World"}; 

//================================= 
void main() 
{ 
    int8 i; 
    int8 buff=0,buffer[17]; 
    set_tris_b(0x00);
   


    //set_tris_c(0xF8);
    lcdcmd(0x38);
    lcdcmd(0x0E);
    lcdcmd(0x01);
    lcdcmd(0x06);
    lcdcmd(0x80);

while(1)
{ 
// Write "Hello World" to external eeprom chip. 
for(i = 0; i <= 10; i++) 

    write_ext_eeprom(i, line1[i]); 
   // a= line1[i];
    //printf("%c",a);

// Read characters from the external eeprom chip 
// and write them into a RAM buffer. 
for(i = 0; i <=10; i++) 
    buffer[i] = read_ext_eeprom(i); 
   buff = buffer[i];
    lcddata(buff+0x30);
   
// lcddata(buffer[i]);
// Display the message on the LCD. 
//printf(lcd_putc, buffer); 

}

}


void lcdcmd(unsigned char cmd)
              

{
  output_b(cmd);
  output_low(rs);
  output_low(rw);
  output_high(en);
  delay_ms(1);
  output_low(en);
  
}

void lcddata(unsigned char volt)

{
  output_b(volt);
  output_high(rs);
  output_low(rw);
  output_high(en);
  delay_ms(1);
  output_low(en);
}

void lcddata1(char *dat)
 {
    
    output_high(rs);
    for(;*dat!='\0';*dat++)
      lcddata(*dat);   
   
 }
24256.c
PHP:
///////////////////////////////////////////////////////////////////////////
////   Library for a 24LC256 serial EEPROM                             ////
////                                                                   ////
////   init_ext_eeprom();    Call before the other functions are used  ////
////                                                                   ////
////   write_ext_eeprom(a, d);  Write the byte d to the address a      ////
////                                                                   ////
////   d = read_ext_eeprom(a);   Read the byte d from the address a    ////
////                                                                   ////
////   The main program may define eeprom_sda                          ////
////   and eeprom_scl to override the defaults below.                  ////
////                                                                   ////
///////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,2003 Custom Computer Services           ////
//// This source code may only be used by licensed users of the CCS C  ////
//// compiler.  This source code may only be distributed to other      ////
//// licensed users of the CCS C compiler.  No other use, reproduction ////
//// or distribution is permitted without written permission.          ////
//// Derivative programs created using this software in object code    ////
//// form are not restricted in any way.                               ////
///////////////////////////////////////////////////////////////////////////


#ifndef EEPROM_SDA

#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3

#endif

#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)

#define EEPROM_ADDRESS long int
#define EEPROM_SIZE   32768

void init_ext_eeprom()
{
   output_float(EEPROM_SCL);
   output_float(EEPROM_SDA);

}


void write_ext_eeprom(long int address , BYTE data)
{
   short int status;
   i2c_start();
   i2c_write(0xa0);
   i2c_write(address>>8);
   i2c_write(address);
   i2c_write(data);
   i2c_stop();
   i2c_start();
   status=i2c_write(0xa0);
   while(status==1)
   {
   i2c_start();
   status=i2c_write(0xa0);
   }
   i2c_stop();
}


BYTE read_ext_eeprom(long int address) {
   BYTE data;
   i2c_start();
   i2c_write(0xa0);
   i2c_write(address>>8);
   i2c_write(address);
   i2c_start();
   i2c_write(0xa1);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}



it display on lcd is 0 0 0 0 but it should display hello world

- - - Updated - - -

hi every one ,now i get string first character, but value cannot be increment, it display h h h ...but i need to display the Hello world....by using eeprom i2c....
PHP:
#include <16F877a.H> 
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP 
#use delay (clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS) 
#use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW)


#define EEPROM_SDA  PIN_C4 
#define EEPROM_SCL  PIN_C3 
#include <24256.c> 


#define rs PIN_C0
#define rw PIN_C1
#define en PIN_C2

 void lcdcmd(unsigned char cmd);
 void lcddata(unsigned char volt);

 init_ext_eeprom(); 
 
 
char line1[]= {"Hello world"}; 

 
void main() 
{ 
    int8 i; 
    int8 buff=0,buffer[10]; 
    set_tris_b(0x00);
   


    //set_tris_c(0xF8);
    lcdcmd(0x38);
    lcdcmd(0x0E);
    lcdcmd(0x01);
    lcdcmd(0x06);
    lcdcmd(0x80);

while(1)
{ 
// Write "Hello World" to external eeprom chip. 
for(i = 0; i <10; i++) 
{

    write_ext_eeprom(i,line1[i]); 
   
 

// Read characters from the external eeprom chip 
// and write them into a RAM buffer. 
for(i = 0; i <10; i++) 
    buffer[i] = read_ext_eeprom(i);
    buff = buffer[i];
    lcddata(buff+0x30);
}


}

}


void lcdcmd(unsigned char cmd)
              

{
  output_b(cmd);
  output_low(rs);
  output_low(rw);
  output_high(en);
  delay_ms(1);
  output_low(en);
  
}

void lcddata(unsigned char volt)

{
  output_b(volt);
  output_high(rs);
  output_low(rw);
  output_high(en);
  delay_ms(1);
  output_low(en);
}


 [PHP]
24256
#include <16F877a.H>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay (clock=4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use i2c(MASTER, FAST, SCL=PIN_C3, SDA=PIN_C4, FORCE_HW)


#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3
#include <24256.c>


#define rs PIN_C0
#define rw PIN_C1
#define en PIN_C2

void lcdcmd(unsigned char cmd);
void lcddata(unsigned char volt);

init_ext_eeprom();


char line1[]= {"Hello world"};


void main()
{
int8 i;
int8 buff=0,buffer[10];
set_tris_b(0x00);



//set_tris_c(0xF8);
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);

while(1)
{
// Write "Hello World" to external eeprom chip.
for(i = 0; i <10; i++)
{

write_ext_eeprom(i,line1);



// Read characters from the external eeprom chip
// and write them into a RAM buffer.
for(i = 0; i <10; i++)
buffer = read_ext_eeprom(i);
buff = buffer;
lcddata(buff+0x30);
}


}

}


void lcdcmd(unsigned char cmd)


{
output_b(cmd);
output_low(rs);
output_low(rw);
output_high(en);
delay_ms(1);
output_low(en);

}

void lcddata(unsigned char volt)

{
output_b(volt);
output_high(rs);
output_low(rw);
output_high(en);
delay_ms(1);
output_low(en);
}


[/PHP]


any body help me....
 

Attachments

  • externaleeprom.JPG
    242.7 KB · Views: 92

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…