将mlx90614所测温度数据显示在stc-isp上
时间: 2023-12-22 17:03:03 浏览: 96
要将 mlx90614 所测温度数据显示在 stc-isp 上,需要进行以下几个步骤:
1.连接 mlx90614 与 STC-ISP:将 mlx90614 的 SDA 连接到 STC-ISP 的 P1.0 引脚,将 mlx90614 的 SCL 连接到 STC-ISP 的 P1.1 引脚。
2.编写程序:使用 C 语言编写程序,通过 IIC 总线读取 mlx90614 的温度数据,并将数据转换为实际温度值,最后将温度值显示在 STC-ISP 的 LCD 屏幕上。
以下是一个简单的示例程序,可以作为参考:
```c
#include <reg52.h>
#include <stdio.h>
#define SDA P1_0
#define SCL P1_1
#define LCD P2
void delay(unsigned int us)
{
while (us--)
;
}
void iic_start(void)
{
SDA = 1;
delay(1);
SCL = 1;
delay(1);
SDA = 0;
delay(1);
SCL = 0;
delay(1);
}
void iic_stop(void)
{
SDA = 0;
delay(1);
SCL = 1;
delay(1);
SDA = 1;
delay(1);
}
unsigned char iic_read(unsigned char ack)
{
unsigned char i, dat = 0;
SDA = 1;
for (i = 0; i < 8; i++)
{
dat <<= 1;
SCL = 1;
delay(1);
dat |= SDA;
SCL = 0;
delay(1);
}
SDA = ack;
delay(1);
SCL = 1;
delay(1);
SCL = 0;
delay(1);
return dat;
}
void iic_write(unsigned char dat)
{
unsigned char i;
for (i = 0; i < 8; i++)
{
SDA = (dat & 0x80) ? 1 : 0;
delay(1);
SCL = 1;
delay(1);
SCL = 0;
delay(1);
dat <<= 1;
}
SDA = 1;
delay(1);
SCL = 1;
delay(1);
SCL = 0;
delay(1);
}
float read_temp(void)
{
int temp_reg;
float temp;
iic_start();
iic_write(0x5A << 1);
iic_write(0x07);
iic_start();
iic_write((0x5A << 1) + 1);
temp_reg = iic_read(1) << 8;
temp_reg |= iic_read(0);
iic_stop();
temp = temp_reg * 0.02 - 273.15;
return temp;
}
void init_lcd()
{
LCD = 0x30; //基本指令集
delay(20000);
LCD = 0x30; //基本指令集
delay(20000);
LCD = 0x30; //基本指令集
delay(20000);
LCD = 0x38; //8位数据,2行,5x7点阵
delay(20000);
LCD = 0x08; //关显示
delay(20000);
LCD = 0x01; //清屏幕
delay(20000);
LCD = 0x06; //写入后指针加1
delay(20000);
LCD = 0x0C; //开显示,不显示光标
delay(20000);
}
void write_lcd(char *str)
{
while (*str)
{
LCD = *str++;
delay(1000);
}
}
void main()
{
float temp;
char str[16];
init_lcd();
while (1)
{
temp = read_temp();
sprintf(str, "Temp: %.2fC", temp);
write_lcd(str);
delay(10000);
}
}
```
此程序使用 STC89C52RC 单片机,通过 IIC 总线读取 mlx90614 的温度数据,并将温度数据显示在 STC-ISP 的 LCD 屏幕上。在使用时需要根据具体的硬件情况进行调整。
阅读全文
相关推荐













