欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: STM32F103使用U8G2庫 [打印本頁]

作者: roc2    時間: 2018-8-1 19:09
標題: STM32F103使用U8G2庫
U8G2軟件庫在OLED、lcd等模塊中使用非常的方便,支持的型號也比較多,不用自己每次寫自己的顯示屏驅動程序,下面介紹下載stm32上使用U8G2庫進行一些圖形和文字的顯示。
首先要下載好U8G2的庫,此處在附件中就可以下載到(庫和完整工程代碼請到零知原貼中下載)。下載到附件后,我們主要在u8g_arm.c中根據模板寫出跟我們硬件相關的接口即可,下面以SSD1306,使用4線方式的OLED接口為例。
我們把下載的庫放到我們的工程目錄下,然后在keil中添加到工程,然后我們在u8g_arm.c文件中編寫如下代碼:
  1. uint8_t u8g2_gpio_and_delay_stm32(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)  
  2. {
  3.                 uint8_t delay_cnt;
  4.       
  5.         switch(msg){  
  6.   
  7.         //Function which implements a delay, arg_int contains the amount of ms  
  8.         case U8X8_MSG_GPIO_AND_DELAY_INIT:  
  9.   
  10.         //oled_gpio_init();
  11.                 oled_io_config();
  12.   
  13.         break;  
  14.         //Function which implements a delay, arg_int contains the amount of ms  
  15.         case U8X8_MSG_DELAY_MILLI:  
  16.         delay_ms(arg_int);  
  17.         break;  
  18.         //Function which delays 10us  
  19.         case U8X8_MSG_DELAY_10MICRO:  
  20.         delay_us(10);  
  21.         break;  
  22.         //Function which delays 100ns  
  23.         case U8X8_MSG_DELAY_100NANO:  
  24.         //__NOP();  
  25.                 {
  26.                         delay_cnt = 0;
  27.                         while(delay_cnt++<10);
  28.                 }
  29.   
  30.         break;  
  31.         //Function to define the logic level of the clockline  
  32.         case U8X8_MSG_GPIO_SPI_CLOCK:  
  33.             if (arg_int) OLED_SCL = 1;  
  34.             else OLED_SCL = 0;  
  35.   
  36.         break;  
  37.         //Function to define the logic level of the data line to the display  
  38.         case U8X8_MSG_GPIO_SPI_DATA:  
  39.             if (arg_int) OLED_SDA = 1;  
  40.             else OLED_SDA = 0;  
  41.   
  42.         break;  
  43.   
  44.         // Function to define the logic level of the CS line  
  45.         case U8X8_MSG_GPIO_CS1:  
  46.   
  47.         break;  
  48.         //Function to define the logic level of the Data/ Command line  
  49.         case U8X8_MSG_GPIO_DC:
  50.                         if(arg_int) OLED_DC = 1;
  51.                         else OLED_DC = 0;
  52.   
  53.         break;  
  54.         //Function to define the logic level of the RESET line  
  55.         case U8X8_MSG_GPIO_RESET:  
  56.             if (arg_int) OLED_RS = 1;  
  57.             else OLED_RS = 0;  
  58.   
  59.         break;  
  60.          
  61.         default:  
  62.             return 0; //A message was received which is not implemented, return 0 to indicate an error  
  63.     }  
  64.   
  65.     return 1; // command processed successfully.  
  66. }
復制代碼
這個就是定義好硬件上連接gpio和延時的操作接口 。此處我們使用的是模擬spi方式,沒有使用硬件SPI接口,因此使用自帶的操作接口u8x8_byte_4wire_sw_spi就可以了,不用自己實現。然后我們在main中就可以調用跟我們相關的型號就可以操作OLED了,我這里調用u8g2_Setup_ssd1306_128x64_noname_f這個接口,實際情況要根據我們的顯示屏的型號來選擇了。我們就可以看到如下的顯示效果,非常的方便:







作者: roc2    時間: 2018-8-2 00:28
下一步準備移植到我們零知平臺上
作者: 木森林的年輪    時間: 2019-1-27 16:39
你好,請問內存不夠你是怎么解決的?

作者: 笑淺    時間: 2019-3-9 23:54
好,試下

作者: lrf32535604    時間: 2019-10-23 16:41
請問有12864的嗎
作者: zhangyucheng    時間: 2020-7-18 17:36
請問附件在哪里下載,謝謝




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1