TA的每日心情 | 奋斗 2023-5-10 20:09 |
---|
签到天数: 1742 天 连续签到: 1 天 [LV.Master]伴坛终老
|
为了进行温湿度曲线的绘制,这里先介绍一下TFT液晶屏的用法,由于并行的TFT屏占用GPIO资源较多,使用这里选用SPI通讯方式的串口屏,它与MCU的连接关系如下:
TFT_CS --PA4
TFT_RST --PA5
TFT_D/C --PA6
TFT_SDI --PA7
TFT_SCK --PA8
TFT_LED --PB0
定义TFT屏输出高低电平语句:
#define LCD_CS_High() GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET) #define LCD_CS_Low() GPIO_WriteBit(GPIOA, GPIO_Pin_4,Bit_RESET)#define LCD_REST_High() GPIO_WriteBit(GPIOA, GPIO_Pin_5, Bit_SET)#define LCD_REST_Low() GPIO_WriteBit(GPIOA, GPIO_Pin_5,Bit_RESET)#define LCD_DC_High() GPIO_WriteBit(GPIOA, GPIO_Pin_6, Bit_SET)#define LCD_DC_Low() GPIO_WriteBit(GPIOA, GPIO_Pin_6,Bit_RESET)#define LCD_SDI_High() GPIO_WriteBit(GPIOA, GPIO_Pin_7, Bit_SET)#define LCD_SDI_Low() GPIO_WriteBit(GPIOA, GPIO_Pin_7,Bit_RESET)#define LCD_SCK_High() GPIO_WriteBit(GPIOA, GPIO_Pin_8, Bit_SET)#define LCD_SCK_Low() GPIO_WriteBit(GPIOA, GPIO_Pin_8,Bit_RESET)#define LCD_LED_High() GPIO_WriteBit(GPIOB, GPIO_Pin_0,Bit_SET)TFT屏引脚配置函数:
void SPI_CONFIG(){ GPIO_InitTypeDef gpioInitStrcut; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); gpioInitStrcut.GPIO_Mode = GPIO_Mode_Out_PP; gpioInitStrcut.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8; gpioInitStrcut.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &gpioInitStrcut); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); gpioInitStrcut.GPIO_Mode = GPIO_Mode_Out_PP; gpioInitStrcut.GPIO_Pin = GPIO_Pin_0; gpioInitStrcut.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &gpioInitStrcut); LCD_LED_High();}TFT屏初始化函数:
void Lcd_Init(void){ LCD_REST_Low(); DelayXms(20); LCD_REST_High(); DelayXms(20); LCD_CS_Low(); LCD_WR_REG(0xCB); LCD_WR_DATA8(0x39); LCD_WR_DATA8(0x2C); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x34); LCD_WR_DATA8(0x02); LCD_WR_REG(0xCF); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0XC1); LCD_WR_DATA8(0X30); LCD_WR_REG(0xE8); LCD_WR_DATA8(0x85); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x78); LCD_WR_REG(0xEA); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x00); LCD_WR_REG(0xED); LCD_WR_DATA8(0x64); LCD_WR_DATA8(0x03); LCD_WR_DATA8(0X12); LCD_WR_DATA8(0X81); LCD_WR_REG(0xF7); LCD_WR_DATA8(0x20); LCD_WR_REG(0xC0); LCD_WR_DATA8(0x23); LCD_WR_REG(0xC1); LCD_WR_DATA8(0x10); LCD_WR_REG(0xC5); LCD_WR_DATA8(0x3e); LCD_WR_DATA8(0x28); LCD_WR_REG(0xC7); LCD_WR_DATA8(0x86); LCD_WR_REG(0x36); LCD_WR_DATA8(0x48); LCD_WR_REG(0x3A); LCD_WR_DATA8(0x55); LCD_WR_REG(0xB1); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x18); LCD_WR_REG(0xB6); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x82); LCD_WR_DATA8(0x27); LCD_WR_REG(0xF2); LCD_WR_DATA8(0x00); LCD_WR_REG(0x26); LCD_WR_DATA8(0x01); LCD_WR_REG(0xE0); LCD_WR_DATA8(0x0F); LCD_WR_DATA8(0x31); LCD_WR_DATA8(0x2B); LCD_WR_DATA8(0x0C); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x4E); LCD_WR_DATA8(0xF1); LCD_WR_DATA8(0x37); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x10); LCD_WR_DATA8(0x03); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x09); LCD_WR_DATA8(0x00); LCD_WR_REG(0XE1); LCD_WR_DATA8(0x00); LCD_WR_DATA8(0x0E); LCD_WR_DATA8(0x14); LCD_WR_DATA8(0x03); LCD_WR_DATA8(0x11); LCD_WR_DATA8(0x07); LCD_WR_DATA8(0x31); LCD_WR_DATA8(0xC1); LCD_WR_DATA8(0x48); LCD_WR_DATA8(0x08); LCD_WR_DATA8(0x0F); LCD_WR_DATA8(0x0C); LCD_WR_DATA8(0x31); LCD_WR_DATA8(0x36); LCD_WR_DATA8(0x0F); LCD_WR_REG(0x11); DelayXms(120); LCD_WR_REG(0x29); LCD_WR_REG(0x2c); }为自行构建小字库,可像OLED屏那样使用字模提取软件PCtoLCD2002,其操作界面如图1所示。
图1 字模提取
由于所购置的2.2寸串口屏是一块竖向显示屏,因此在制作图2的显示效果时,必须对相应的显示函数进行转置,如字符、数值、中文显示函数及波形绘制函数等。
图2 转置处理
利用温湿度检测例程,在配置字符显示函数和图形绘制函数的情况下,可以实现图3所示的设计效果。
图3 曲线绘制
实现温湿度曲线绘制的主函数如下:
int main(void){ int16_t i,sj,sp,j,sq,sg; uint32_t tem; uint32_t hum; uint32_t n=0,m; Hardware_Init(); SPI_CONFIG(); DelayXms(1000); Lcd_Init(); LCD_Clear(RED); BACK_COLOR=RED; POINT_COLOR=WHITE; showhanzi16h(40,100,6,0); showhanzi16h(40,120,5,0); showhanzi16h(40,140,4,0); showhanzi16h(40,160,3,0); showhanzi16h(40,180,2,0); showhanzi16h(40,200,1,0); showhanzi16h(40,220,0,0); showhanzi16h(200,160,2,0); showhanzi16h(200,180,1,0); showhanzi16h(200,280,2,0); showhanzi16h(200,300,0,0); POINT_COLOR=WHITE; //RED; DelayMs(1000); KEY_Init(); LCD_DrawLine(10, 300, 190, 300); LCD_DrawLine(190, 10, 190, 300); //125 sp=220-190; sq=sp; while(1) { SHT20_GetValue(); tem=sht20Info.tempreture; hum=sht20Info.humidity; j++; POINT_COLOR=YELLOW; sj=tem*4; sg=hum*2; LCD_DrawLine(220-sp, 300-4*(j-1), 220-sj, 300-4*(j)); POINT_COLOR=GREEN; LCD_DrawLine(220-sq, 300-4*(j-1), 220-sg, 300-4*(j)); POINT_COLOR=YELLOW; sp=sj; sq=sg; if(j>=64) { Loop: LCD_Clear(RED); j=0; POINT_COLOR=WHITE; showhanzi16h(40,100,6,0); showhanzi16h(40,120,5,0); showhanzi16h(40,140,4,0); showhanzi16h(40,160,3,0); showhanzi16h(40,180,2,0); showhanzi16h(40,200,1,0); showhanzi16h(40,220,0,0); showhanzi16h(200,160,2,0); showhanzi16h(200,180,1,0); showhanzi16h(200,280,2,0); showhanzi16h(200,300,0,0); POINT_COLOR=WHITE; LCD_DrawLine(10, 300, 190, 300); LCD_DrawLine(190, 10, 190, 300); } POINT_COLOR=YELLOW; tem=tem*10; hum=hum*10; LCD_ShowCharh(200,140,':',0); LCD_ShowCharh(200,260,':',0); LCD_ShowCharh(200,250,tem/100+0x30,0); LCD_ShowCharh(200,240,tem0/10+0x30,0); LCD_ShowCharh(200,230,'.',0); tem=tem; LCD_ShowCharh(200,220,tem+0x30,0); POINT_COLOR=GREEN; LCD_ShowCharh(200,130,hum/100+0x30,0); LCD_ShowCharh(200,120,hum0/10+0x30,0); LCD_ShowCharh(200,110,'.',0); hum=hum; LCD_ShowCharh(200,100,hum+0x30,0); // 采样间隔设置 if (!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_12)) n=18000; //时级 if (!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_13)) goto loop;//清除 if (!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_14)) n=5; //秒级 if (!GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15)) n=300; //分级 For(m=0;m<n;m++) DelayMs(200); }}初识麒麟座mini开发板 https://www.eeboard.com/bbs/thread-96943-1-1.html
麒麟座开发板的开发环境构建及验证 https://www.eeboard.com/bbs/thread-97074-1-1.html
麒麟座开发板的OLED屏显示 https://www.eeboard.com/bbs/thread-97103-1-1.html
以麒麟座开发板实现温湿度控制 https://www.eeboard.com/bbs/thread-97137-1-1.html
以麒麟座开发板实现温湿度曲线显示 https://www.eeboard.com/bbs/thread-97190-1-1.html |
|