为什么写iic 的时候读取用中间变量读不出来,比如unsigned char i,用 i = at24c02_writebyte(0x00,1)就不能显示出正确的数值
void main()
{
unsigned char i = 0;
P2 = 0xa0;
P0 = 0x00;
P2 = 0x00;
P2 = 0x80;
P0 = 0xff;
P2 = 0x00;
i = at24c02_writebyte(0x00,1);
Delay(200);
while(1)
{
DisplaySMG_Bit(0x01,SMGNoDot_CA[i]);
Delay(10);
}
}
但是如果不用i这个中间变量就可以
```c
void main()
{
P2 = 0xa0;
wanzheng P0 = 0x00;
P2 = 0x00;
P2 = 0x80;
P0 = 0xff;
P2 = 0x00;
at24c02_writebyte(0x00,1);
Delay(200);
while(1)
{
DisplaySMG_Bit(0x01,SMGNoDot_CA[AT24C02_Readbyte(0x00)]);
Delay(10);
}
}
但是如果不用i这个中间变量就可以
```c
#include "reg52.h"
#include "iic.h"
#define AT24C02_ADD 0xa0
unsigned char SMGNoDot_CA[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void Delay(unsigned int t)
{
while(t--);
}
//================
void DisplaySMG_Bit(unsigned char pos ,unsigned char value)
{
P2 = 0xc0;
P0 = pos;
P2 = 0xe0;
P0 = value;
}
//================
void at24c02_writebyte(unsigned char dizhi,unsigned char shuzhi)
{
IIC_Start();
IIC_SendByte(AT24C02_ADD);
IIC_WaitAck();
IIC_SendByte(dizhi);
IIC_WaitAck();
IIC_SendByte(shuzhi);
IIC_WaitAck();
IIC_Stop();
}
unsigned char AT24C02_Readbyte(unsigned char dizhi)
{
unsigned char Data;
IIC_Start();
IIC_SendByte(AT24C02_ADD);
IIC_WaitAck();
IIC_SendByte(dizhi);
IIC_WaitAck();
IIC_Start();
IIC_SendByte(AT24C02_ADD | 0x01);
IIC_WaitAck();
Data = IIC_RecByte();
IIC_SendAck(1);
IIC_Stop();
return Data;
}
void main()
{
P2 = 0xa0;
P0 = 0x00;
P2 = 0x00;
P2 = 0x80;
P0 = 0xff;
P2 = 0x00;
at24c02_writebyte(0x00,1);
Delay(200);
while(1)
{
DisplaySMG_Bit(0x01,SMGNoDot_CA[AT24C02_Readbyte(0x00)]);
Delay(10);
}
}