📄 sim24cxx1.cpp
字号:
//-------------------------simat24xx
//---------getat24xx()
//---------getat24xx()
//---------getat24xx()
//---------getat24xx()
void getat24xx(void)
{
if(at24xxold!=filv[at24xxrb])
{
/////////////
if((at24xxold&at24xxscl1)&&(filv[at24xxrb]&at24xxscl1))
{
if((!(filv[at24xxrb]&at24xxsda1))&&(at24xxold&at24xxsda1))
{
opat24xx=1;
at24xxclk=0;
at24xxdat=0;
}
else if((!(at24xxold&at24xxsda1))&&(filv[at24xxrb]&at24xxsda1))
{
opat24xx=0;
}
}
if(opat24xx0)
{
if((!(at24xxold&at24xxscl1))&&(filv[at24xxrb]&at24xxscl1))
{//0-->1
if(opat24xx03)
{
if(at24xxclk<8)
{
if(at24xxdat&0x80)
{
filv[at24xxrb]|=at24xxsda1;
}
else
{
filv[at24xxrb]&=at24xxsda0;
}
at24xxclk++;
at24xxdat<<=1;
}
else if(at24xxclk==8)
{
if(!opat24xx33)
{
opat24xx33=1;
at24xxdat=at24xx[at24xxaddress];
}
else
{
at24xxdat=at24xx[++at24xxaddress];
}
if((at24xxclk==8)&&(opat24xx1))
{
opat24xx1=0;
filv[at24xxrb]&=at24xxsda0;//ack
}
else
{
filv[at24xxrb]|=at24xxsda1;//noack
}
}
}
else if((at24xxclk==8)&&(opat24xx1))
{
opat24xx1=0;
filv[at24xxrb]&=at24xxsda0;//ack
}
if(at24xxclk>=8)
{//8bits
at24xxclk=0;
}
else if(!opat24xx03)
{
at24xxdat<<=1;
if((filv[at24xxrb]&at24xxsda1))
{
at24xxdat|=0x1;
}
at24xxclk++;
if(at24xxclk==8)
{//8bits
if(!opat24xx00)
{//dat00 is command/device address
if((at24xxdat&0xf0)==0xa0)
{
opat24xx00=1;
if(!(at24xxdat&0x1))
{//wt
opat24xx01=1;
}
else
{//rd
opat24xx03=1;
rdat24xx();
}
opat24xx1=1;//ack
}
}
else
{//dat01;dat02
if(opat24xx01)
{//wt
if(!opat24xx02)
{//word address
opat24xx02=1;
at24xxaddress=at24xxdat;
}
else
{//data
if(!opat24xx22)
{
opat24xx22=1;
at24xx[at24xxaddress]=at24xxdat;
wtat24xx();
}
else
{//data
at24xxaddress++;
at24xx[at24xxaddress]=at24xxdat;
wtat24xx();
}
}
opat24xx1=1;//ack
}
}
}
}
}
}
at24xxold=filv[at24xxrb];
/////////////
}
}
//---------void rdat24xx(char * fln)
//---------void rdat24xx(char * fln)
//---------void rdat24xx(char * fln)
//---------void rdat24xx(char * fln)
void rdat24xx(void)
{
char ccc[47];
int i,j;
int cnt;
int addr;
int lnst;
char ln1[100];
int k;
CFile myFile;
myFile.Open(fat24xx, CFile::modeReadWrite);
if(myFile==-1)
{
myFile.Open(fat24xx, CFile::modeCreate);
if(myFile==-1)
{
fileerr=1;
strcpy(strCFile,"at24xxFile RWrite error!");
return;
}
else
{
myFile.Close();
myFile.Open(fat24xx, CFile::modeReadWrite);
if(myFile==-1)
{
fileerr=1;
strcpy(strCFile,"at24xxFile RWrite error!");
}
return;
}
}
BOOL CCCC=TRUE;
addr=0;
ln1[0]=0;
while(CCCC)
{
if(addr>=2080)
{
addr=addr;
}
for(i=0;i<47;i++)
{
ccc[i]=0;
}
myFile.Read(ccc,46);//10);
i=strlen(ccc);
j=46;
if(i<46)
{
CCCC=FALSE;
if(i>0)
{
j=i;
}
}
strcat(ln1,ccc);
j=strlen(ln1);
lnst=0;
cnt=0;
for(i=0;i<j;i++)
{
if(ln1[i]==13)
{
for(k=0;k<i;k++)
{
lnst++;
if(ln1[k]>=0x61)
{
cnt=cnt*16+ln1[k]-0x57;
}
else if(ln1[k]>=0x41)
{
cnt=cnt*16+ln1[k]-0X37;
}
else if(ln1[k]>=0X30)
{
cnt=cnt*16+ln1[k]-0X30;
}
else
{
cnt=0;
lnst=0;
}
if(lnst==2)
{
at24xx[addr]=cnt;
addr++;
if(addr>=40)
{
CCCC=FALSE;
break;
}
cnt=0;
lnst=0;
}
}
if(CCCC==FALSE)
{
break;
}
for(;k<j;)
{
if(ln1[k++]>=48)
{
break;
}
}
k--;
for(i=0;k<j;)
{
ln1[i++]=ln1[k++];
}
j=i;
ln1[j]=0;
i=0;
}
}
}
myFile.Close();
//wtat24xx();
}
//---------------void wtat24xx(void)
//---------------void wtat24xx(void)
//---------------void wtat24xx(void)
//---------------void wtat24xx(void)
void wtat24xx(void)
{
char ccc[47];
int i,j,k,l;
char ln1[100];
char fin[100];
CFile myFile;
myFile.Open(fat24xx, CFile::modeReadWrite);
if(myFile==-1)
{
fileerr=1;
strcpy(strCFile,"at24xxFile RWrite error!");
return;
}
k=0;
for(i=0;i<3;i++)
{
ln1[0]=0;
if(!i)
{
j=9;
}
else if(i==1)
{
j=16;
}
else
{
j=15;
}
l=j*3;
for(;j;j--)
{
strcpy(ccc,_itoa(at24xx[k++],fin,16));
if(strlen(ccc)==1)
{
strcat(ln1,"0");
}
strcat(ln1,ccc);
strcat(ln1," ");
}
ln1[l++]=13;
ln1[l++]=10;
myFile.Write(ln1,l);
}
myFile.Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -