1 目的
该文档的主要目的是描述怎样实现单片机和红外温度计MLX90615的SMBus通信。代码是基于STC12C5604AD单片机的。实例给出了由C语言实现MLX90615读取物体温度,写入数据到MLX90615的功能。
2 C 代码
2.1 由MLX90615读取温度部分
实例给出了应用C语言来实现从MLX90615中读取物体温度的程序。为了使程序操作和运行简单起见,整个项目被分为几个子项目。在该文档中整个C程序分为主文件 (用来实现对物体温度的读取、改变SMBus地址、改变发射率参数功能);子文件(具体描述SMBus通信的起始状态,终止状态,发送和接受数据); 子文件(包含了利用SMBus通信由MLX90615读取数据,对MLX90615写入数据和PEC校验码计算的程序);子文件(调用延迟函数);子文件(将十进制转换为十六进制);子文件(根据十六进制数值计算温度读数);子文件(在数字LEDs上显示温度读数)。在主文件的头文件中引用相应的子文件.h文件,以将所有功能综合、链接起来。
2.2 STCSTCSCLSCLSCLSCLDATASCLSCLSCLSCLDATASTCSCLSCLSCLSCLSCLSCLSCLSCLSCLSCLSCLSCLSC
LSCLSCLSCLSCLSCLSCLSCLACKSCLSCLSCLSCLACKSTCSCLSCLCRCCRCCRCRAMSLASLASLASLASLASLACRCSLASLASLASLASTCSTCSTCSCLSCLSCL文件介绍
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------// 头文件保护
//----------------------------------------------------------------------------------------------------------------------------------------// #ifndef SMBUS_CM_H #define SMBUS_CM_H
//----------------------------------------------------------------------------------------------------------------------------------------// 函数声明
//----------------------------------------------------------------------------------------------------------------------------------------// void start_bit(); void stop_bit();
void send_bit(unsigned char bit_out); unsigned char receive_bit(); unsigned char slave_ack();
void TX_byte(unsigned char TX_buffer); unsigned char RX_byte(unsigned char ack_nack);
#endif
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------// 头文件保护
//----------------------------------------------------------------------------------------------------------------------------------------// #ifndef SMBUS_OP_H #define SMBUS_OP_H
//----------------------------------------------------------------------------------------------------------------------------------------// 函数声明
//----------------------------------------------------------------------------------------------------------------------------------------// unsigned char PEC_cal(unsigned char pec[],int n);
unsigned long int MEM_READ(unsigned char slave_addR,unsigned char cmdR);
void EEPROM_WRITE(unsigned char slave_addW,unsigned char cmdW,unsigned char DataL,unsigned char DataH);
#endif
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------// 函数声明
//----------------------------------------------------------------------------------------------------------------------------------------// void Delay(unsigned int N);
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------// 函数声明
//----------------------------------------------------------------------------------------------------------------------------------------// unsigned int *dec2hex(float e);
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------// 函数声明
//----------------------------------------------------------------------------------------------------------------------------------------// extern unsigned int *CALTEMP(unsigned long int TEMP);
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------// 函数声明
//----------------------------------------------------------------------------------------------------------------------------------------// extern void show(unsigned int mahh[],int number);
//----------------------------------------------------------------------------------------------------------------------------------------//
//----------------------------------------------------------------------------------------------------------------------------------------//