EEPROM存储功能验证
作者:互联网
在飞凌RT1052开发板上,配有一个I2C接口的EEPROM,其型号是24C02,容量为256字节。由于容量较小,因此只适应于参数的存储,而不适于做硬字库来使用。
为验证24C02的读写功能,特为它配上TFT串口屏来进行信息显示,其验证效果如图所示。
<ignore_js_op>
24C02读写验证效果
现实验证效果的主程序为:
实现十六进制数显示的函数为:
进行读写验证的函数为:
<ignore_js_op>
24C02读写验证效果
现实验证效果的主程序为:
- int main(void)
- {
- BOARD_ConfigMPU();
- BOARD_InitPins();
- BOARD_InitI2C1Pins();
- BOARD_BootClockRUN();
- BOARD_InitDebugConsole();
- GPIO_PinInit(EXAMPLE_LED_GPIO, EXAMPLE_LED_GPIO_PIN, &led_config);
- LCD_GPIO_Cogfig();
- Lcd_Init();
- LCD_Clear(RED);
- BACK_COLOR=RED;
- POINT_COLOR=WHITE;
- LCD_ShowString(52,20,100,16,16,"OK1052-C");
- LCD_ShowString(52,40,200,16,16,"EEPROM TEST");
- I2C_EEPROM_Init();
- I2C_EEPROM_TEST();
- while (1);
- }
实现十六进制数显示的函数为:
- void LCD_ShowNumH(uint16_t x,uint16_t y,uint32_t num,char size)
- {
- char t,temp;
- char enshow=0;
- temp=num/16;
- if(temp<10) LCD_ShowChar(x,y,temp+'0',size,0);
- else LCD_ShowChar(x,y,temp-10+'A',size,0);
- temp=num%16;
- if(temp<10) LCD_ShowChar(x+8,y,temp+'0',size,0);
- else LCD_ShowChar(x+8,y,temp-10+'A',size,0);
- }
进行读写验证的函数为:
- void I2C_EEPROM_TEST()
- {
- uint8_t dataBuff[8] = {0};
- if(!I2C_EEPROM_Read(I2C_EEPROM_BASE,0,dataBuff,8))
- {
- LCD_ShowString(20,80,200,16,16,"Read from EEPROM Sucess !");
- for(uint8_t i=0;i<8;i++)
- {
- LCD_ShowNumH(20+i*24,100,dataBuff[i],16);
- }
- }
- for(uint8_t i=0;i<8;i++)
- {
- dataBuff[i] = i;
- }
- if(!I2C_EEPROM_Write(I2C_EEPROM_BASE,0,dataBuff,8))
- {
- LCD_ShowString(20,120,200,16,16,"Write to EEPROM Sucess !");
- for(uint8_t i=0;i<8;i++)
- {
- LCD_ShowNumH(20+i*24,140,dataBuff[i],16);
- }
- }
- memset(dataBuff,0,8);
- if(!I2C_EEPROM_Read(I2C_EEPROM_BASE,0,dataBuff,8))
- {
- LCD_ShowString(20,160,200,16,16,"Read from EEPROM Sucess !");
- for(uint8_t i=0;i<8;i++)
- {
- LCD_ShowNumH(20+i*24,180,dataBuff[i],16);
- }
- }
- }
标签:存储,dataBuff,20,16,验证,LCD,I2C,EEPROM 来源: https://www.cnblogs.com/zhugeanran/p/16390603.html