【DFRobot 云雀气象仪】学习笔记02(LCD显示云雀气象仪数据)
## 7:单片机串口接收气象数据### 7.1:串口数据处理
为了能够接收云雀气象仪的数据,我们实用串口通讯来实现数据处理,单片机采用STM32单片机,使用PA9和PA10的串口功能实现。首先初始化串口引脚功能,具体实现方式如下:
```C
void Bsp_USART1_Init(unsigned intbound)
{
//GPIO端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE); //使能USART1,GPIOA时钟
//USART1_TX GPIOA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.9
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.9
//USART1_RX GPIOA.10初始化
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//PA10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//浮空输入
GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化GPIOA.10
//Usart1 NVIC 配置
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3 ; //抢占优先级3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
//USART 初始化设置
USART_InitStructure.USART_BaudRate = bound;//串口波特率
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
USART_InitStructure.USART_StopBits = USART_StopBits_1;//一个停止位
USART_InitStructure.USART_Parity = USART_Parity_No;//无奇偶校验位
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//无硬件数据流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收发模式
USART_Init(USART1, &USART_InitStructure); //初始化串口1
/* CPU的小缺陷:串口配置好,如果直接Send,则第1个字节发送不出去,如下语句解决第1个字节无法正确发送出去的问题 */
/* 清发送完成标志,Transmission Complete flag */
USART_ClearFlag(USART2, USART_FLAG_TC);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启串口接受中断
USART_Cmd(USART1, ENABLE); //使能串口1
}
```
接着配置串口中断接收数据处理,我这里实用普通的串口中断,当然也可以实用串口空闲中断接收:
```
void USART1_IRQHandler(void)
{
unsigned char dat;
/*使用串口中断接收,不是串口空闲中断*/
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
dat = USART_ReceiveData(USART1);
CBUF_Push(RxBuffer1, dat);
USART_ClearITPendingBit(USART1, USART_IT_RXNE);
}
}
```
再者,串口定时发送获取气象数据命令来获取气象数据,这里有温度,湿度,风向,风速,海拔,气压等6个参数。
```C
/*获取天气数据状态机*/
voidGet_Weather_Info_StateMachine(void)
{
// staticunsigned char timeCount=0;
// timeCount++;
// if(timeCount==20)
// {
// timeCount =0;
// }
/*状态切换*/
state++;
switch(state)
{
case STATE_TEMP:
USART1_DMA_Send(get_temp_cmd,sizeof(get_temp_cmd));
// state = STATE_HUMI;
break;
case STATE_HUMI:
USART1_DMA_Send(get_humi_cmd,sizeof(get_humi_cmd));
break;
case STATE_WINDSPEED:
USART1_DMA_Send(get_windSpeed_cmd,sizeof(get_windSpeed_cmd));
break;
case STATE_WINDDIR:
USART1_DMA_Send(get_windDir_cmd,sizeof(get_windDir_cmd));
break;
case STATE_ALTITUDE:
USART1_DMA_Send(get_altitude_cmd,sizeof(get_altitude_cmd));
break;
case STATE_PRESSURE:
USART1_DMA_Send(get_pressure_cmd,sizeof(get_pressure_cmd));
break;
default :
break;
}
}
```
最后,进行数据解析,将保存好的数据放入到指定字符串下。
```
voidUSART1_IRQ_VerityFun(void)
{
unsigned char strLen=0;
unsigned char i=0;
if(flagFrame) //帧接收完成标志,即接收到一帧新数据
{
flagFrame=0; //帧接收完成标志清零
strLen = CBUF_Len(RxBuffer1);
if(strLen>ResDataPackageLen)
{
RTT_LOG("len=%d",strLen);
for(i=0;i<strLen;i++)
{
RTT_LOG("%c",RxBuffer1.m_entry);
}
switch(state)
{
case STATE_TEMP:
memcpy(tempBuf, (u8*)&RxBuffer1.m_entry, strLen-ResDataPackageLen);
RTT_LOG("%s",tempBuf);
break;
case STATE_HUMI:
memcpy(humiBuf, (u8*)&RxBuffer1.m_entry, strLen-ResDataPackageLen);
RTT_LOG("%s",humiBuf);
break;
case STATE_WINDSPEED:
memcpy(windSpeedBuf, (u8*)&RxBuffer1.m_entry, strLen-ResDataPackageLen);
RTT_LOG("%s",windSpeedBuf);
break;
case STATE_WINDDIR:
memcpy(windDirBuf, (u8*)&RxBuffer1.m_entry, strLen-ResDataPackageLen);
RTT_LOG("%s",windDirBuf);
break;
case STATE_ALTITUDE:
memcpy(altitudeBuf, (u8*)&RxBuffer1.m_entry, strLen-ResDataPackageLen);
RTT_LOG("%s",altitudeBuf);
break;
case STATE_PRESSURE:
RTT_LOG("------");
memcpy(pressureBuf, (u8*)&RxBuffer1.m_entry, strLen-ResDataPackageLen);
RTT_LOG("%s",pressureBuf);
state = STATE_IDLE;
break;
default :
break;
}
USART1_Clear();
}
else if(strLen<=ResDataPackageLen)
{
USART1_Clear();
}
else
{
}
}
}
```
### 7.2:LCD显示驱动
数据显示,我采用1.77寸LCD显示气象数据。
1.77寸TFT LCD液晶显示屏采用高透光率玻璃基板,配以低功耗驱动IC电路设计而成。其外观尺寸为17英寸×11英寸×2.44厘米(长×宽×厚),重量约为0.45千克。
!(https://boreyun.oss-cn-shanghai.aliyuncs.com/image-20231112151105092.png)
(1)该款LCD液晶屏采用了高透光率的玻璃基板,使屏幕画面清晰明亮、层次分明、色彩丰富艳丽;同时由于采用了低功耗驱动IC电路设计而成,使得整机耗电量大大降低,从而降低了用户的使用成本。
首先编写LCD驱动显示函数:具体代码如下:
```c
#include "main.h"
#include "Lcd_Driver.h"
#include "LCD_Config.h"
//#include "delay.h"
#include "stdlib.h"//函数调用头文件
#include "stdio.h" //为了解除sprintf警告
#include "LCD_calculate.h"
//#include "global.h"
//液晶IO初始化配置
void LCD_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//开漏输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//开漏输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
//向SPI总线传输一个8位数据
voidSPI_WriteData(unsigned char Data)
{
unsigned char i=0;
for(i=8;i>0;i--)
{
if(Data&0x80)
LCD_SDA_SET; //输出数据
else LCD_SDA_CLR;
LCD_SCL_CLR;
LCD_SCL_SET;
Data<<=1;
}
}
//向液晶屏写一个8位指令
void Lcd_WriteIndex(unsigned char Index)
{
//SPI 写命令时序开始
LCD_CS_CLR;
LCD_RS_CLR;
SPI_WriteData(Index);
LCD_CS_SET;
}
//向液晶屏写一个8位数据
void Lcd_WriteData(unsigned char Data)
{
LCD_CS_CLR;
LCD_RS_SET;
SPI_WriteData(Data);
}
//向液晶屏写一个16位数据
void LCD_WriteData_16Bit(unsigned int Data)
{
LCD_CS_CLR;
LCD_RS_SET;
SPI_WriteData(Data>>8); //写入高8位数据
SPI_WriteData(Data); //写入低8位数据
LCD_CS_SET;
}
void Lcd_WriteReg(unsigned char Index,unsigned char Data)
{
Lcd_WriteIndex(Index);
Lcd_WriteData(Data);
}
void Lcd_Reset(void)
{
unsigned int i;
LCD_RST_CLR;
//delay_ms(100);
for(i=0;i<6000;i++);
LCD_RST_SET;
for(i=0;i<6000;i++);
}
//LCD Init For 1.44Inch LCD Panel with ST7735R.
void Lcd_Init(void)
{
unsigned int i;
LCD_GPIO_Init();
Lcd_Reset(); //Reset before LCD Init.
//LCD Init For 1.44Inch LCD Panel with ST7735R.
Lcd_WriteIndex(0x11);//Sleep exit
//delay_ms (120);
for(i=0;i<65000;i++);
for(i=0;i<65000;i++);
//ST7735R Frame Rate
Lcd_WriteIndex(0xB1);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB2);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB3);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteData(0x01);
Lcd_WriteData(0x2C);
Lcd_WriteData(0x2D);
Lcd_WriteIndex(0xB4); //Column inversion
Lcd_WriteData(0x07);
//ST7735R Power Sequence
Lcd_WriteIndex(0xC0);
Lcd_WriteData(0xA2);
Lcd_WriteData(0x02);
Lcd_WriteData(0x84);
Lcd_WriteIndex(0xC1);
Lcd_WriteData(0xC5);
Lcd_WriteIndex(0xC2);
Lcd_WriteData(0x0A);
Lcd_WriteData(0x00);
Lcd_WriteIndex(0xC3);
Lcd_WriteData(0x8A);
Lcd_WriteData(0x2A);
Lcd_WriteIndex(0xC4);
Lcd_WriteData(0x8A);
Lcd_WriteData(0xEE);
Lcd_WriteIndex(0xC5); //VCOM
Lcd_WriteData(0x0E);
Lcd_WriteIndex(0x36); //MX, MY, RGB mode
Lcd_WriteData(0xC0);
//ST7735R Gamma Sequence
Lcd_WriteIndex(0xe0);
Lcd_WriteData(0x0f);
Lcd_WriteData(0x1a);
Lcd_WriteData(0x0f);
Lcd_WriteData(0x18);
Lcd_WriteData(0x2f);
Lcd_WriteData(0x28);
Lcd_WriteData(0x20);
Lcd_WriteData(0x22);
Lcd_WriteData(0x1f);
Lcd_WriteData(0x1b);
Lcd_WriteData(0x23);
Lcd_WriteData(0x37);
Lcd_WriteData(0x00);
Lcd_WriteData(0x07);
Lcd_WriteData(0x02);
Lcd_WriteData(0x10);
Lcd_WriteIndex(0xe1);
Lcd_WriteData(0x0f);
Lcd_WriteData(0x1b);
Lcd_WriteData(0x0f);
Lcd_WriteData(0x17);
Lcd_WriteData(0x33);
Lcd_WriteData(0x2c);
Lcd_WriteData(0x29);
Lcd_WriteData(0x2e);
Lcd_WriteData(0x30);
Lcd_WriteData(0x30);
Lcd_WriteData(0x39);
Lcd_WriteData(0x3f);
Lcd_WriteData(0x00);
Lcd_WriteData(0x07);
Lcd_WriteData(0x03);
Lcd_WriteData(0x10);
Lcd_WriteIndex(0x2a);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x7f);
Lcd_WriteIndex(0x2b);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x00);
Lcd_WriteData(0x9f);
Lcd_WriteIndex(0xF0); //Enable test command
Lcd_WriteData(0x01);
Lcd_WriteIndex(0xF6); //Disable ram power save mode
Lcd_WriteData(0x00);
Lcd_WriteIndex(0x3A); //65k mode
Lcd_WriteData(0x05);
Lcd_WriteIndex(0x29);//Display on
}
/*************************************************
函数名:LCD_Set_Region
功能:设置lcd显示区域,在此区域写点数据自动换行
入口参数:xy起点和终点
返回值:无
*************************************************/
void Lcd_SetRegion(unsigned int x_start,unsigned int y_start,unsigned int x_end,unsigned int y_end)
{
Lcd_WriteIndex(0x2a);
Lcd_WriteData(0x00);
Lcd_WriteData(x_start);//Lcd_WriteData(x_start+2);
Lcd_WriteData(0x00);
Lcd_WriteData(x_end+2);
Lcd_WriteIndex(0x2b);
Lcd_WriteData(0x00);
Lcd_WriteData(y_start+0);
Lcd_WriteData(0x00);
Lcd_WriteData(y_end+1);
Lcd_WriteIndex(0x2c);
}
/*************************************************
函数名:LCD_Set_XY
功能:设置lcd显示起始点
入口参数:xy坐标
返回值:无
*************************************************/
void Lcd_SetXY(unsigned int x,unsigned int y)
{
Lcd_SetRegion(x,y,x,y);
}
/*************************************************
函数名:LCD_DrawPoint
功能:画一个点
入口参数:无
返回值:无
*************************************************/
void Gui_DrawPoint(unsigned int x,unsigned int y,unsigned int Data)
{
Lcd_SetRegion(x,y,x+1,y+1);
LCD_WriteData_16Bit(Data);
}
/*****************************************
函数功能:读TFT某一点的颜色
出口参数:color点颜色值
******************************************/
unsigned int Lcd_ReadPoint(unsigned int x,unsigned int y)
{
unsigned int Data;
Lcd_SetXY(x,y);
Lcd_WriteData(Data);
return Data;
}
/*************************************************
函数名:Lcd_Clear
功能:全屏清屏函数
入口参数:填充颜色COLOR
返回值:无
*************************************************/
void Lcd_Clear(unsigned int Color) //刷新全屏
{
unsigned int i,m;
Lcd_SetRegion(0,0,X_MAX_PIXEL-1,Y_MAX_PIXEL-1);
Lcd_WriteIndex(0x2C);
for(i=0;i<X_MAX_PIXEL;i++)
for(m=0;m<Y_MAX_PIXEL;m++)
{
LCD_WriteData_16Bit(Color);
}
}
void Lcd_Clear_1(unsigned int Color) //刷新局部
{
unsigned int i,m;
Lcd_SetRegion(105,137,120,152-1);
Lcd_WriteIndex(0x2C);
for(i=0;i<120;i++)
for(m=0;m<152;m++)
{
LCD_WriteData_16Bit(Color);
}
}
/*
屏幕显示测试
*/
void Redraw_Mainmenu(void)
{
Lcd_Clear(GRAY0);
Gui_DrawFont_GBK16(15,5,BLUE,GRAY0,"实验平台");
//值的边框
DisplayButtonUp(85,27,125,45); //x1,y1,x2,y2//TO
//DisplayButtonUp(85,49,125,67); //x1,y1,x2,y2//ONE
}
void Num_Test(void)
{
// char txt;
// char txt1;
//
// sprintf(txt, "%d", tempdata);
// Gui_DrawFont_GBK16(90,25,BLUE,GRAY0,txt);
//
// sprintf(txt1, "%d", humidata);
// Gui_DrawFont_GBK16(90,47,RED,GRAY0,txt1);
}
void Color_Test(void)
{
unsigned int i=1;
Lcd_Clear(GRAY0);
Gui_DrawFont_GBK16(20,10,BLUE,GRAY0,"Color Test");
while(i--)
{
Lcd_Clear(WHITE);
Lcd_Clear(BLACK);
Lcd_Clear(RED);
Lcd_Clear(GREEN);
Lcd_Clear(BLUE);
}
}
//取模方式 水平扫描 从左到右 低位在前
void showimage(const unsigned char *p) //显示40*40 QQ图片
{
int i,j,k;
unsigned char picH,picL;
Lcd_Clear(WHITE); //清屏
for(k=0;k<4;k++)
{
for(j=0;j<3;j++)
{
Lcd_SetRegion(40*j+2,40*k,40*j+39,40*k+39); //坐标设置
for(i=0;i<40*40;i++)
{
picL=*(p+i*2);//数据低位在前
picH=*(p+i*2+1);
LCD_WriteData_16Bit(picH<<8|picL);
}
}
}
}
void QDTFT_Test_Demo(void)
{
// LCD_LED_SET;//通过IO控制背光亮
Num_Test();//
}
```
其次利用取模软件,显示中文字体,
!(https://boreyun.oss-cn-shanghai.aliyuncs.com/image-20231112151720258.png)
具体字体文件如下:
```
云(0) 雀(1) 气(2) 象(3) 仪(4) 温(5) 度(6) 湿(7)
度(8) 风(9) 速(10) 风(11) 向(12) 海(13) 拔(14) 气(15)
压(16)
{0xFF,0xFF,0xC0,0x07,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0xFD,0xFF},
{0xFB,0xFF,0xFB,0xFF,0xF7,0xBF,0xEF,0xDF,0xDF,0xEF,0x80,0x07,0xDF,0xF7,0xFF,0xF7},/*"云",0*/
{0xFE,0xFF,0xEE,0xEF,0xEE,0xF7,0xDE,0xDB,0xBF,0x3F,0xFC,0xFF,0xF3,0x7F,0xCF,0xBF},
{0x20,0x03,0xEF,0x7F,0xE0,0x07,0xEF,0x7F,0xE0,0x07,0xEF,0x7F,0xE0,0x03,0xEF,0xFF},/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EF,0xB7,0xEF,0xB7,0xEF,0xBF,0x04,0x01,0xEF,0x7F,0xEB,0x7F,0xE7,0x03},
{0xCE,0xBB,0x2E,0xBB,0xEE,0xD7,0xEE,0xD7,0xED,0xEF,0xED,0xD7,0xAB,0xBB,0xDE,0x7D},/*"拔",14*/
{0xEF,0xFF,0xEF,0xFF,0xC0,0x03,0xDF,0xFF,0xB0,0x0F,0x7F,0xFF,0xC0,0x0F,0xFF,0xEF},
{0xFF,0xEF,0xFF,0xEF,0xFF,0xEF,0xFF,0xEF,0xFF,0xF5,0xFF,0xF5,0xFF,0xF9,0xFF,0xFD},/*"气",15*/
{0xFF,0xFF,0xC0,0x01,0xDF,0xFF,0xDF,0x7F,0xDF,0x7F,0xDF,0x7F,0xDF,0x7F,0xD0,0x03},
{0xDF,0x7F,0xDF,0x7F,0xDF,0x6F,0xDF,0x77,0xDF,0x77,0xBF,0x7F,0xA0,0x01,0x7F,0xFF},/*"压",16*/
```
该字体大小是16*16,如果自己想改变字体大小的话,重新设置字体大小就行
### 7.3:实时刷新气象数据
首先实用中文显示气象数据信息:具体代码如下:
```c
void app_init(void)
{
Lcd_Init();
Lcd_Clear(GRAY0); //清屏
Gui_DrawFont_GBK16(24,0,BLUE,WHITE,"云雀气象仪:");
Gui_DrawFont_GBK16(0,24,BLACK,GRAY0,"温度:");
Gui_DrawFont_GBK16(0,48,RED,GRAY0,"湿度:");
Gui_DrawFont_GBK16(0,72,BLUE,WHITE,"风速:");
Gui_DrawFont_GBK16(0,96,RED,GRAY0,"风向:");
Gui_DrawFont_GBK16(0,120,BLUE,WHITE,"海拔:");
Gui_DrawFont_GBK16(0,144,BLACK,WHITE,"气压:");
bsp_InitLedHard();
}
```
将各个气象数据信息显示出来:
```c
voidDisplay_Weather_Data(void)
{
// Lcd_Clear(GRAY0); //清屏
Gui_DrawFont_GBK16(40,24,BLACK,GRAY0, (char*)tempBuf);
Gui_DrawFont_GBK16(40,48,RED,GRAY0,(char*)humiBuf);
Gui_DrawFont_GBK16(40,72,BLUE,WHITE, (char*)windSpeedBuf);
Gui_DrawFont_GBK16(40,96,BLUE,WHITE, (char*)windDirBuf);
Gui_DrawFont_GBK16(40,120,BLUE,WHITE, (char*)altitudeBuf);
Gui_DrawFont_GBK16(40,144,BLUE,WHITE, (char*)pressureBuf);
}
```
将此函数放入到循环任务里面显示,定时3秒刷新一次数据即可。
!(https://boreyun.oss-cn-shanghai.aliyuncs.com/image-20231112152239063.png)
具体视频为:
[各类传感器学习笔记05(LCD显示云雀气象仪传感器数据)_哔哩哔哩_bilibili]( 串口协议还是非常方便的,开发板看起来象武汉芯原的开发板呀。 <p>感谢楼主提供的技术分享,先收藏学习再发表个人意见,顶起来</p>
lugl4313820 发表于 2023-11-14 10:21
串口协议还是非常方便的,开发板看起来象武汉芯原的开发板呀。
<p>是的,就是他们家的开发板</p>
页:
[1]