本设计采用串口通信方式控制云台的姿态和内部温度值,通过串口发送控制命令+MPULCD ON控制读取MPU6050姿态参数,发送控制命令+TEMLCD ON读取内部温度参数,并且通过TFTLCD 实时显示各参数值。
//串口通信显示函数错误,但是TFTLCD能正常显示MPU6050 参数值和温度值
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "lcd.h"
#include "tsensor.h"
#include "malloc.h"
#include "sdio_sdcard.h"
#include "w25qxx.h"
#include "ff.h"
#include "exfuns.h"
#include "text.h"
#include "mpu6050.h"
#include "usmart.h"
#include "inv_mpu.h"
#include "inv_mpu_dmp_motion_driver.h"
#include "mpulcd.h"
#include "temlcd.h"
#include "string.h"
int main(void)
{
u8 key;
u16 rlen=0;
delay_init(); //延时函数初始化
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
uart_init(115200); //串口初始化为115200
LED_Init(); //LED端口初始化
KEY_Init(); //初始化与按键连接的硬件接口
usmart_dev.init(72); //初始化USMART
LCD_Init();
T_Adc_Init(); //ADC初始化
MPU_Init(); //初始化MPU6050
W25QXX_Init(); //初始化W25Q128
my_mem_init(SRAMIN); //初始化内部内存池
exfuns_init(); //为fatfs相关变量申请内存
mpu_lcd();
tem_lcd();
f_mount(fs[0],"0:",1); //挂载SD卡
f_mount(fs[1],"1:",1); //挂载FLASH.
while(font_init()) //检查字库
{
LCD_Clear(WHITE); //清屏
POINT_COLOR=RED; //设置字体为红色
LCD_ShowString(30,50,200,16,16,"ELITE STM32F103 ^_^");
while(SD_Init()) //检测SD卡
{
LCD_ShowString(30,70,200,16,16,"SD Card Failed!");
delay_ms(200);
LCD_Fill(30,70,200+30,70+16,WHITE);
delay_ms(200);
}
LCD_ShowString(30,70,200,16,16,"SD Card OK");
LCD_ShowString(30,90,200,16,16,"Font Updating...");
key=update_font(20,110,16,"0:");//更新字库
while(key)//更新失败
{
LCD_ShowString(30,110,200,16,16,"Font Update Failed!");
delay_ms(200);
LCD_Fill(20,110,200+20,110+16,WHITE);
delay_ms(200);
}
LCD_ShowString(30,110,200,16,16,"Font Update Success! ");
delay_ms(1500);
LCD_Clear(WHITE);//清屏
}
POINT_COLOR=DARKBLUE;
Show_Str(30,50,280,16,"基于STM32单片机无线监控系统的设计",16,0);
Show_Str(30,70,200,16,"WIFI-通信测试程序",16,0);
POINT_COLOR=RED;
Show_Str(30,90,200,16,"作者:LuX",16,0);
Show_Str(30,110,200,16,"日期:2019年4月10日",16,0);
Show_Str(30,130,200,16,"按KEY0,更新字库",16,0);
LCD_ShowString(30,150,200,16,16,"TEMPERATE: 00.00C");
while(mpu_dmp_init())
{
LCD_ShowString(30,170,200,16,16,"MPU6050 Error");
delay_ms(200);
LCD_Fill(30,170,239,130+16,WHITE);
delay_ms(200);
}
LCD_ShowString(30,170,200,16,16,"MPU6050 IS OK!");
POINT_COLOR=BLUE;//设置字体为蓝色
LCD_ShowString(30,190,200,16,16," Temp: . C");
LCD_ShowString(30,210,200,16,16,"Pitch: . C");
LCD_ShowString(30,230,200,16,16," Roll: . C");
LCD_ShowString(30,250,200,16,16," Yaw : . C");
// LCD_ShowString(30,270,200,16,16,"Send:");
LCD_ShowString(30,270,200,16,16,"Receive:");
USART_RX_STA=0;
while(1)
{
if(USART_RX_STA&0X8000) //接收到一次数据了
{
LCD_Fill(30,290,240,320,WHITE); //清除显示
rlen=USART_RX_STA&0X7FFF; //得到数据长度
USART_RX_BUF[rlen]=0; //加入结束符
//红色部分可以这样吗?串口里面会报错?有没有大神有好的解决方法//
if(strcmp((const char*)USART_RX_BUF,"+TEMLCD ON")==0)//关闭LED1
{
tem_lcd();
}
if(strcmp((const char*)USART_RX_BUF,"+MPULCD ON")==0)//关闭LED1
{
mpu_lcd();
}
LCD_ShowString(30,290,209,119,16,USART_RX_BUF);//显示接收到的数据
USART_RX_STA=0;
}
}
}
|