0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

【RTT大賽作品連載】 OLED顯示圖片

閑來(lái)無(wú)事玩單片機(jī)呀 ? 來(lái)源:閑來(lái)無(wú)事玩單片機(jī)呀 ? 作者:閑來(lái)無(wú)事玩單片機(jī) ? 2021-12-06 09:17 ? 次閱讀

上一篇文章講了OLED文字顯示代碼:http://ttokpm.com/d/1749110.html

這片文章將講解如何用OLED顯示圖片,包括長(zhǎng)度為128像素,64像素,48像素,24像素,16像素的bmp單色圖片,各種像素的圖片可以根據(jù)自己的要求進(jìn)行修改,本文只是舉例。

一、生成圖片

找一張想要顯示的圖片,使用PS或者其他圖片處理工具將圖片變換成長(zhǎng)度為128像素大小。

本文使用電子發(fā)燒友的logo來(lái)實(shí)驗(yàn)。

1. 保存電子發(fā)燒有的圖片,并使用PS工具將圖片大小修改為128像素,寬度不用設(shè)置,然后打開(kāi)畫圖工具將圖片另存為單色bmp格式。

pYYBAGGrVViAZH3cAACmjBW2SK8945.png

2. 打開(kāi)PCtoLCD取模工具,選擇模式→圖形模式

pYYBAGGrVj2AWdLZAADk28Zft58910.png

3. 打開(kāi)圖片,選擇需要取模的圖片,然后點(diǎn)擊生成字模

poYBAGGrVkqALwIQAAI8ujCA-e4492.png

poYBAGGrVliAapJjAAJFFBeHI8k527.png

4. 將生成的字模復(fù)制到bmp.c中,放在EleFans_Logo數(shù)組中

const unsigned char EleFans_logo[][16] =
{
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x7F},
{0xC0,0x00,0x00,0x00,0x03,0xFF,0xF8,0x00,0x00,0x00,0x0F,0xF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00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFC,0x07,0x80,0x00,0x00},
{0x0F,0xFC,0x00,0x40,0x00,0x00,0x0C,0xCC,0x00,0x40,0x00,0x00,0x0C,0xCC,0x07,0xC0},
{0x00,0x00,0x0C,0xCC,0x00,0x40,0x00,0x00,0x0C,0xCC,0x00,0x40,0x00,0x00,0x1D,0xFE},
{0x07,0x80,0x00,0x00,0x1F,0xFF,0x80,0x00,0x00,0x00,0x1F,0xFF,0x87,0x80,0x00,0x00},
{0x0C,0xCC,0x80,0x40,0x00,0x00,0x0C,0xCC,0x80,0x40,0x00,0x00,0x0C,0xCC,0x87,0xC0},
{0x00,0x00,0x0F,0xFC,0x80,0x40,0x00,0x00,0x0F,0xFD,0x80,0x40,0x00,0x00,0x0F,0xB0},
{0x87,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x07,0x80,0x00,0x00},
{0x00,0x60,0x00,0x40,0x00,0x00,0x18,0x60,0x05,0x40,0x00,0x00,0x18,0x60,0x07,0xC0},
{0x00,0x00,0x18,0x60,0x00,0x40,0x00,0x00,0x18,0x60,0x87,0x80,0x00,0x00,0x18,0x60},
{0x80,0x00,0x00,0x00,0x18,0x61,0x80,0x40,0x00,0x00,0x18,0xFF,0x80,0x00,0x00,0x00},
{0x19,0xFF,0x03,0x80,0x00,0x00,0x1F,0xE0,0x05,0x40,0x00,0x00,0x1E,0x60,0x05,0x40},
{0x00,0x00,0x1C,0x60,0x05,0x40,0x00,0x00,0x18,0x60,0x03,0x40,0x00,0x00,0x00,0x60},
{0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x1E,0x03,0x83,0x80,0x00,0x00,0x1E,0x1F,0x85,0x40,0x00,0x00,0x07,0xFC,0x05,0x40},
{0x00,0x00,0x07,0xE0,0x85,0x40,0x00,0x00,0x1F,0xC1,0x83,0x40,0x00,0x00,0x1E,0xD9},
{0x81,0x00,0x00,0x00,0x06,0xDF,0x80,0x00,0x00,0x00,0x06,0xC7,0x02,0x00,0x00,0x00},
{0x06,0xC7,0x02,0x00,0x00,0x00,0x06,0xC7,0x0F,0xC0,0x00,0x00,0x06,0xDF,0x8A,0x00},
{0x00,0x00,0x0E,0xF9,0x8A,0x00,0x00,0x00,0x0E,0xF1,0x80,0x00,0x00,0x00,0x00,0x00},
{0x83,0x80,0x00,0x00,0x00,0x00,0x04,0x40,0x00,0x00,0x00,0x00,0x04,0x40,0x00,0x00},
{0x0F,0xE1,0x84,0xC0,0x00,0x00,0x00,0xFF,0x8F,0x40,0x00,0x00,0x1F,0xFE,0x00,0x40},
{0x00,0x00,0x0B,0xFF,0x00,0x00,0x00,0x00,0x07,0xE3,0x83,0xC0,0x00,0x00,0x0C,0x80},
{0x06,0x00,0x00,0x00,0x08,0x98,0x86,0x00,0x00,0x00,0x18,0x9F,0x83,0xC0,0x00,0x00},
{0x18,0x9E,0x00,0x00,0x00,0x00,0x1D,0x98,0x06,0x40,0x00,0x00,0x0F,0x98,0x05,0x40},
{0x00,0x00,0x0F,0x9F,0x85,0x40,0x00,0x00,0x09,0xDB,0x84,0xC0,0x00,0x00,0x09,0x99},
{0x80,0x00,0x00,0x00,0x09,0x10,0x00,0x40,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00},
{0x00,0x00,0x06,0xC0,0x00,0x00,0x0C,0x1F,0x84,0x40,0x00,0x00,0x0F,0xFF,0x84,0x40},
{0x00,0x00,0x1F,0xE0,0x00,0x00,0x00,0x00,0x1D,0x81,0x83,0x80,0x00,0x00,0x0D,0xB1},
{0x84,0x40,0x00,0x00,0x0D,0xBB,0x84,0x40,0x00,0x00,0x0D,0x9F,0x03,0x80,0x00,0x00},
{0x0D,0x8F,0x00,0x00,0x00,0x00,0x0D,0x87,0x07,0xC0,0x00,0x00,0x0D,0x8F,0x04,0x00},
{0x00,0x00,0x0D,0x9F,0x85,0x40,0x00,0x00,0x0D,0xF9,0x87,0x80,0x00,0x00,0x0D,0xE1},
{0x84,0x00,0x00,0x00,0x0C,0x81,0x87,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};

