安服优-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;
}

完整工程请后台私聊;

相关推荐
沉浸式学习ing1 天前
播客和视频怎么变成知识库里的笔记?音视频转结构化笔记完整方案
人工智能·笔记·gpt·学习·ai·音视频·notion
冰暮流星1 天前
URL结构解析
笔记
知识分享小能手1 天前
R语言入门学习教程,从入门到精通,R语言数据处理与清洗 (9)
开发语言·学习·r语言
炽烈小老头1 天前
【 每天学习一点算法 2026/05/14】单词接龙
学习·算法
Genevieve_xiao1 天前
【xjtuse】【数学建模】课程笔记(一)初等模型、图与网络
笔记·数学建模
yxc_inspire1 天前
24年CCPC山东邀请赛补题
学习·算法
red_redemption1 天前
自由学习记录(187)
学习
OBiO20131 天前
靶向肠道的腺相关病毒(AAV)血清型及启动子选择
笔记
star learning white1 天前
xm电气工程5
笔记
nashane1 天前
HarmonyOS 6学习:Web组件与JavaScript交互的三大高频问题与终极解决方案
前端·学习·harmonyos