[活动专区] 【AT-START-F423测评】8.综合应用实现简单的信息显示屏

[复制链接]
2029|7
 楼主| yuyy1989 发表于 2023-10-30 19:58 | 显示全部楼层 |阅读模式
#申请原创# @21小跑堂  

综合前面已经实现的功能用这些东西简单做一个信息显示屏
微信图片_20231030195641.jpg
显示屏分3个页面,用开发板上的按键进行切换
第1页显示一些欢迎信息

  1. void lcd_change()
  2. {
  3.     yuyy_hs12864g18b_clear_screen(&hs12864_dev);
  4.     if(mode == 0)
  5.     {
  6.         yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,0,0,(uint8_t *)" AT32F423 TEST  ");
  7.         yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,2,0,(uint8_t *)"    WELCOME     ");
  8.         yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,4,0,(uint8_t *)" Press userkey  ");
  9.         yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,6,0,(uint8_t *)"Code by yuyy1989");
  10.     }
  11.     else if(mode == 1)
  12.     {
  13.         bmp280_readpress();
  14.         dht11_readHT();
  15.     }
  16.     else
  17.     {
  18.         yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,2,0,(uint8_t *)"   Wait data    ");
  19.     }
  20. }
第2页显示时钟和传感器数据
  1. uint8_t *WeekdayStr[7]= {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  2. void showtime()
  3. {
  4.     ertc_time_type time;
  5.     char out[20];
  6.     ertc_calendar_get(&time);
  7.     if(mode != 1)
  8.         return;
  9.     sprintf(out," 20%02d-%02d-%02d %s ",time.year, time.month, time.day,WeekdayStr[time.week%7]);
  10.     yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,0,0,(uint8_t *)out);
  11.     sprintf(out,"    %02d:%02d:%02d    ",time.hour, time.min, time.sec);
  12.     yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,2,0,(uint8_t *)out);
  13. }
  14. void bmp280_readpress()
  15. {
  16.     float temp,press;
  17.     char out[20];
  18.     temp = yuyy_bmp280_readtemp(&bmp280_dev);
  19.     press = yuyy_bmp280_readpress(&bmp280_dev);
  20.      if(mode != 1)
  21.             return;
  22.     sprintf(out,"   %.1fPa",press);
  23.     yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,6,0,(uint8_t *)out);
  24. }
  25. void dht11_readHT()
  26. {
  27.     float humi,temp;
  28.     char out[20];
  29.     uint8_t outlen;
  30.     uint8_t result = yuyy_dht11_readHT(&dht11_dev,&temp,&humi);
  31.     if(YUYY_DHT11_OK == result)
  32.     {
  33.         if(mode != 1)
  34.             return;
  35.         outlen = sprintf(out,"  %.1f%% %.1f",humi,temp);
  36.         yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,4,0,(uint8_t *)out);
  37.         yuyy_hs12864g18b_display_graphic_16x16(&hs12864_dev,0,4,8*outlen,(uint8_t *)test16x16temp);
  38.         yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,4,8*(outlen+2),(uint8_t *)"   ");
  39.     }
  40. }
第3页显示电脑CPU内存占用和网速,通过串口接收上位机发送过来的数据并显示
  1. uint8_t lcdhead[4] = {'L','C','D',':'};
  2. uint8_t lcdbuf[4][17] = {0};
  3. uint8_t lcdheadindex = 0;
  4. uint8_t lcdrowindex = 0;
  5. uint8_t lcdcolindex = 0;
  6. uint8_t lcd_showflag = 0;
  7. void uart_receivebyte(uint8_t dat)
  8. {
  9.     if(lcdheadindex < 4)
  10.     {
  11.         if(dat == lcdhead[lcdheadindex])
  12.             lcdheadindex += 1;
  13.         else
  14.             lcdheadindex = 0;
  15.     }
  16.     else
  17.     {
  18.         if(dat == '\n')
  19.         {
  20.             lcd_showflag = 1;
  21.         }
  22.         else if(dat == '#')
  23.         {
  24.             lcdrowindex += 1;
  25.             lcdcolindex = 0;
  26.         }
  27.         else if(lcdrowindex < 4 && lcdcolindex < 16)
  28.         {
  29.             lcdbuf[lcdrowindex][lcdcolindex] = dat;
  30.             lcdcolindex += 1;
  31.         }
  32.     }
  33. }
  34. void procLcddata()
  35. {
  36.     if(mode != 2)
  37.             return;
  38.     uint8_t i = 0;
  39.     while(i<4)
  40.     {
  41.         yuyy_hs12864g18b_display_string_8x16(&hs12864_dev,0,i*2,0,lcdbuf[i]);
  42.         i += 1;
  43.     }
  44.     memset(lcdbuf,' ',68);
  45.     lcdbuf[0][16] = 0;
  46.     lcdbuf[1][16] = 0;
  47.     lcdbuf[2][16] = 0;
  48.     lcdbuf[3][16] = 0;
  49.     lcdheadindex = 0;
  50.     lcdrowindex = 0;
  51.     lcdcolindex = 0;
  52. }
运行效果


tpgf 发表于 2023-11-7 17:24 | 显示全部楼层
屏幕的刷新频率达到多少不会出现闪烁的情况呢
guanjiaer 发表于 2023-11-8 08:35 | 显示全部楼层
可以通过这种方式来现实一些系统实时运行的信息
木木guainv 发表于 2023-11-8 09:40 | 显示全部楼层
这种屏幕可以实现屏幕分辨率的自适应显示吗
xiaoqizi 发表于 2023-11-8 12:30 | 显示全部楼层
可以使用这个方式进行程序的监控
renzheshengui 发表于 2023-11-8 16:37 | 显示全部楼层
这个屏幕是 使用的串口通讯方式是吧
wakayi 发表于 2023-11-8 18:00 | 显示全部楼层
可以多加几个按钮 丰富显示的内容
您需要登录后才可以回帖 登录 | 注册

本版积分规则

认证:同飞软件研发工程师
简介:制冷系统单片机软件开发,使用PID控制温度

168

主题

826

帖子

10

粉丝
快速回复 在线客服 返回列表 返回顶部