5. 在bmp.h中寫一個(gè)函數(shù)獲取圖片數(shù)據(jù)數(shù)組的大小,后邊顯示圖片的時(shí)候會(huì)使用到

unsigned int Get_EleFans_logo_len(void)
{
    return sizeof(EleFans_logo)/sizeof(unsigned char);
}

6. 在bmp.h中聲明數(shù)組與函數(shù),用于app_oled.c中調(diào)用

extern unsigned int Get_EleFans_logo_len(void);
extern const unsigned char EleFans_logo[][16];

二、圖片顯示函數(shù)編輯

根據(jù)取模規(guī)則,編寫圖片顯示函數(shù)

static void OLED_DrawBmpImg(uint8_t x,
uint8_t y,
SSD1306_COLOR color,
const uint8_t bmp[][16],
uint32_t len)
{
uint16_t t,t1;
uint8_t y0 = y;
uint8_t temp = 0u;
uint16_t len2 = (uint16_t)(len>>4u);

for(t=0; t {
temp=(White == color) ?
(bmp[(uint8_t)(t/16)][(uint8_t)(t%16)]):(~bmp[(uint8_t)(t/16)][(uint8_t)(t%16)]);;>

for(t1=0; t1<8; t1++)
{
if(temp&0x80)
ssd1306_DrawPixel(x, y, White);

temp <<= 1u;
y++;
if((y-y0) == len2)
{
y = y0;
x ++;
break;
}
}
}
}

三、對(duì)顯示圖片函數(shù)進(jìn)行改進(jìn),可以顯示不同規(guī)格的圖片,其中size是圖片的長(zhǎng)度,目前支持16,24,48,64長(zhǎng)度的圖片的顯示

static void OLED_DrawBmpImg2(uint8_t x,
uint8_t y,
SSD1306_COLOR color,
const uint8_t bmp[][8],
uint32_t len,
uint8_t size)
{
uint16_t t, t1;
uint8_t y_end;
uint8_t temp;
uint16_t len2 = 0u;

y_end = y;

if(size == 24)
len2 = (uint16_t)(len/3.2);
else if(size == 16)
len2 = (uint16_t)(len/2);
else if(size == 48)
len2 = (uint16_t)(len/6);
else if(size == 64)
len2 = (uint16_t)(len/16);

for(t=0; t {
temp=(White == color) ?
(bmp[(uint8_t)(t/8)][(uint8_t)(t%8)]):(~bmp[(uint8_t)(t/8)][(uint8_t)(t%8)]);;>

for(t1=0; t1<8; t1++)
{
if(temp&0x80)
ssd1306_DrawPixel(x, y, White);

temp <<= 1u;
y++;
if((y-y_end) == len2)
{
y = y_end;
x ++;
break;
}
}
}
}

四、顯示電子發(fā)燒友logo

    ssd1306_Fill(Black);
    OLED_DrawBmpImg(0, 10, White, EleFans_logo, Get_EleFans_logo_len());
    ssd1306_UpdateScreen();

五、效果

1.下圖是顯示的電子發(fā)燒友的logo

poYBAGGrWFKANW_5AAeansUOKKw826.png

2. 顯示其他尺寸的圖片效果

pYYBAGGrWV2ASWxSAAie9w2taPo086.png

六、完整代碼

參考https://gitee.com/hehung/ab32-vg1_-rt-thread/tree/master/OLED_test

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • OLED技術(shù)
    +關(guān)注

    關(guān)注

    1

    文章

    66

    瀏覽量

    13259
  • OLED
    +關(guān)注

    關(guān)注

    119

    文章

    6171

    瀏覽量

    223691
  • 函數(shù)
    +關(guān)注

    關(guān)注

    3

    文章

    4284

    瀏覽量

    62328
  • RT-Thread
    +關(guān)注

    關(guān)注

    31

    文章

    1261

    瀏覽量

    39842
收藏 人收藏

    評(píng)論

    相關(guān)推薦

    RTT大賽作品:AB32VG1開(kāi)發(fā)板OLED顯示實(shí)驗(yàn)

    最近在玩AB32VG1,在做OLED顯示實(shí)驗(yàn)時(shí),很多關(guān)于AB32VG1驅(qū)動(dòng)OLED的文章,很多都是官方例程操作,在msh窗口中輸入測(cè)試指令,測(cè)試驅(qū)動(dòng)是否正常。很少有關(guān)于在main函數(shù)中直接實(shí)現(xiàn)的,本編文章直接在MAIN函數(shù)實(shí)現(xiàn)
    的頭像 發(fā)表于 11-05 16:03 ?6174次閱讀
    <b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b>:AB32VG1開(kāi)發(fā)板<b class='flag-5'>OLED</b><b class='flag-5'>顯示</b>實(shí)驗(yàn)

    RTT大賽作品連載】AB32VG1評(píng)估板到貨控制彩燈測(cè)試

    RTT大賽作品連載】AB32VG1評(píng)估板到貨控制彩燈測(cè)試篇;接下來(lái)看看在如何AB32VG1評(píng)估板控制彩燈! 在RT-ThreadStudio新建項(xiàng)目到對(duì)應(yīng)開(kāi)發(fā)配置及下載及驗(yàn)證測(cè)試!
    的頭像 發(fā)表于 11-07 19:39 ?5149次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】AB32VG1評(píng)估板到貨控制彩燈測(cè)試

    RTT大賽作品連載】CH32V103開(kāi)發(fā)板資料及上電首測(cè)

    簡(jiǎn)介 ? 參加論壇舉辦的rtt大賽也有幾天了,我選用的是CH32V103的板子,第一步就是收集板卡的相關(guān)資料了。 CH32V103是 沁恒微電子設(shè)計(jì)的一款RSIC-V的單片機(jī),使用了RSIC-V3A
    的頭像 發(fā)表于 11-15 08:45 ?8546次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】CH32V103開(kāi)發(fā)板資料及上電首測(cè)

    RTT大賽作品連載】AB32VG1評(píng)估板 音樂(lè)播放器

    RTT大賽作品連載】AB32VG1評(píng)估板 音樂(lè)播放器
    的頭像 發(fā)表于 11-12 21:11 ?6191次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】AB32VG1評(píng)估板 音樂(lè)播放器

    RTT大賽作品連載】中科藍(lán)訊AB32VG1開(kāi)發(fā)板開(kāi)箱篇

    介紹電路原理圖分析接口說(shuō)明,AB32VG1開(kāi)發(fā)板是以中科藍(lán)訊(Bluetrum)公司推出的基于RISC-V架構(gòu)的高配置芯片AB5301A為核心所組成的?!?b class='flag-5'>RTT大賽作品連載】中科藍(lán)訊A
    的頭像 發(fā)表于 11-13 10:01 ?1w次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】中科藍(lán)訊AB32VG1開(kāi)發(fā)板開(kāi)箱篇

    RTT大賽作品連載】 PWM操作蜂鳴器

    使用AB32VG1的PWM來(lái)操作無(wú)源蜂鳴器,能夠輸出頻率為1KHz到20KHz的聲音。
    的頭像 發(fā)表于 12-06 08:36 ?9525次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】 PWM操作蜂鳴器

    RTT大賽作品連載OLED顯示中文

    使用AB32VG1操作OLED顯示文字信息,包括漢字取模方式介紹,漢字顯示函數(shù)編寫.
    的頭像 發(fā)表于 12-06 09:25 ?8813次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】 <b class='flag-5'>OLED</b><b class='flag-5'>顯示</b>中文

    RTT大賽作品連載】AB32VG1開(kāi)發(fā)板之OLED

    驅(qū)動(dòng)OLED屏.
    的頭像 發(fā)表于 01-04 08:58 ?4462次閱讀
    【<b class='flag-5'>RTT</b><b class='flag-5'>大賽</b><b class='flag-5'>作品</b><b class='flag-5'>連載</b>】AB32VG1開(kāi)發(fā)板之<b class='flag-5'>OLED</b>屏

    電子發(fā)燒友設(shè)計(jì)大賽前4屆獲獎(jiǎng)作品圖片

    `第一屆電子設(shè)計(jì)大賽冠軍作品:流水燈第1,3,5,7個(gè)燈半亮,其余的全亮第二屆電子設(shè)計(jì)大賽冠軍作品:搖搖棒第三屆電子設(shè)計(jì)大賽冠軍
    發(fā)表于 11-29 15:49

    【星核計(jì)劃】上傳FPGA大賽作品,領(lǐng)取電子發(fā)燒友專屬上傳福利!

    -FPGA大賽,本次大賽獎(jiǎng)勵(lì)豐厚,不僅有獎(jiǎng)金,還有電子發(fā)燒友論壇為參賽者準(zhǔn)備的上傳福利,按照下面規(guī)則上傳參賽作品即可獲得,還在等什么,快來(lái)參加吧?。?b class='flag-5'>作品上傳地址:【FPGA開(kāi)發(fā)者項(xiàng)目
    發(fā)表于 05-21 15:01

    【文章連載】RT-Thread創(chuàng)新應(yīng)用大賽文章匯總

    作者:RTT大賽學(xué)習(xí)經(jīng)驗(yàn)分享 基于 rt-thread studio 的 sdk 開(kāi)發(fā) adc 的應(yīng)用詳解RTT大賽作品:AB32VG1開(kāi)發(fā)
    發(fā)表于 10-11 15:13

    【有獎(jiǎng)活動(dòng)】RT-Thread創(chuàng)新應(yīng)用大賽作品連載征文

    禮品:https://jifen.elecfans.com/index.html?文章標(biāo)題格式:【RTT大賽作品連載】+自擬內(nèi)容?文章作品
    發(fā)表于 10-21 18:49

    RTT大賽作品連載】AB32VG1開(kāi)發(fā)板OLED顯示實(shí)驗(yàn)

    最近在玩AB32VG1,在做OLED顯示實(shí)驗(yàn)時(shí),在csdn搜索了很多關(guān)于AB32VG1驅(qū)動(dòng)OLED的文章,很多都是官方例程操作,在msh窗口中輸入測(cè)試指令,測(cè)試驅(qū)動(dòng)是否正常。很少有關(guān)于在main函數(shù)
    發(fā)表于 11-05 14:33

    怎么用MCU實(shí)現(xiàn)OLED顯示圖片?

    怎么用MCU實(shí)現(xiàn)OLED 顯示圖片
    發(fā)表于 10-13 06:29

    基于51單片機(jī)的OLED顯示圖片文字

    基于51單片機(jī)的OLED屏幕顯示,可顯示圖片文字字母等。
    的頭像 發(fā)表于 06-12 00:43 ?1.4w次閱讀
    基于51單片機(jī)的<b class='flag-5'>OLED</b><b class='flag-5'>顯示</b><b class='flag-5'>圖片</b>文字