主函数
int main()
{
u8 wdata=0,value;
u8 i,j,dat[6],dat1[6];
I2C_INIT();
TFT_Init(); //TFT 彩屏初始化
LED_Init(); //端口初始化
key_init(); //按键初始化
printf_init(); //printf 初始化
TFT_ClearScreen(BLACK); //清屏
GUI_Show12ASCII(10,10,"This is a IIC-AT24C02 Check!",YELLOW,BLACK);
GUI_Show12ASCII(10,27,"PB10 PB11 is IIC Interface!",YELLOW,BLACK);
GUI_Show12ASCII(10,44,"The K_UP is:AT24C02 Write",YELLOW,BLACK);
GUI_Show12ASCII(10,61,"The K_DOWM is:AT24C02 Read",YELLOW,BLACK);
GUI_Show12ASCII(10,100,"Write data Range is: 0-255",YELLOW,BLACK);
GUI_Show12ASCII(10,150,"Write data is:",YELLOW,BLACK);
GUI_Show12ASCII(10,167,"Read data is:",YELLOW,BLACK);
while(1)
{
if(k_up==1) //按键 k_up 按下写入数据
{
delay_ms(10);
if(k_up==1)
{
AT24Cxx_WriteOneByte(0,++wdata);//写入的是单字节,0-255 取值范围
dat[0]=wdata/100+0x30;
dat[1]=wdata%100/10+0x30;
dat[2]=wdata%100%10+0x30;
dat[3]='\0';
GUI_Show12ASCII(160,150,dat,YELLOW,BLACK);
}
// while(k_up);
}
if(k_down==0) //读取数据
{
delay_ms(10);
if(k_down==0)
{
value=AT24Cxx_ReadOneByte(0);
dat1[0]=value/100+0x30;
dat1[1]=value%100/10+0x30;
dat1[2]=value%100%10+0x30;
dat1[3]='\0';
GUI_Show12ASCII(160,167,dat1,YELLOW,BLACK);
}
while(!k_down);
}
if(j>1)
{
j=0;
GPIO_SetBits(GPIOC,GPIO_Pin_0);
}
else
{
j++;
GPIO_ResetBits(GPIOC,GPIO_Pin_0);
}
delay_ms(200);
}
} |