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 support@ccsinfo.com

ATMEL 24C64 help. Reading and writing block.

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



Joined: 04 Feb 2014
Posts: 9

View user's profile Send private message

ATMEL 24C64 help. Reading and writing block.
PostPosted: Tue Feb 04, 2014 7:17 pm     Reply with quote

ATMEL 24C64 help. Reading and writing block.

THE routine of ccs can not read this memory.
Protocol is different?
Can someone help me.
PIC Simulator IDE works correctly.
Proteus does not work.
In Radware (board) does not work.
Code:

#include <16F876A.H>
#use delay(clock=4000000)
#fuses HS,NOPROTECT,NOWDT,NOBROWNOUT,PUT
//
#define EEPROM_SDA  PIN_C4
#define EEPROM_SCL  PIN_C3
#use I2C(MASTER, SDA=EEPROM_SDA, SCL=EEPROM_SCL,FAST=400000)

#define EEPROM_ADDRESS long int
#define EEPROM_SIZE    4096
#define hi(x)  (*((int8 *)&x+1))

long int count_I2c=0;

#include "Display_v7_0.c"
//             
static char Buffer1[22] = {'A','B','C','D','E','F','G','H','I','J','L','M','N','O','P','Q','R','S','T','U','V','W'};
static char Buffer2[22];
////////////////  EEPROM I2C - ATMEL 24C64 -  Reading and writing block.  ////
void init_ext_eeprom() {
   output_low(eeprom_scl);
   output_high(eeprom_sda);
   delay_ms(200);
}


BOOLEAN ext_eeprom_ready() {
   int1 ack;
   i2c_start();            // If the write command is acknowledged,
   ack = i2c_write(0xa0);  // then the device is ready.
   i2c_stop();
   return !ack;
}
//////////////// 
void page_write_ext_eeprom(int pagina,long int address, char *data)
{
   int i;

   i2c_start();
   i2c_write(0xa0);
   i2c_write((address>>8)&0x1f);
   i2c_write(address);
    for (i=0 ; i< pagina ; ++i) { 
      i2c_write(*data++);
     // delay_ms(5);
      }
   i2c_stop();
   delay_ms(15);
}
//
void read_bloc_eeprom(long address,int n_data) {
int data,n;
data=0;
   i2c_start();
   i2c_write(0xA0);       // Commande d'ecriture
   i2c_write((address>>8)&0x1f);
   i2c_write(address);     // Adresse, poids faible
   i2c_start(); 
   i2c_write(0xA1);       // Commande de lecture
   
   for (n=0;n<n_data;n++)
   {
      Buffer2[n] = i2c_read(0);
   }
   i2c_stop();
   delay_ms(15);

///////////////////  CCS  //////////////////////////
void write_ext_eeprom(long int address, BYTE data)
{
   short int status;
   i2c_start();
   i2c_write(0xa0);
   i2c_write((address>>8)&0x1f);
   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(hi(address));
   i2c_write(address);
   i2c_start();
   i2c_write(0xa1);
   data=i2c_read(0);
   i2c_stop();
   return(data);
}

///////////////////////////////////////////////////////
void main(void) {
int8 n;
  lcd_init();
  count_I2c=0;
  init_ext_eeprom();
  page_write_ext_eeprom(22,count_I2c,&Buffer1);


         
lcd_putc("\f");

count_I2c=0;
read_bloc_eeprom(count_I2c,15);
     for (n=0;n<15;n++)
     {
     lcd_putc(Buffer2[n]);
     }


  while(TRUE);;
 
       
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Feb 04, 2014 8:45 pm     Reply with quote

Your routines have many things wrong. Study the routines in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=17787


Edit:
azand1 PM'ed me that his problem is solved.
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