azand1
Joined: 04 Feb 2014 Posts: 9
|
ATMEL 24C64 help. Reading and writing block. |
Posted: Tue Feb 04, 2014 7:17 pm |
|
|
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);;
} |
|
|