18926453764的个人空间 https://blog.eetop.cn/1736369 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

AT24C02存储器读写测试程序

已有 870 次阅读| 2019-8-22 15:44 |系统分类:嵌入式| AT24C02

本程序利用Ginkgo I2C适配器底层接口函数对AT24C02存储器进行读写控制,程序将写入的数据显示出来,程序代码如下:
  1. #include <stdio.h>
  2. #include <Windows.h>
  3. //定义I2C适配器底层函数的函数指针
  4. typedef int(*I2C_Funtion)(char *in,char *out);
  5. //数据存储区
  6. unsigned char inString[10240];
  7. unsigned char outString[10240];
  8. //主函数
  9. int main(void)
  10. {
  11.         // 加载DLL
  12.         HINSTANCE hDLL;    //DLL句柄
  13.         hDLL = LoadLibrary("vtfreqfunc.dll");
  14.         //获取I2C初始化函数指针地址
  15.         I2C_Funtion I2C_Init = (I2C_Funtion)GetProcAddress(hDLL,"VTIF_I2C_Init");
  16.         //获取I2C写数据函数指针地址
  17.         I2C_Funtion I2C_WriteData = (I2C_Funtion)GetProcAddress(hDLL,"VTIF_I2C_WriteData");
  18.         //获取I2C读数据函数指针地址
  19.         I2C_Funtion I2C_ReadData = (I2C_Funtion)GetProcAddress(hDLL,"VTIF_I2C_ReadData");
  20.         //获取I2C设备选择函数指针地址
  21.         I2C_Funtion I2C_SelectDevice = (I2C_Funtion)GetProcAddress(hDLL,"VTIF_I2C_SelectDevice");
  22.         //选择I2C适配器
  23.         printf("选择I2C适配器\n");
  24.         I2C_SelectDevice("0",(char*)outString);//选择I2C适配器
  25.         printf("%s\n\n",outString);//显示选择适配器操作后的字符串数据
  26.         <font color="#ff0000">//初始化I2C适配器
  27.         //数据格式为:“控制模式|设备地址|读写速度|子地址模式|子地址宽度|初始化通道”
  28.         printf("初始化I2C适配器\n");
  29.         I2C_Init("1|0xA0|100000|1|1|0",(char*)outString);//初始化I2C适配器
  30.         printf("%s\n\n",outString);//显示初始化后适配器返回的初始化结果字符串</font>


  31.         //向24C02存储器写数据,首字节为子地址,后面是写入的数据
  32.         printf("向24C02存储器写数据\n");
  33.         I2C_WriteData("0x00|0x00|0x01|0x02|0x03|0x04|0x05|0x06|0x07",(char*)outString);
  34.         printf("%s\n\n",outString);//显示数据写操作后的结果

  35.         //读取24C02存储器指定地址的数据
  36.         printf("正在读取数据\n");
  37.         I2C_ReadData("0x00|8",(char*)outString);//首字节为子地址,读取8字节数据
  38.         printf("%s\n\n",outString);//显示返回来的数据,数据格式为:“数据1|数据2|...|数据n”

  39.         FreeLibrary(hDLL);
  40.         system("pause");
  41.         return 0;
  42. }
复制代码
运行结果.jpg 

点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 4

    粉丝
  • 0

    好友
  • 0

    获赞
  • 0

    评论
  • 361

    访问数
关闭

站长推荐 上一条 /2 下一条

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-4-19 16:59 , Processed in 0.021869 second(s), 14 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部