piymoon
Newbie level 3
- Joined
- Sep 16, 2013
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 76
hello,
i'm beginner in this, so plz heeelllllllpppp me .... for "programming to 24c04 with 89c52 in read mode specially; i wants write many values of integer n read continuously ....i m totally confused how to use eeprom in my programming .....i hav attached my prog sample.....plz help me ....this is my last hope....:sad::sad::sad::sad::sad::sad::sad:
in my prog ....i wants to write ...kv, mas, macontrol, timer 's value n read these all value......
prog...here=======>>>
#include <regx51.h>
#include <intrins.h>
sbit scl = P3^1;
sbit sda = P3^0;
sbit D0 = P0^0;
sbit D1 = P0^1;
sbit D2 = P0^2;
sbit D3 = P0^3;
sbit D4 = P0^4;
sbit D5 = P0^5;
sbit D6 = P0^6;
sbit D7 = P0^7;
//Keypad Connections
sbit R1 = P1^0;
sbit R2 = P1^1;
sbit R3 = P1^2;
sbit C1 = P1^3;
sbit C2 = P1^4;
sbit C3 = P1^5;
sbit G1 = P2^4;
sbit G2 = P2^5;
sbit G3 = P2^6;
sbit G4 = P2^7;
sbit gnd = P3^6;
int unit, ten, hundred, thousand, mast, kvpt,kvpp;
int i,j,q;
int count=2;
int kv=40;
int t = 0;
int ma = 1;
int w = 0;
int timert;
//void Dis(int);
void display (int);
void digit (int);
void bcd(int o);
//void timer3(int);
//void maled(int);
void clockcntl(int);
char mas(void);
//char kvp(void);
//char macontrol(void);
//char timercal(void);
char Read_Keypad();
void Delay(unsigned char ms)
{
int i,j;
for(i=0;i<=ms;i++)
for(j=0;j<=1275;j++);
}
void sta()
{
sda = 1;
scl = 1;
_nop_();
sda = 0;
_nop_();
scl = 0;
}
void stop()
{
sda = 0;
scl = 1;
Delay(15);
sda = 1;
Delay(10);
}
void ack()
{
sda = 1;
scl = 1;
F0 = 0;
if(sda == 0)
F0 = 1;
scl = 0;
_nop_();
}
void mack()
{
sda = 0;
scl = 1;
_nop_();
scl = 0;
}
void mnack()
{
sda = 1;
scl = 1;
_nop_();
scl = 0;
}
char rdata()
{
unsigned char nn=0xff,mm=0x80,uu=0x7f;
char j;
sda=1;
for(j=0;j<8;j++)
{
scl=1;
if(sda==0)
{nn=(nn&uu);}
else
{nn=(nn|mm);}
nn=_crol_(nn,1);
scl=0;
}
return(nn);
}
char rdata1()
{
unsigned char nn=0xff,mm1=0x80,uu=0x7f;
char j;
sda=1;
for(j=0;j<8;j++)
{
scl=1;
if(sda==0)
{nn=(nn&uu);}
else
{nn=(nn|mm1);}
nn=_crol_(nn,1);
scl=0;
}
return(nn);
}
void wdata1(unsigned char dat)
{
int k;
for(k = 0;k<=7;k++)
{
if((dat & 0x80) > 0)
{
sda = 1;
scl = 1;
_nop_();
scl = 0;
sda = 0;
}
else
{
sda = 0;
scl = 1;
_nop_();
scl = 0;
}
dat = dat << 1;
}
ack();
}
void wdata(unsigned char dat)
{
int k;
for(k = 0;k<=7;k++)
{
if((dat & 0x80) > 0)
{
sda = 1;
scl = 1;
_nop_();
scl = 0;
sda = 0;
}
else
{
sda = 0;
scl = 1;
_nop_();
scl = 0;
}
dat = dat << 1;
}
ack();
}
char rdata2()
{
unsigned char nn=0xff,mm1=0x80,uu=0x7f;
char j;
sda=1;
for(j=0;j<8;j++)
{
scl=1;
if(sda==0)
{nn=(nn&uu);}
else
{nn=(nn|mm1);}
nn=_crol_(nn,1);
scl=0;
}
return(nn);
}
void wdata2(unsigned char dat)
{
int k;
for(k = 0;k<=7;k++)
{
if((dat & 0x80) > 0)
{
sda = 1;
scl = 1;
_nop_();
scl = 0;
sda = 0;
}
else
{
sda = 0;
scl = 1;
_nop_();
scl = 0;
}
dat = dat << 1;
}
ack();
}
/////////////////////////////kaypad/////////////////////////////////////////////
char Read_Keypad()
{
C1=1;
C2=1;
C3=1;
R1=0;
R2=0;
R3=0;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=1;
R2=0;
R3=0;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=0;
R2=1;
R3=0;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=1;
R2=1;
R3=0;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=0;
R2=0;
R3=1;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=1;
R2=0;
R3=1;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=0;
R2=1;
R3=1;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=1;
R2=1;
R3=1;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
return 1;
}
/////////////////////////////end read keypad//////////////////////////////
void main()
{
// int i,j;
P1 = 0xFF;
gnd = 0;
while(1){
if(t==0)
{
display(count);
t = t+1;
}
Read_Keypad();
mas();
}
}
///////////////////////////////////////////mas//////////////////////////////////
char mas(void){
//
// i = count;
// display(i);
if(C1==0 && C2==1 && C3==1 && R1==0 && R2==0 && R3==0)
{
count++;
if(count < 250){
i = count;
display(i);
}
else{
count = 250;
i = count;
display(i);
}
}
if(C1==1 && C2==0 && C3==1 && R1==1 && R2==1 && R3==0){
count--;
if(count > 2){
i = count;
display(i);
}
else{
count = 2;
i = count;
display(i);
}
}
if(C1==1 && C2==0 && C3==1 && R1==0 && R2==1 && R3==1){
count = count + 10;
if(count < 250){
i = count;
display(i);
}
else{
count = 250;
i = count;
display(i);
}
}
if(C1==1 && C2==0 && C3==1 && R1==0 && R2==0 && R3==0){
count = count - 10;
if(count > 2){
i = count;
display(i);
}
else{
count = 2;
i = count;
display(i);
}
}
//mast = count;
return 1;
}
/////////////////////////////////////end mas///////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void display(int d)
{
int rd1=0,rd2,rd3,rd4;
int temp;
temp = d/10;
unit = d%10;
ten = temp%10;
temp = temp/10;
hundred = temp%10;
sta(); // start connection
wdata(0xa0); // write command to I2C
ack();
wdata(0x06); // selecting address
ack();
wdata(hundred); // writing data to I2C
mnack(); // selecting address
wdata(ten); // writing data to I2C
mnack(); // selecting address
wdata(unit); // writing data to I2C
mnack();
//stop();
// stop();
stop();
sta();
wdata(0xa0);
wdata(0x06);
sta();
wdata(0xa1); // reading command to I2C
// for(j=0;j<81;j++)
// {
rd1 = rdata();
mack();
rd2 = rdata();
mack();
rd3 = rdata();
mack();
// }
mnack();
stop();
digit (rd1);
bcd (2);
clockcntl(3);
Delay(1);
clockcntl(0);
bcd (11);
//Delay(1);
// }
// mnack();
// stop();
//digit (rd1);
// c1 = 0;
// sta();
// wdata(0xa0);
/// wdata(0x07);
// sta();
// wdata(0xa1); // reading command to I2C
/// for(j=0;j<8;j++)
// {
digit (rd2);
bcd (1);
clockcntl(3);
Delay(1);
clockcntl(0);
bcd (11);
// Delay(1);
// }
// mnack();
// stop();
//digit (rd2);
//c2 = 0;
// sta();
// wdata(0xa0);
//wdata(0x08);
// sta();
// wdata(0xa1); // reading command to I2C
// for(j=0;j<8;j++)
// {
digit (rd3);
bcd (0);
clockcntl(3);
Delay(1);
clockcntl(0);
bcd (0);
Delay(11);
//digit(rd3);
//digit (hundred);
// c3 = 0;
}
///////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void bcd(int o)
{
switch(o)
{
case 1: D4=0; D5=0; D6=0; D7=0;
break;
case 2: D4=1; D5=0; D6=0; D7=0;
break;
case 3: D4=0; D5=1; D6=0; D7=0;
break;
case 4: D4=1; D5=1; D6=0; D7=0;
break;
case 5: D4=0; D5=0; D6=1; D7=0;
break;
case 6: D4=1; D5=0; D6=1; D7=0;
break;
case 7: D4=0; D5=1; D6=1; D7=0;
break;
case 8: D4=1; D5=1; D6=1; D7=0;
break;
case 9: D4=0; D5=0; D6=0; D7=1;
break;
case 10: D4=1; D5=0; D6=0; D7=1;
break;
case 11: D4=0; D5=1; D6=0; D7=1;
break;
}
}
///////////////////////////////////////////////////////////////////////////////
void digit(int k)
{
switch(k)
{
case 0: D0=0; D1=0; D2=0; D3=0;
break;
case 1: D0=1; D1=0; D2=0; D3=0;
break;
case 2: D0=0; D1=1; D2=0; D3=0;
break;
case 3: D0=1; D1=1; D2=0; D3=0;
break;
case 4: D0=0; D1=0; D2=1; D3=0;
break;
case 5: D0=1; D1=0; D2=1; D3=0;
break;
case 6: D0=0; D1=1; D2=1; D3=0;
break;
case 7: D0=1; D1=1; D2=1; D3=0;
break;
case 8: D0=0; D1=0; D2=0; D3=1;
break;
case 9: D0=1; D1=0; D2=0; D3=1;
break;
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////clock control///////////////////////////////
void clockcntl(int C)
{
switch(C)
{
case 0: G1=0; G2=0; G3=0; G4=1;
break;
case 1: G1=1; G2=0; G3=0; G4=1;
break;
case 2: G1=0; G2=1; G3=0; G4=0;
break;
case 3: G1=1; G2=1; G3=0; G4=1;
break;
case 4: G1=0; G2=0; G3=1; G4=0;
break;
case 5: G1=1; G2=0; G3=1; G4=1;
break;
case 6: G1=0; G2=1; G3=1; G4=0;
break;
case 7: G1=1; G2=1; G3=1; G4=1;
break;
case 9: G1=0; G2=0; G3=0; G4=1;
break;
}
}
/////////////////////////////////End clock control/////////////////////////////
i'm beginner in this, so plz heeelllllllpppp me .... for "programming to 24c04 with 89c52 in read mode specially; i wants write many values of integer n read continuously ....i m totally confused how to use eeprom in my programming .....i hav attached my prog sample.....plz help me ....this is my last hope....:sad::sad::sad::sad::sad::sad::sad:
in my prog ....i wants to write ...kv, mas, macontrol, timer 's value n read these all value......
prog...here=======>>>
#include <regx51.h>
#include <intrins.h>
sbit scl = P3^1;
sbit sda = P3^0;
sbit D0 = P0^0;
sbit D1 = P0^1;
sbit D2 = P0^2;
sbit D3 = P0^3;
sbit D4 = P0^4;
sbit D5 = P0^5;
sbit D6 = P0^6;
sbit D7 = P0^7;
//Keypad Connections
sbit R1 = P1^0;
sbit R2 = P1^1;
sbit R3 = P1^2;
sbit C1 = P1^3;
sbit C2 = P1^4;
sbit C3 = P1^5;
sbit G1 = P2^4;
sbit G2 = P2^5;
sbit G3 = P2^6;
sbit G4 = P2^7;
sbit gnd = P3^6;
int unit, ten, hundred, thousand, mast, kvpt,kvpp;
int i,j,q;
int count=2;
int kv=40;
int t = 0;
int ma = 1;
int w = 0;
int timert;
//void Dis(int);
void display (int);
void digit (int);
void bcd(int o);
//void timer3(int);
//void maled(int);
void clockcntl(int);
char mas(void);
//char kvp(void);
//char macontrol(void);
//char timercal(void);
char Read_Keypad();
void Delay(unsigned char ms)
{
int i,j;
for(i=0;i<=ms;i++)
for(j=0;j<=1275;j++);
}
void sta()
{
sda = 1;
scl = 1;
_nop_();
sda = 0;
_nop_();
scl = 0;
}
void stop()
{
sda = 0;
scl = 1;
Delay(15);
sda = 1;
Delay(10);
}
void ack()
{
sda = 1;
scl = 1;
F0 = 0;
if(sda == 0)
F0 = 1;
scl = 0;
_nop_();
}
void mack()
{
sda = 0;
scl = 1;
_nop_();
scl = 0;
}
void mnack()
{
sda = 1;
scl = 1;
_nop_();
scl = 0;
}
char rdata()
{
unsigned char nn=0xff,mm=0x80,uu=0x7f;
char j;
sda=1;
for(j=0;j<8;j++)
{
scl=1;
if(sda==0)
{nn=(nn&uu);}
else
{nn=(nn|mm);}
nn=_crol_(nn,1);
scl=0;
}
return(nn);
}
char rdata1()
{
unsigned char nn=0xff,mm1=0x80,uu=0x7f;
char j;
sda=1;
for(j=0;j<8;j++)
{
scl=1;
if(sda==0)
{nn=(nn&uu);}
else
{nn=(nn|mm1);}
nn=_crol_(nn,1);
scl=0;
}
return(nn);
}
void wdata1(unsigned char dat)
{
int k;
for(k = 0;k<=7;k++)
{
if((dat & 0x80) > 0)
{
sda = 1;
scl = 1;
_nop_();
scl = 0;
sda = 0;
}
else
{
sda = 0;
scl = 1;
_nop_();
scl = 0;
}
dat = dat << 1;
}
ack();
}
void wdata(unsigned char dat)
{
int k;
for(k = 0;k<=7;k++)
{
if((dat & 0x80) > 0)
{
sda = 1;
scl = 1;
_nop_();
scl = 0;
sda = 0;
}
else
{
sda = 0;
scl = 1;
_nop_();
scl = 0;
}
dat = dat << 1;
}
ack();
}
char rdata2()
{
unsigned char nn=0xff,mm1=0x80,uu=0x7f;
char j;
sda=1;
for(j=0;j<8;j++)
{
scl=1;
if(sda==0)
{nn=(nn&uu);}
else
{nn=(nn|mm1);}
nn=_crol_(nn,1);
scl=0;
}
return(nn);
}
void wdata2(unsigned char dat)
{
int k;
for(k = 0;k<=7;k++)
{
if((dat & 0x80) > 0)
{
sda = 1;
scl = 1;
_nop_();
scl = 0;
sda = 0;
}
else
{
sda = 0;
scl = 1;
_nop_();
scl = 0;
}
dat = dat << 1;
}
ack();
}
/////////////////////////////kaypad/////////////////////////////////////////////
char Read_Keypad()
{
C1=1;
C2=1;
C3=1;
R1=0;
R2=0;
R3=0;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=1;
R2=0;
R3=0;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=0;
R2=1;
R3=0;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=1;
R2=1;
R3=0;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=0;
R2=0;
R3=1;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=1;
R2=0;
R3=1;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=0;
R2=1;
R3=1;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
R1=1;
R2=1;
R3=1;
if(C1==0){Delay(10);return 1;}
if(C2==0){Delay(10);return 1;}
if(C3==0){Delay(10);return 1;}
return 1;
}
/////////////////////////////end read keypad//////////////////////////////
void main()
{
// int i,j;
P1 = 0xFF;
gnd = 0;
while(1){
if(t==0)
{
display(count);
t = t+1;
}
Read_Keypad();
mas();
}
}
///////////////////////////////////////////mas//////////////////////////////////
char mas(void){
//
// i = count;
// display(i);
if(C1==0 && C2==1 && C3==1 && R1==0 && R2==0 && R3==0)
{
count++;
if(count < 250){
i = count;
display(i);
}
else{
count = 250;
i = count;
display(i);
}
}
if(C1==1 && C2==0 && C3==1 && R1==1 && R2==1 && R3==0){
count--;
if(count > 2){
i = count;
display(i);
}
else{
count = 2;
i = count;
display(i);
}
}
if(C1==1 && C2==0 && C3==1 && R1==0 && R2==1 && R3==1){
count = count + 10;
if(count < 250){
i = count;
display(i);
}
else{
count = 250;
i = count;
display(i);
}
}
if(C1==1 && C2==0 && C3==1 && R1==0 && R2==0 && R3==0){
count = count - 10;
if(count > 2){
i = count;
display(i);
}
else{
count = 2;
i = count;
display(i);
}
}
//mast = count;
return 1;
}
/////////////////////////////////////end mas///////////////////////////////////
////////////////////////////////////////////////////////////////////////////
void display(int d)
{
int rd1=0,rd2,rd3,rd4;
int temp;
temp = d/10;
unit = d%10;
ten = temp%10;
temp = temp/10;
hundred = temp%10;
sta(); // start connection
wdata(0xa0); // write command to I2C
ack();
wdata(0x06); // selecting address
ack();
wdata(hundred); // writing data to I2C
mnack(); // selecting address
wdata(ten); // writing data to I2C
mnack(); // selecting address
wdata(unit); // writing data to I2C
mnack();
//stop();
// stop();
stop();
sta();
wdata(0xa0);
wdata(0x06);
sta();
wdata(0xa1); // reading command to I2C
// for(j=0;j<81;j++)
// {
rd1 = rdata();
mack();
rd2 = rdata();
mack();
rd3 = rdata();
mack();
// }
mnack();
stop();
digit (rd1);
bcd (2);
clockcntl(3);
Delay(1);
clockcntl(0);
bcd (11);
//Delay(1);
// }
// mnack();
// stop();
//digit (rd1);
// c1 = 0;
// sta();
// wdata(0xa0);
/// wdata(0x07);
// sta();
// wdata(0xa1); // reading command to I2C
/// for(j=0;j<8;j++)
// {
digit (rd2);
bcd (1);
clockcntl(3);
Delay(1);
clockcntl(0);
bcd (11);
// Delay(1);
// }
// mnack();
// stop();
//digit (rd2);
//c2 = 0;
// sta();
// wdata(0xa0);
//wdata(0x08);
// sta();
// wdata(0xa1); // reading command to I2C
// for(j=0;j<8;j++)
// {
digit (rd3);
bcd (0);
clockcntl(3);
Delay(1);
clockcntl(0);
bcd (0);
Delay(11);
//digit(rd3);
//digit (hundred);
// c3 = 0;
}
///////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
void bcd(int o)
{
switch(o)
{
case 1: D4=0; D5=0; D6=0; D7=0;
break;
case 2: D4=1; D5=0; D6=0; D7=0;
break;
case 3: D4=0; D5=1; D6=0; D7=0;
break;
case 4: D4=1; D5=1; D6=0; D7=0;
break;
case 5: D4=0; D5=0; D6=1; D7=0;
break;
case 6: D4=1; D5=0; D6=1; D7=0;
break;
case 7: D4=0; D5=1; D6=1; D7=0;
break;
case 8: D4=1; D5=1; D6=1; D7=0;
break;
case 9: D4=0; D5=0; D6=0; D7=1;
break;
case 10: D4=1; D5=0; D6=0; D7=1;
break;
case 11: D4=0; D5=1; D6=0; D7=1;
break;
}
}
///////////////////////////////////////////////////////////////////////////////
void digit(int k)
{
switch(k)
{
case 0: D0=0; D1=0; D2=0; D3=0;
break;
case 1: D0=1; D1=0; D2=0; D3=0;
break;
case 2: D0=0; D1=1; D2=0; D3=0;
break;
case 3: D0=1; D1=1; D2=0; D3=0;
break;
case 4: D0=0; D1=0; D2=1; D3=0;
break;
case 5: D0=1; D1=0; D2=1; D3=0;
break;
case 6: D0=0; D1=1; D2=1; D3=0;
break;
case 7: D0=1; D1=1; D2=1; D3=0;
break;
case 8: D0=0; D1=0; D2=0; D3=1;
break;
case 9: D0=1; D1=0; D2=0; D3=1;
break;
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////clock control///////////////////////////////
void clockcntl(int C)
{
switch(C)
{
case 0: G1=0; G2=0; G3=0; G4=1;
break;
case 1: G1=1; G2=0; G3=0; G4=1;
break;
case 2: G1=0; G2=1; G3=0; G4=0;
break;
case 3: G1=1; G2=1; G3=0; G4=1;
break;
case 4: G1=0; G2=0; G3=1; G4=0;
break;
case 5: G1=1; G2=0; G3=1; G4=1;
break;
case 6: G1=0; G2=1; G3=1; G4=0;
break;
case 7: G1=1; G2=1; G3=1; G4=1;
break;
case 9: G1=0; G2=0; G3=0; G4=1;
break;
}
}
/////////////////////////////////End clock control/////////////////////////////