Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Sensor_传感器框架
先楫HPM_RISCV
【24嵌入式设计大赛】基于RT-Thread的的桌面温湿度计
发布于 2024-09-17 12:11:12 浏览:293
订阅该版
[tocm] 下面是我的作品温湿度计显示。主要使用HPM5300开发板,加上温湿度传感器SHTC3和oled显示。实物如下: ![screenshot_dbb6957e0970b6e504b8ebdacd57540.jpg](https://oss-club.rt-thread.org/uploads/20240916/eb9dcfa8f77f2bc76785be6051345ebf.jpg.webp) ## 主要功能: 这次设计比较简单,主要是读取温湿度传感器并显示。使用硬件平台是先楫的HPM5300-evk开发板,温湿度传感器SHTC3,SSD1306驱动OLED显示。使用I2C0接口接温湿度传感器和OLED显示屏。传感器和oled屏单独做了一块小板,板上还有光照传感器和加速度传感器还未用上。传感器都简单对接了RT-Thread的sensor传感器框架,可以通过传感器设备读取数据。 整个代码在vscode开发,使用env编译,使用先楫的HPMicro_Manufacturing_Tool工具下载固件。所有应用代码在applications文件夹。 ![screenshot_image.png](https://oss-club.rt-thread.org/uploads/20240917/1f56d86d474603632d973005a72b78b5.png.webp) ### 应用软件流程: 在main中启动一个应用线程用于读取传感器数据并显示在OLED屏。 main线程 ```c void thread_entry(void *arg); int main(void) { static uint32_t app_thread_arg = 0; rt_thread_t led_thread = rt_thread_create("app_thread", thread_entry, &app_thread_arg, 1024, 1, 10); rt_thread_startup(led_thread); rt_pin_mode(APP_LED0_PIN_NUM, PIN_MODE_OUTPUT); while(1) { rt_pin_write(APP_LED0_PIN_NUM, APP_LED_ON); rt_thread_mdelay(500); rt_pin_write(APP_LED0_PIN_NUM, APP_LED_OFF); rt_thread_mdelay(100); } return 0; } ``` ### 应用线程: ```c void thread_entry(void *arg) { rt_device_t dev_temp = RT_NULL; rt_device_t dev_humi = RT_NULL; struct rt_sensor_data data; rt_uint8_t buff[16]; int temp,humi; int ground_pos; int i,j; ground_pos = 0; shtc3_port(); rpr0521_port(); adxl345_port(); rt_kprintf("ssd1306 %#x.\r\n",lcd_display_init(&oled_ssd1306)); lcd_set_font_window(0,0,lcd_get_width(),lcd_get_height()); lcd_clear(LCD_WHITE); lcd_display_flush(&oled_ssd1306); rt_thread_mdelay(100); lcd_clear(LCD_BLACK); lcd_set_font(&Font_ASCII16X8_default); lcd_disp_str_at(0,2,"RT-Thread"); lcd_disp_str_at(0,20,"HPM5300"); lcd_disp_str_at(0,40,"WoodData"); oled_qrcode(74, 5, "RT-Thread桌面温湿度计"); rt_thread_mdelay(3000); dev_temp = rt_device_find("temp_shtc3"); if (dev_temp == RT_NULL) { LOG_E("Can't find device:temp_shtc3"); }else { if (rt_device_open(dev_temp, RT_DEVICE_FLAG_RDONLY) != RT_EOK) { LOG_E("open temp_shtc3 device failed!"); }else rt_device_control(dev_temp, RT_SENSOR_CTRL_SET_ODR, (void *)100); } dev_humi = rt_device_find("humi_shtc3"); if (dev_humi == RT_NULL) { LOG_E("Can't find device:humi_shtc3"); }else { if (rt_device_open(dev_humi, RT_DEVICE_FLAG_RDONLY) != RT_EOK) { LOG_E("open humi_shtc3 device failed!"); }else rt_device_control(dev_humi, RT_SENSOR_CTRL_SET_ODR, (void *)100); } lcd_clear(LCD_BLACK); lcd_draw_image(0,0,24,24,(uint8_t*)temperature_code); lcd_draw_image(0,26,24,24,(uint8_t*)humidity_code); while(1) { if ((dev_temp != RT_NULL) && (rt_device_read(dev_temp, 0, &data, 1) != 1)) { LOG_E("read data failed!"); }else { temp = data.data.temp; } rt_thread_mdelay(10); if ((dev_humi != RT_NULL) && (rt_device_read(dev_humi, 0, &data, 1) != 1)) { LOG_E("read data failed!"); }else { humi = data.data.humi; } lcd_set_font(&Font_ASCII_Num12x20); rt_snprintf(buff,10,"%3d.%d\xA1\xE6",temp/10,temp%10); lcd_disp_str_at(32,2,buff); rt_snprintf(buff,10,"%3d.%d%% ",humi/10,humi%10); lcd_disp_str_at(32,28,buff); lcd_display_flush(&oled_ssd1306); for(j=0;j<40;j++) { for(i=0;i<10;i++) { lcd_draw_image(i*16 - ground_pos,56,16,8,(uint8_t *)Ground_n); } lcd_draw_image(20,46,16,16,(uint8_t *)dino16x16); lcd_display_flush(&oled_ssd1306); ground_pos += 4; if(ground_pos >= 16) ground_pos = 0; rt_thread_mdelay(50); } } } ``` i2c接口封装了rt-thread的I2C发送接收函数API。方便各种I2C接口芯片驱动。 ```c uint8_t I2C_WriteByte(void *i2cbus,uint32_t dev_addr, uint32_t addr,uint8_t Byte); uint8_t I2C_ReadByte (void *i2cbus,uint32_t dev_addr, uint32_t addr); uint8_t I2C_PageWrite(void *i2cbus,uint32_t dev_addr, uint32_t addr,uint8_t *str,uint32_t num); uint8_t I2C_PageRead (void *i2cbus,uint32_t dev_addr, uint32_t addr,uint8_t *str,uint32_t num); uint8_t I2C_Write(void *i2cbus,uint32_t dev_addr, uint8_t *cmd,uint32_t len,uint8_t *str,uint32_t num); uint8_t I2C_Read (void *i2cbus,uint32_t dev_addr, uint8_t *cmd,uint32_t len,uint8_t *str,uint32_t num); uint8_t I2C_WriteOnly(void *i2cbus,uint32_t dev_addr,uint8_t *str,uint32_t num); uint8_t I2C_ReadOnly (void *i2cbus,uint32_t dev_addr,uint8_t *str,uint32_t num); uint8_t I2C_IsDeviceReady(void *i2cbus,uint32_t dev_addr); void * I2C_FindDevice(char *name); ``` 温湿度传感器对接sensor框架接口。 ```c #define DBG_ENABLE #define DBG_LEVEL DBG_INFO #define DBG_SECTION_NAME "sensor.sr.shtc3" #define DBG_COLOR #include
#define SENSOR_HUMI_RANGE_MAX 100 #define SENSOR_HUMI_RANGE_MIN 0 #define SENSOR_TEMP_RANGE_MAX 60 #define SENSOR_TEMP_RANGE_MIN (-20) static rt_size_t shtc3_polling_get_data(rt_sensor_t sensor, struct rt_sensor_data *data) { int temperature,humidity; if(SHTC3_GetMode1_TempRH(&temperature, &humidity)) return 0; rt_kprintf("shtc3:t=%#x \t rh=%#x \r\n",temperature,humidity); if (sensor->info.type == RT_SENSOR_CLASS_TEMP) { data->type = RT_SENSOR_CLASS_TEMP; data->data.temp = temperature; data->timestamp = rt_sensor_get_ts(); } else if (sensor->info.type == RT_SENSOR_CLASS_HUMI) { data->type = RT_SENSOR_CLASS_HUMI; data->data.humi = humidity; data->timestamp = rt_sensor_get_ts(); } else { LOG_E("only RT_SENSOR_CLASS_TEMP,RT_SENSOR_CLASS_HUMI could get"); return 0; } return 1; } static rt_ssize_t shtc3_fetch_data(struct rt_sensor_device *sensor, void *buf, rt_size_t len) { RT_ASSERT(buf); if (sensor->config.mode == RT_SENSOR_MODE_POLLING) { return shtc3_polling_get_data(sensor, buf); } else { LOG_E("only RT_SENSOR_MODE_POLLING could get"); return 0; } } static rt_err_t shtc3_control(struct rt_sensor_device *sensor, int cmd, void *args) { rt_err_t result = RT_EOK; switch (cmd) { case RT_SENSOR_CTRL_GET_ID: uint32_t *p = args; *p = shtc3_id; break; case RT_SENSOR_CTRL_SET_RANGE: result = -RT_ERROR; break; case RT_SENSOR_CTRL_SET_ODR: result = -RT_ERROR; break; case RT_SENSOR_CTRL_SET_MODE: break; case RT_SENSOR_CTRL_SET_POWER: break; case RT_SENSOR_CTRL_SELF_TEST: result = -RT_ERROR; break; default: // LOG_E("only RT_SENSOR_CTRL_GET_ID,RT_SENSOR_CTRL_SET_POWER could set"); return -RT_ERROR; } return result; } static struct rt_sensor_ops sensor_ops = { shtc3_fetch_data, shtc3_control, }; ``` 对于SSD1306的OLED显示,我未使用rt-thread的软件包SSD1306,而是参考后使用自己写的lcd简易显示框架。方便对接各种lcd显示以及各种显示字体。而且统一了一般的基础画图API操作。 下面是框架的结构体 ```c /*---------------------- Graphic LCD color definitions -----------------------*/ /* Color coding (16-bit): 15..11 = R4..0 (Red) 10..5 = G5..0 (Green) 4..0 = B4..0 (Blue) */ /* GLCD RGB color definitions */ #define RGB565(r,g,b) ((((uint32_t)(r)&0xf8)<<8)|(((uint32_t)(g)&0xfc)<<3)|((uint32_t)(b)&0xf8)>>3) #define RGB888(r,g,b) (((uint32_t)(r)<<16)|((uint32_t)(g)<<8)|(uint32_t)(b)) typedef uint32_t lcd_color_t; #define RGB(r,g,b) RGB888(r,g,b) #define LCD_BLACK RGB( 0, 0, 0) /* 0, 0, 0 */ #define LCD_NAVY RGB( 0, 0,128) /* 0, 0, 128 */ #define LCD_DARK_GREEN RGB( 0,128, 0) /* 0, 128, 0 */ #define LCD_DARK_CYAN RGB( 0,128,128) /* 0, 128, 128 */ #define LCD_MAROON RGB(128, 0, 0) /* 128, 0, 0 */ #define LCD_PURPLE RGB(128, 0,128) /* 128, 0, 128 */ #define LCD_OLIVE RGB(128,128, 0) /* 128, 128, 0 */ #define LCD_LIGHT_GREY RGB(192,192,192) /* 192, 192, 192 */ #define LCD_DARK_GREY RGB(128,128,128) /* 128, 128, 128 */ #define LCD_BLUE RGB( 0, 0,255) /* 0, 0, 255 */ #define LCD_GREEN RGB( 0,255, 0) /* 0, 255, 0 */ #define LCD_CYAN RGB( 0,255,255) /* 0, 255, 255 */ #define LCD_RED RGB(255, 0, 0) /* 255, 0, 0 */ #define LCD_MAGENTA RGB(255, 0,255) /* 255, 0, 255 */ #define LCD_YELLOW RGB(255,255, 0) /* 255, 255, 0 */ #define LCD_WHITE RGB(255,255,255) /* 255, 255, 255 */ ///////////////////////////////////////////////////////////////////////////////////////////////// typedef struct lcd_point_t { int32_t x; int32_t y; }lcd_point_t; typedef struct lcd_area_size_t { uint32_t width; uint32_t height; }lcd_area_size_t; typedef struct lcd_info_t { int16_t sx; int16_t sy; uint16_t width; // uint16_t height; // uint32_t color_bit :6; //1,2,4,8,16,24,32bit uint32_t color_type :6; // }lcd_info_t; typedef struct lcd_draw_opt_t { lcd_color_t (*get_point) (int16_t x, int16_t y ); uint32_t (*set_point) (int16_t x, int16_t y, lcd_color_t color); //set_point or fill uint32_t (*clear) (lcd_color_t color); uint32_t (*h_line) (int16_t x1, int16_t y1, int16_t x2, lcd_color_t color); uint32_t (*v_line) (int16_t x1, int16_t y1, int16_t y2, lcd_color_t color); uint32_t (*line) (int16_t x1, int16_t y1, int16_t x2, int16_t y2, lcd_color_t color); uint32_t (*fill) (int16_t x, int16_t y, uint16_t w, uint16_t h, lcd_color_t color); //set_point or fill uint32_t (*draw_bmp) (uint8_t mode, int16_t x, int16_t y, uint16_t w, uint16_t h, const uint8_t *bmp); //must uint32_t (*draw_char_bmp)(uint8_t mode, int16_t x, int16_t y, uint16_t w, uint16_t h, const uint8_t *buff,lcd_color_t f_color,lcd_color_t b_color); //must }lcd_draw_opt_t; typedef struct lcd_func_opt_t { uint32_t (*init)(void *args); //must uint32_t (*flush)(void *args); uint32_t (*get_backlight) (void); uint32_t (*set_backlight) (uint8_t light); }lcd_func_opt_t; typedef struct lcd_bmp_t { lcd_info_t bmp_info; uint16_t lcd_bmp_child_type :1; //use struct lcd_bmp_t *c uint16_t lcd_buffer_type :2; //use 0,1,2,3 union{ struct lcd_bmp_t *c; uint8_t *p8bmpbuff; //0 uint16_t *p16bmpbuff; //1 uint32_t *p32bmpbuff; //2 uint32_t pcolor; //3 }bmpbuff; }lcd_bmp_t; typedef struct lcd_text_opt_t { uint32_t (*text_init) (void); uint32_t (*text_clear) (void); uint32_t (*text_flush) (void); uint32_t (*text_line) (int16_t sx, int16_t line, char * str); uint32_t (*text_at) (int16_t tx, int16_t ty, char * str); uint32_t (*text_bmp) (int16_t tx, int16_t ty, lcd_bmp_t * bmp); }lcd_text_opt_t; typedef struct lcd_adapter_t { lcd_info_t info; lcd_draw_opt_t draw; lcd_func_opt_t func; // lcd_text_opt_t text; int16_t sx; int16_t sy; uint16_t width; uint16_t height; uint32_t backlight : 8; uint32_t color_bit : 6; //1,2,4,8,16,24,32bit uint32_t color_type : 6; // }lcd_adapter_t; ``` 主要对接lcd_adapter_t结构来操作LCD显示。 下面是通用的API应用操作: ```c uint32_t lcd_display_init(void *args); uint32_t lcd_display_flush(void *args); uint32_t lcd_set_backlight(uint8_t light); uint32_t lcd_get_backlight(void); uint32_t lcd_set_color_type(uint8_t flag); uint32_t lcd_set_color_bit(uint8_t flag); uint32_t lcd_set_window(int16_t sx,int16_t sy,uint16_t width,uint16_t height); uint32_t lcd_reset_window(void); uint32_t lcd_get_width(void); uint32_t lcd_get_height(void); uint32_t lcd_clear(lcd_color_t color); uint32_t lcd_draw_point(int16_t x, int16_t y, lcd_color_t color); uint32_t lcd_draw_line(int16_t x1, int16_t y1, int16_t x2, int16_t y2, lcd_color_t color); uint32_t lcd_draw_circle(int16_t x, int16_t y, uint16_t r,lcd_color_t color); uint32_t lcd_draw_rect(int16_t x, int16_t y, uint16_t w, uint16_t h, lcd_color_t color); uint32_t lcd_draw_polyline(const lcd_point_t *par_vertex, uint32_t par_size, lcd_color_t color); uint32_t lcd_draw_arc(int16_t x, int16_t y, uint16_t radius, uint16_t start_angle, uint16_t sweep, lcd_color_t color); uint32_t lcd_fill_rect(int16_t x, int16_t y, uint16_t w, uint16_t h, lcd_color_t color); uint32_t lcd_fill_circle(int16_t x, int16_t y, uint16_t r,lcd_color_t color); uint32_t lcd_draw_image(int16_t x, int16_t y, uint16_t w, uint16_t h, uint8_t *bmp); uint32_t lcd_draw_char_dot(int16_t x, int16_t y, uint16_t w, uint16_t h,const uint8_t *buff,lcd_color_t f_color,lcd_color_t b_color); uint32_t lcd_draw_bmp(int16_t x, int16_t y, uint16_t w, uint16_t h, lcd_bmp_t *bmp); uint32_t lcd_draw_char_bmp(int16_t x, int16_t y, uint16_t w, uint16_t h,const lcd_bmp_t *bmp,lcd_color_t f_color,lcd_color_t b_color); ``` 其中oled主要对接接口如下: ```c // Fill the whole screen with the given color uint32_t ssd1306_Fill(lcd_color_t color) { uint32_t i; for(i = 0; i < sizeof(SSD1306_Buffer); i++) { SSD1306_Buffer[i] = (color == LCD_BLACK) ? 0x00 : 0xFF; } return 0; } // Write the screenbuffer with changed to the screen uint32_t ssd1306_UpdateScreen(void *args) { // Write data to each page of RAM. Number of pages // depends on the screen height: // // * 32px == 4 pages // * 64px == 8 pages // * 128px == 16 pages for(uint8_t i = 0; i < SSD1306_HEIGHT/8; i++) { ssd1306_WriteCommand(0xB0 + i); // Set the current RAM page address. ssd1306_WriteCommand(0x00); ssd1306_WriteCommand(0x10); ssd1306_WriteData(&SSD1306_Buffer[SSD1306_WIDTH*i],SSD1306_WIDTH); } return 0; } // Draw one pixel in the screenbuffer // X => X Coordinate // Y => Y Coordinate // color => Pixel color uint32_t ssd1306_DrawPixel(int16_t x, int16_t y, lcd_color_t color) { if(x < 0 || x >= SSD1306_WIDTH || y< 0 || y >= SSD1306_HEIGHT) { // Don't write outside the buffer return 1; } if(color == LCD_BLACK) { SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] &= ~(1 << (y % 8)); } else { SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] |= 1 << (y % 8); } return 0; } uint32_t ssd1306_DrawCharDot(uint8_t mode, int16_t x,int16_t y,uint16_t w,uint16_t h,const uint8_t *buff,lcd_color_t f_color,lcd_color_t b_color) { uint8_t markbit; uint32_t i, j; uint8_t *b= (uint8_t *)buff; if((x >= SSD1306_WIDTH) || (y >= SSD1306_HEIGHT) || ((x+w)<=0) || ((y+h)<=0)) return 1; switch(mode) { case 0: for(i = 0; i < h; i++) { for(j = 0; j < w;) { if((*b << (j%8)) & 0x80) { ssd1306_DrawPixel(x + j, (y + i), f_color); } else { ssd1306_DrawPixel(x + j, (y + i), b_color); } j++; if(!(j%8)) b++; } if(w%8) b++; } break; case 1: for(i = 0; i < h; i++) { for(j = 0; j < w;) { if((*b >> (j%8)) & 0x01) { ssd1306_DrawPixel(x + j, (y + i), f_color); } else { ssd1306_DrawPixel(x + j, (y + i), b_color); } j++; if(!(j%8)) b++; } if(w%8) b++; } break; case 2: for(i = 0; i < w; i++) { for(j = 0; j < h;) { if((*b << (j%8)) & 0x80) { ssd1306_DrawPixel(x + i, (y + j), f_color); } else { ssd1306_DrawPixel(x + i, (y + j), b_color); } j++; if(!(j%8)) b++; } if(h%8) b++; } break; case 3: for(i = 0; i < w; i++) { for(j = 0; j < h;) { if((*b >> (j%8)) & 0x01) { ssd1306_DrawPixel(x + i, (y + j), f_color); } else { ssd1306_DrawPixel(x + i, (y + j), b_color); } j++; if(!(j%8)) b++; } if(h%8) b++; } break; } return 0; } uint32_t ssd1306_DrawImage(uint8_t mode, int16_t x,int16_t y,uint16_t w,uint16_t h,const uint8_t *buff) { return ssd1306_DrawCharDot(mode,x,y,w,h,buff,LCD_WHITE,LCD_BLACK); } ``` ssd1306 oled对接的lcd_adapter_t结构如下。 ```c lcd_adapter_t oled_ssd1306= { .info.sx = 0, .info.sy = 0, .info.width = SSD1306_WIDTH, .info.height = SSD1306_HEIGHT, .info.color_bit = 1, .info.color_type = 0, .func.init = ssd1306_Init, .func.flush = ssd1306_UpdateScreen, .func.get_backlight = NULL, .func.set_backlight = ssd1306_SetDisplayOn, .draw.get_point = NULL, .draw.set_point = ssd1306_DrawPixel, .draw.clear = ssd1306_Fill, .draw.h_line = NULL, .draw.v_line = NULL, .draw.line = NULL, .draw.fill = NULL, .draw.draw_bmp = ssd1306_DrawImage, .draw.draw_char_bmp = ssd1306_DrawCharDot, }; ``` 字体显示对接框架如下: ```c /* type define ------------------------------------------------------------*/ typedef struct lcd_font_t { uint16_t font_height; //font height uint16_t font_width; //font width =0:call get_font_w() get width. uint16_t font_buffer_size; //char dot buffer size uint16_t font_buffer_cnt; //char dot buffer size number uint8_t * pfont_buff; //font char dot buffer pointer char * pfont_filename; //font buffer dot file name uint16_t (* get_font_w)(uint32_t ch); //get char width void (* draw_char)(int16_t x,int16_t y,uint32_t ch); // }lcd_font_t; typedef struct lcd_font_display_t { lcd_font_t *pfont; //dispaly char font pointer lcd_color_t font_fore; //dispaly char front color lcd_color_t font_back; //dispaly char back color uint16_t font_dx; //Character spacing uint16_t font_dy; //vertical spacing int16_t font_x; //dispaly char area start x int16_t font_y; //dispaly char area start y uint16_t font_w; //dispaly char area width uint16_t font_h; //dispaly char area height uint16_t str_encode; //char code��ASCII,GBK,UTF8... }lcd_font_display_t; typedef struct font_char_code_t { uint32_t ch; uint8_t * buf_code; }font_char_code_t; //API lcd_font_t * lcd_set_font( const lcd_font_t *newfont); lcd_font_t * lcd_get_font(void); void lcd_set_font_color(lcd_color_t fore, lcd_color_t back); lcd_color_t lcd_get_font_color_fore(void); lcd_color_t lcd_get_font_color_back(void); void lcd_set_font_window(int16_t x,int16_t y,uint16_t w,uint16_t h); void lcd_disp_char_at(int16_t usX, int16_t usY, uint32_t cChar); void lcd_disp_str_at(int16_t usX, int16_t usY, const char *pStr); void lcd_display_string(int16_t x, int16_t y, const char *pStr, const lcd_font_t * font,lcd_color_t fore, lcd_color_t back); ``` 下面是对接一个裁剪的字体显示例子: ```c const uint8_t font_num_code_12x20[18][40]= { //0x0020( ) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,}, //0x0025(%) {0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x30,0x88,0x60,0x88,0xC0,0x89,0xC0,0x89,0x80, 0x73,0x00,0x06,0x00,0x06,0x00,0x0D,0xC0,0x1A,0x20,0x3A,0x20,0x32,0x20,0x62,0x20, 0xC1,0xC0,0x00,0x00,0x00,0x00,0x00,0x00}, //0x002A(*) {0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x17,0x00,0x3F,0xE0,0x1F,0xC0,0x07,0x00, 0x1F,0xC0,0x3F,0xE0,0x17,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //0x002B(+) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x07,0x00, 0x07,0x00,0x07,0x00,0x7F,0xF0,0x7F,0xF0,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //0x002D(-) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //0x002E(.) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x0F,0x00,0x0F,0x00, 0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //0x002F(/) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x01,0xC0,0x01,0x80,0x03,0x80,0x03,0x00, 0x03,0x00,0x07,0x00,0x06,0x00,0x0E,0x00,0x0C,0x00,0x1C,0x00,0x18,0x00,0x18,0x00, 0x38,0x00,0x30,0x00,0x70,0x00,0x00,0x00}, //0x0030(0) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x80,0x1F,0xE0,0x38,0xE0,0x78,0xF0, 0x70,0xF0,0x73,0xF0,0x77,0x70,0x7E,0x70,0x78,0x70,0x78,0xF0,0x38,0xE0,0x1F,0xC0, 0x0F,0x80,0x00,0x00,0x00,0x00,0x00,0x00}, //0x0031(1) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x1F,0x00,0x3F,0x00,0x27,0x00, 0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x07,0x00,0x3F,0xE0, 0x3F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00}, //0x0032(2) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x7F,0x80,0x23,0xC0,0x01,0xC0, 0x01,0xC0,0x01,0xC0,0x03,0x80,0x07,0x00,0x0E,0x00,0x1C,0x00,0x38,0x00,0x7F,0xC0, 0x7F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00}, //0x0033(3) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x7F,0x80,0x43,0x80,0x03,0x80, 0x03,0x80,0x1F,0x00,0x1F,0x80,0x03,0xC0,0x01,0xC0,0x01,0xC0,0x43,0xC0,0x7F,0x80, 0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //0x0034(4) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x80,0x0F,0x80,0x1F,0x80,0x1B,0x80, 0x3B,0x80,0x33,0x80,0x63,0x80,0xE3,0x80,0xFF,0xE0,0xFF,0xE0,0x03,0x80,0x03,0x80, 0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00}, //0x0035(5) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xC0,0x3F,0xC0,0x38,0x00,0x38,0x00, 0x38,0x00,0x3F,0x80,0x3F,0xC0,0x01,0xE0,0x00,0xE0,0x00,0xE0,0x01,0xE0,0x3F,0xC0, 0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //0x0036(6) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,0x1F,0xC0,0x3C,0x00,0x38,0x00, 0x70,0x00,0x77,0x80,0x7F,0xC0,0x78,0xE0,0x70,0xE0,0x70,0xE0,0x39,0xE0,0x3F,0xC0, 0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00}, //0x0037(7) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xC0,0x7F,0xC0,0x01,0xC0,0x03,0x80, 0x03,0x80,0x03,0x00,0x07,0x00,0x06,0x00,0x0E,0x00,0x0E,0x00,0x1C,0x00,0x1C,0x00, 0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //0x0038(8) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x80,0x3F,0xE0,0x70,0xE0,0x70,0xE0, 0x79,0xE0,0x3F,0xC0,0x1F,0x80,0x3B,0xC0,0x70,0xE0,0x70,0xE0,0x70,0xE0,0x3F,0xC0, 0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00}, //0x0039(9) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x3F,0xC0,0x79,0xC0,0x70,0xE0, 0x70,0xE0,0x70,0xE0,0x3F,0xE0,0x1E,0xE0,0x00,0xE0,0x01,0xC0,0x03,0xC0,0x3F,0x80, 0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, //0x003A(:) {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00, 0x0F,0x00,0x0F,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x0F,0x00,0x0F,0x00, 0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, }; const uint8_t font_gbk_code_20x20[1][60]= { {0X30,0X00,0X00,0X48,0X00,0X00,0X48,0X1E,0X00,0X38,0X7F,0X00,0X00,0XC1,0X80,0X01,0X80,0XC0,0X01,0X00,0X00,0X03,0X00,0X00,0X03,0X00,0X00,0X03,0X00,0X00,0X03,0X00,0X00,0X03,0X00,0X00,0X01,0X00,0XC0,0X01,0X80,0XC0,0X00,0XC3,0X80,0X00,0X7F,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,}, }; #define ASCII_CHAR_NUM_LEN 19 //2E 2D 3A 25 2F 2B 2A .-:%/+* const font_char_code_t font_num_12x20[ASCII_CHAR_NUM_LEN]= { {0x20, (uint8_t *)font_num_code_12x20[0]}, {0x25, (uint8_t *)font_num_code_12x20[1]}, {0x2A, (uint8_t *)font_num_code_12x20[2]}, {0x2B, (uint8_t *)font_num_code_12x20[3]}, {0x2D, (uint8_t *)font_num_code_12x20[4]}, {0x2E, (uint8_t *)font_num_code_12x20[5]}, {0x2F, (uint8_t *)font_num_code_12x20[6]}, {0x30, (uint8_t *)font_num_code_12x20[7]}, {0x31, (uint8_t *)font_num_code_12x20[8]}, {0x32, (uint8_t *)font_num_code_12x20[9]}, {0x33, (uint8_t *)font_num_code_12x20[10]}, {0x34, (uint8_t *)font_num_code_12x20[11]}, {0x35, (uint8_t *)font_num_code_12x20[12]}, {0x36, (uint8_t *)font_num_code_12x20[13]}, {0x37, (uint8_t *)font_num_code_12x20[14]}, {0x38, (uint8_t *)font_num_code_12x20[15]}, {0x39, (uint8_t *)font_num_code_12x20[16]}, {0x3A, (uint8_t *)font_num_code_12x20[17]}, {0xA1E6, (uint8_t *)font_gbk_code_20x20[0]}, //℃ }; #define ASCII_W 12 #define ASCII_H 20 #define ASCII_BUFFER_LEN 40 #define GBK_W 20 #define GBK_BUFFER_LEN 60 static void lcd_disp_ascii_num_12x20(int16_t x, int16_t y, uint32_t usChar) { uint8_t ucBuffer[GBK_BUFFER_LEN] = {0}; lcd_font_t *pfont; font_char_code_t *pcodebuf; uint16_t width,height; uint32_t buf_len; pfont = lcd_get_font(); width = pfont->font_width; if(width == 0) width = pfont->get_font_w(usChar); height = pfont->font_height; if(usChar <= 0xff) buf_len = ASCII_BUFFER_LEN; else buf_len = GBK_BUFFER_LEN; for(int i=0;i< ASCII_CHAR_NUM_LEN;i++) { pcodebuf = (font_char_code_t *)pfont->pfont_buff; if(usChar == pcodebuf[i].ch) { memcpy(ucBuffer,pcodebuf[i].buf_code,buf_len); lcd_set_color_type(0); lcd_draw_char_dot(x,y,width,height,ucBuffer,lcd_get_font_color_fore(),lcd_get_font_color_back()); break; } } } static uint16_t ascii12x20_get_font_w(uint32_t ch) { if(ch <= 0xff) return ASCII_W; else return GBK_W; } const lcd_font_t Font_ASCII_Num12x20 = { ASCII_H, 0, sizeof(font_char_code_t), ASCII_CHAR_NUM_LEN, (uint8_t *)font_num_12x20, NULL, ascii12x20_get_font_w, lcd_disp_ascii_num_12x20, }; ``` 整体代码在gitee上地址: 仓库:https://gitee.com/water_source/rtt_hpm5361evk.git 演示视频:https://www.bilibili.com/video/BV13Ft8eYE94
0
条评论
默认排序
按发布时间排序
登录
注册新账号
关于作者
WoodData
这家伙很懒,什么也没写!
文章
1
回答
10
被采纳
0
关注TA
发私信
相关文章
1
有关多sensor设备的module定义结构体自调用的疑惑
2
ART-PI,使用vl53l0x软件包,报错
3
sensor传感器驱动框架中sensor.h疑问
4
SENSOR驱动框架的使用
5
请教RT-thread的传感器框架的使用
6
RT_THREAD使用线程读取传感器数据偶尔会失败
7
关于单总线传感器驱动问题
8
寻求sensor多种数据一次全采集的实现方式
9
设备dev是如何根据parameter找到的
10
max6675 热电偶接入sensor框架,间隔时间太短读出来数值不会变化
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
ART-Pi
FinSH
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
ESP8266
I2C_IIC
WIZnet_W5500
ota在线升级
UART
cubemx
PWM
flash
packages_软件包
freemodbus
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
ulog
C++_cpp
at_device
本月问答贡献
出出啊
1516
个答案
342
次被采纳
小小李sunny
1440
个答案
289
次被采纳
张世争
799
个答案
171
次被采纳
crystal266
547
个答案
161
次被采纳
whj467467222
1222
个答案
148
次被采纳
本月文章贡献
出出啊
1
篇文章
1
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
1
篇文章
4
次点赞
crystal266
2
篇文章
2
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
投诉
建议
回到
底部