安服优-B-1 人体红外测温传感器——ZYNQ学习笔记23

后续更新IIC驱动方案

通信协议简介:

B-1 红外测温模块可以支持 UART 或者 IIC 从机两种协议方式,模块上电时默

认为串口协议,5 秒内未接收到串口命令则自动切换到 IIC 协议,在串口协议与

IIC 协议中均为配置模块的协议方式,当配置协议方式后,模块会禁用自动协议

切换,再次上电会直接切换至配置的协议方式。

使用UART0作配置端口,UART1做调试端口

UART通信协议比较简单,这里放置顶层文件

cs 复制代码
#include "xparameters.h"	//器件参数信息
#include "xuartps.h"		//包含 PS UART 的函数声明
#include "xil_printf.h"		//包含 print()函数
#include "xscugic.h"		//包含中断的函数声明
#include "stdio.h"			//包含 printf 函数的声明
#include "xscugic.h"		//
#include "sleep.h"
#include "uart.h"
#include "intr.h"

XUartPs Uart0ps	;
XUartPs Uart1ps	;
XScuGic Intc	;

float calculate_temperature(unsigned char high_byte, unsigned char low_byte);

u8 buffer[64];
int bytes_received;
u8 get_data_flag;
unsigned int result;

int main(){
	uart0_config(&Uart0ps);
	uart1_config(&Uart1ps);
	intr_config(&Intc,&Uart0ps);

	uint8_t cmd[] = {0xAA, 0xA5, 0x03, 0x01, 0x04, 0x55};		//查询温度

	float temperature = 0;

	while(1){
		sleep(1);
		uart0_send_bytes(cmd, sizeof(cmd));
		temperature = calculate_temperature(buffer[get_data_flag+4],buffer[get_data_flag+5]);
		uart1_printf("人体温度 = %.2f\r\n",temperature);
//		uart1_printf("%x %x %x %x\r\n",buffer[get_data_flag+4],buffer[get_data_flag+5],
//										buffer[get_data_flag+6],buffer[get_data_flag+7]);
	}
}

float calculate_temperature(unsigned char high_byte, unsigned char low_byte) {
    unsigned int raw_value = (high_byte << 8) | low_byte;
    float temperature = raw_value / 10.0f;
    return temperature;
}

完整工程请后台私聊;

相关推荐
凯尔萨厮10 分钟前
Maven(Windows下载安装)
笔记·maven
wdfk_prog12 分钟前
[Linux]学习笔记系列 -- [drivers][input]serio
linux·笔记·学习
菩提小狗1 小时前
小迪安全2023-2024|第5天:基础入门-反弹SHELL&不回显带外&正反向连接&防火墙出入站&文件下载_笔记|web安全|渗透测试|
笔记·安全·web安全
Wentao Sun2 小时前
致敬软件创业者2026
笔记·程序人生
ZH15455891312 小时前
Flutter for OpenHarmony Python学习助手实战:GUI桌面应用开发的实现
python·学习·flutter
编程小白20263 小时前
从 C++ 基础到效率翻倍:Qt 开发环境搭建与Windows 神级快捷键指南
开发语言·c++·windows·qt·学习
学历真的很重要3 小时前
【系统架构师】第二章 操作系统知识 - 第二部分:进程与线程(补充版)
学习·职场和发展·系统架构·系统架构师
深蓝海拓3 小时前
PySide6,QCoreApplication::aboutToQuit与QtQore.qAddPostRoutine:退出前后的清理工作
笔记·python·qt·学习·pyqt
酒鼎3 小时前
学习笔记(3)HTML5新特性(第2章)
笔记·学习·html5
L***一3 小时前
2026届大专跨境电商专业毕业生就业能力提升路径探析
学习