要求
1、在LCD1602上显示数字
2、按下K1对数字加1,按下K2对数字减1
3、按下K3将数字存到AT24C02中,按下K4将数字从AT24C02中取出来并在LCD上显示
效果
资源
工程文件压缩包
链接:https://pan.baidu.com/s/1EdI2_KE5v8NaU3Wk89ipig
提取码:foi0
main函数
#include <REGX52.H>
#include <INTRINS.H>
#include "LCD1602.H"
#include "Delay.H"
#include "Key.H"
#include "AT24C02.H"
void main(){
unsigned char KEY;
unsigned int Num=0;
LCD_Init();
LCD_ShowNum(1,1,Num,5);
while(1){
// temp=AT24C02_ReadByte(1);
KEY=key();
if(KEY==1) Num++;
if(KEY==2) Num--;
if(KEY==3){
AT24C02_WriteByte(0,Num%256);
Delayms(5); //写数据较慢,需要延时
AT24C02_WriteByte(1,Num/256);
Delayms(5);
LCD_ShowString(2,1,"W OK");
Delays(1);
LCD_ShowString(2,1," ");
}
if(KEY==4){
Num=AT24C02_ReadByte(0); //读数据较快,不需要延时
Num|=(AT24C02_ReadByte(1)<<8);
LCD_ShowString(2,1,"R OK");
Delays(1);
LCD_ShowString(2,1," ");
}
LCD_ShowNum(1,1,Num,5);
}
}