- void lcd_change()
- {
- yuyy_hs12864g18b_clear_screen(&hs12864_dev);
- if(mode == 0)
- {
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,0,0,(uint8_t *)" AT32F423 TEST ");
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,2,0,(uint8_t *)" WELCOME ");
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,4,0,(uint8_t *)" Press userkey ");
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,6,0,(uint8_t *)"Code by yuyy1989");
- }
- else if(mode == 1)
- {
- bmp280_readpress();
- dht11_readHT();
- }
- else
- {
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,2,0,(uint8_t *)" Wait data ");
- }
- }
第2页显示时钟和传感器数据
- uint8_t *WeekdayStr[7]= {"SUN","MON","TUE","WED","THU","FRI","SAT"};
- void showtime()
- {
- ertc_time_type time;
- char out[20];
- ertc_calendar_get(&time);
- if(mode != 1)
- return;
- sprintf(out," 20%02d-%02d-%02d %s ",time.year, time.month, time.day,WeekdayStr[time.week%7]);
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,0,0,(uint8_t *)out);
- sprintf(out," %02d:%02d:%02d ",time.hour, time.min, time.sec);
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,2,0,(uint8_t *)out);
- }
- void bmp280_readpress()
- {
- float temp,press;
- char out[20];
- temp = yuyy_bmp280_readtemp(&bmp280_dev);
- press = yuyy_bmp280_readpress(&bmp280_dev);
- if(mode != 1)
- return;
- sprintf(out," %.1fPa",press);
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,6,0,(uint8_t *)out);
- }
- void dht11_readHT()
- {
- float humi,temp;
- char out[20];
- uint8_t outlen;
- uint8_t result = yuyy_dht11_readHT(&dht11_dev,&temp,&humi);
- if(YUYY_DHT11_OK == result)
- {
- if(mode != 1)
- return;
- outlen = sprintf(out," %.1f%% %.1f",humi,temp);
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,4,0,(uint8_t *)out);
- yuyy_hs12864g18b_display_graphic_16x16(&hs12864_dev,0,4,8*outlen,(uint8_t *)test16x16temp);
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,4,8*(outlen+2),(uint8_t *)" ");
- }
- }
第3页显示电脑CPU内存占用和网速,通过串口接收上位机发送过来的数据并显示
- uint8_t lcdhead[4] = {'L','C','D',':'};
- uint8_t lcdbuf[4][17] = {0};
- uint8_t lcdheadindex = 0;
- uint8_t lcdrowindex = 0;
- uint8_t lcdcolindex = 0;
- uint8_t lcd_showflag = 0;
- void uart_receivebyte(uint8_t dat)
- {
- if(lcdheadindex < 4)
- {
- if(dat == lcdhead[lcdheadindex])
- lcdheadindex += 1;
- else
- lcdheadindex = 0;
- }
- else
- {
- if(dat == '\n')
- {
- lcd_showflag = 1;
- }
- else if(dat == '#')
- {
- lcdrowindex += 1;
- lcdcolindex = 0;
- }
- else if(lcdrowindex < 4 && lcdcolindex < 16)
- {
- lcdbuf[lcdrowindex][lcdcolindex] = dat;
- lcdcolindex += 1;
- }
- }
- }
- void procLcddata()
- {
- if(mode != 2)
- return;
- uint8_t i = 0;
- while(i<4)
- {
- yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,i*2,0,lcdbuf[i]);
- i += 1;
- }
- memset(lcdbuf,' ',68);
- lcdbuf[0][16] = 0;
- lcdbuf[1][16] = 0;
- lcdbuf[2][16] = 0;
- lcdbuf[3][16] = 0;
- lcdheadindex = 0;
- lcdrowindex = 0;
- lcdcolindex = 0;
- }
运行效果