Ich arbeite an EEPROM AT24C16 für ein bestimmtes Projekt. Laut Datenblatt muss es 2048 Adressen haben und ich sollte 1024 unsigned int hineinschreiben können [1 unsigned int pro 2 Adressen], aber ich kann nur 128 unsigned ints auf 256 Adressen schreiben.
Ist mein EEPROM doppelt oder ich bin verwirrt und es hat nur 256 Adressen. Bitte helfen Sie mir, die Anzahl der Adressen in AT24C16 herauszufinden.
Code:
#include<p18f4520.h>
#include<i2c.h> // Required For In-built I2C Routine
#pragma config OSC = HS /* Sets the oscillator mode HS */
#pragma config WDT = OFF /* Turns the watchdog timer off */
#pragma config LVP = OFF /* Turns low voltage programming off */
#define LCD_PORT LATB
#define LCD_EN LATDbits.LATD7
#define LCD_RS LATDbits.LATD6
#define ADDRESS 0xA0
#define LCD_PORT_DIR TRISB
#define LCD_EN_DIR TRISDbits.TRISD7
#define LCD_RS_DIR TRISDbits.TRISD6
#define I2C_SCL TRISCbits.TRISC3
#define I2C_SDA TRISCbits.TRISC4
#define AddressU 0
#define AddressL 1
int TempUpper, TempLower;
long int TempValue;
int TempUpper1, TempLower1;
long int TempValue1;
void DelayMS(unsigned int);
void init_lcd();
void command();
void lcd_data(unsigned char);
void Init_MSSP_I2C();
void DelayMS(unsigned int itime) {
unsigned int i;
unsigned char j;
for (i = 0; i < itime; i++)
for (j = 0; j < 165; j++);
}
void command() {
LCD_RS = 0 ;
LCD_EN = 1 ;
DelayMS(1);
LCD_EN = 0 ;
DelayMS(1);
}
void lcd_data(unsigned char dat) {
LCD_PORT = dat ;
LCD_RS = 1 ;
LCD_EN = 1 ;
LCD_EN = 0 ;
DelayMS(1);
}
void init_lcd() {
LCD_PORT = 0x38 ; //LCD 2 Lines
command();
LCD_PORT = 0x0E; //Display On,Cursor On
command();
LCD_PORT = 0x01; // Clear LCD
command();
LCD_PORT = 0x06; //Shift Cursor right
command();
LCD_PORT = 0x80; //line 1, position 1
command();
}
void lcd_string(char rom *str) {
while (*str)
{ lcd_data(*str++); }
DelayMS(1);
}
void Init_MSSP_I2C() {
I2C_SCL = 1 ; // Initilize MSSP For I2C Send Write '1' RC3/SCL
I2C_SDA = 1 ; // Initilize MSSP For I2C Send Write '1' RC4/SDA
OpenI2C(MASTER, SLEW_OFF) ; // Start I2C Stop I2C
SSPADD = 0x18 ;
}
unsigned int e, th, h, t, o, c = 0, g = 0, temp, tempvalue, fu, add = 0, mv = 0;
void main(void) {
Init_MSSP_I2C();
LCD_RS_DIR = 0 ;
LCD_EN_DIR = 0 ;
LCD_PORT_DIR = 0 ;
DelayMS(250); // Wait on Intilization LCD
init_lcd();
lcd_string((rom char *)"Testing 24C02.. "); // DPTR in 8051 AS
TempValue = mv;
add = 0;
while (add < 512) {
TempUpper1 = (TempValue >> 8) & 0x00FF;
TempLower1 = (TempValue & 0x00FF);
EEByteWrite(ADDRESS, add, TempUpper1);
DelayMS(10);
EEByteWrite(ADDRESS, add + 1, TempLower1);
DelayMS(10);
TempValue = TempValue + 1;
add = add + 2;
}
init_lcd();
lcd_string((rom char *)"END ");
while (1);
while (add < 512) {
TempUpper = EERandomRead(ADDRESS, add);
TempLower = EERandomRead(ADDRESS, add + 1);
DelayMS(10);
add = add + 2;
TempValue = 0x0000;
TempValue = TempUpper;
TempValue = TempValue << 8;
TempValue = TempValue | TempLower;
DelayMS(50);
g = TempValue;
fu = g / 10000; // gets 1000's value of number to Segments[1]
temp = g % 10000;
th = temp / 1000; // gets 1000's value of number to Segments[2]
temp = temp % 1000;
h = temp / 100; // gets 100's of number value to Segments[3]
temp = temp % 100;
t = temp / 10; // gets 10's value of number to Segments[4]
o = temp % 10; // gets 1's value of number to Segments[5]
LCD_PORT = 0xc2; //line 1, position 1
command();
lcd_data(fu | 0x30) ;
LCD_PORT = 0xc3; //line 1, position 1
command();
lcd_data(th | 0x30) ;
LCD_PORT = 0xc4; //line 1, position 1
command();
lcd_data(h | 0x30) ;
LCD_PORT = 0xc5; //line 1, position 2
command();
lcd_data(t | 0x30) ;
LCD_PORT = 0xc6; //line 1, position 3
command();
lcd_data(o | 0x30) ;
DelayMS(1000);
}
while (1);
}
Das Problem hier liegt eigentlich bei der I2C-Peripheriebibliothek, nicht bei Ihrem Code.
Die EEByteWrite
Funktion ist definiert als:
signed char EEByteWrite1( unsigned char control,
unsigned char address,
unsigned char data );
#define EEByteWrite EEByteWrite1
Wie Sie sehen können, ist der Adressparameter ein, unsigned char
was bedeutet, dass er nur Werte bis 255 akzeptieren kann. Das ist die Grenze, die Sie erreichen.
Die EERandomRead
Funktion ist ähnlich definiert.
Die eingebauten EEByte*
Funktionen plib
sind für nichts anderes als kleine EEPROMs mit bis zu 256 Adressen geeignet.
Um auf mehr als 256 Adressen zuzugreifen, müssen Sie Ihre eigenen Routinen schreiben, die den Zielchip entsprechend steuern.
Roger Rowland
prog_SAHIL
Roger Rowland
Nick Johnson
prog_SAHIL
Russell McMahon
Russell McMahon
Russell McMahon
Roger Rowland
Russell McMahon
Roger Rowland
Russell McMahon
Roger Rowland
prog_SAHIL
prog_SAHIL