新手入门
- 积分
- 9
- 金钱
- 9
- 注册时间
- 2020-2-19
- 在线时间
- 1 小时
|
文末有接线图和实验结果图,
先简单呈现主函数#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
//#include "lcd.h"
#include "key.h"
#include "24cxx.h"
#include "myiic.h"
const u8 TEXT_Buffer[]={"MiniSTM32 IIC TEST"};
#define SIZE sizeof(TEXT_Buffer)
int main(void)
{
u8 key;
u16 i=0;
u8 datatemp[SIZE];
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// éèÖÃÖD¶ÏóÅÏ輶·Ö×é2
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
uart_init(9600); //′®¿ú3õê¼»ˉÎa9600
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
//LCD_Init();
KEY_Init(); //°′¼ü3õê¼»ˉ
AT24CXX_Init(); //IIC3õê¼»ˉ
while(AT24CXX_Check())//¼ì2a2»μ½24c02
{
//LCD_ShowString(60,150,200,16,16,"24C02 Check Failed!");
printf("¼ì2a2»μ½24c02");
printf("\r\n");
delay_ms(500);
//LCD_ShowString(60,150,200,16,16,"Please Check! ");
printf("Please Check! ");
printf("\r\n");
delay_ms(500);
LED0=!LED0;//DS0éá˸
}
//LCD_ShowString(60,150,200,16,16,"24C02 Ready!");
//POINT_COLOR=BLUE;//éèÖÃ×ÖìåÎaà¶é«
printf("24C02 Ready!");
printf("\r\n");
while(1)
{
key=KEY_Scan(0);
if(key==WKUP_PRES)//WK_UP °′ÏÂ,D′èë24C02
{
//LCD_Fill(0,170,239,319,WHITE);//Çå3y°ëÆá
//LCD_ShowString(60,170,200,16,16,"Start Write 24C02....");
printf("Start Write 24C02....");
printf("\r\n");
AT24CXX_Write(0,(u8*)TEXT_Buffer,SIZE);
//LCD_ShowString(60,170,200,16,16,"24C02 Write Finished!");//ìáê¾′«Ëííê3é
printf("24C02 Write Finished!");
printf("\r\n");
}
if(key==KEY0_PRES)//KEY0 °′ÏÂ,¶áè¡×Ö·û′®2¢ÏÔê¾
{
//LCD_ShowString(60,170,200,16,16,"Start Read 24C02.... ");
printf("Start Read 24C02.... ");
printf("\r\n");
AT24CXX_Read(0,datatemp,SIZE);
//LCD_ShowString(60,170,200,16,16,"The Data Readed Is: ");//ìáê¾′«Ëííê3é
printf("The Data Readed Is: ");
printf("%s",datatemp);
printf("\r\n");
//LCD_ShowString(60,190,200,16,16,datatemp);//ÏÔ꾶áμ½μÄ×Ö·û′®
}
i++;
delay_ms(10);
if(i==20)
{
LED0=!LED0;//ìáê¾Ïμí3ÕyÔúÔËDD
i=0;
}
}
}
下面是AT24Cxx检测函数u8 AT24CXX_Check(void)
{
u8 temp;
temp=AT24CXX_ReadOneByte(255);//±üÃaÿ′οa»ú¶¼D′AT24CXX
if(temp==0X55)return 0;
else//ÅÅ3yμúò»′Î3õê¼»ˉμÄÇé¿ö
{
AT24CXX_WriteOneByte(255,0X55);
temp=AT24CXX_ReadOneByte(255);
if(temp==0X55)return 0;
}
return 1;
}
|
|