hello , this is a counter program and counter value stored in eeprom, but i have a problem with storage it store only 255 count and rest to 0, i want to store 999999 cunt what to do.
[code]
#include "Wire.h"
#include <LiquidCrystal.h>
#define EEPROM_I2C_ADDRESS 0x50
LiquidCrystal lcd(12,11,5,4,3,2);
int enter =7;
int shift =8;
int inc =9;
int menu=10;
int no=1;
int Key;
int key=1;
int x=0;
byte val = 11;
int address = 0;
byte readVal ;
void setup()
{
lcd.begin(20,4);
Wire.begin();
analogWrite(6,x); //Display intensity
pinMode(enter,INPUT_PULLUP);
pinMode(shift,INPUT_PULLUP);
pinMode(inc,INPUT_PULLUP);
pinMode(menu,INPUT_PULLUP);
byte readVal = readAddress(address);
lcd.setCursor(0,0);
lcd.println("Last count:");
lcd.setCursor(11,1);
lcd.println(readVal);
}
void Key_Scane()
{
bool key_input ;
Key=0;
key_input = digitalRead(enter);
if (key_input==0) {delay(100); if (key_input==0) {Key='E'; return ;}}
key_input = digitalRead(shift);
if (key_input==0) {delay(100); if (key_input==0) {Key='S'; return ;}}
key_input = digitalRead(inc);
if (key_input==0) {delay(100); if (key_input==0) {Key='I'; return ;}}
key_input = digitalRead(menu);
if (key_input==0) {delay(100); if (key_input==0) {Key ='M' ; return ;}}
}
void writeAddress(int address, byte val)
{
Wire.beginTransmission(EEPROM_I2C_ADDRESS);
//Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); //LSB
Wire.write(val);
Wire.endTransmission();
delay(5);
}
byte readAddress(int address)
{
byte rData = 0xFF;
Wire.beginTransmission(EEPROM_I2C_ADDRESS);
// Wire.write((int)(address >> 8)); // MSB
Wire.write((int)(address & 0xFF)); //LSB
Wire.endTransmission();
Wire.requestFrom(EEPROM_I2C_ADDRESS, 1);
rData = Wire.read();
return rData;
}
void loop()
{
while(1)
{Key_Scane();
readVal = readAddress(address);
val=readVal;
if(Key=='I'){ val++;
writeAddress(address, val);
readVal = readAddress(address);
lcd.clear ();
lcd.print("Total Count: ");
lcd.println(readVal);
delay(500);
}}
}
The question is a bit vague. Have you looked on any of the many fine EEPROM tutorials online? Have you tried any of the examples included in your IDE. Have you tried any of the examples; try them they are good.
@mohitnama400 - why did you submit a Report to moderator ?
thank you sir,
sir but i don,t know how break a integer value into 3 or more than 3 byte,
and i want know what is the process to break large number into byte vice versa.
“ sir but i don,t know how break a integer value into 3 or more than 3 byte,
and i want know what is the process to break large number into byte vice versa.”
larryd:
“ sir but i don,t know how break a integer value into 3 or more than 3 byte,
and i want know what is the process to break large number into byte vice versa.”
Do you know the memory is arranged as bytes and you can only read or write one byte at a time. It does not know nor care what the bytes are or what they indicate, that is your softwares job. To save a three byte number you will need to write them in three different locations, typically sequentially but not required.