【經(jīng)驗分享】Banana PI Leaf S3開發(fā)板之OLED屏顯示驅(qū)動實現(xiàn)
OLED屏有多種形式,在例程中提供了一種I2C接口的0.96寸單色屏程序。本人則有一款I(lǐng)2C接口的0.96寸雙色屏,在掌握GPIO口使用的基礎(chǔ)上,以模擬I2C的方式實現(xiàn)了它的驅(qū)動顯示。
其引腳的連接關(guān)系如下:
VCC----3.3V
GND---GND
SDA---- GPIO15
SCL---- GPIO16
圖1 引腳連接
將所用引腳設(shè)置為輸出模式的語句為:
sda=Pin(15,Pin.OUT) #15
sck=Pin(16,Pin.OUT) #16
實現(xiàn)數(shù)據(jù)數(shù)據(jù)發(fā)送的函數(shù)為:
1.def Write_IIC_Byte(IIC_Byte):
2. da=IIC_Byte
3. sck.off()
4. for i in range(8):
5. m=da
6. m=m&0x80
7. if(m==0x80):
8. sda.on()
9. else:
10. sda.off()
11. da=da<<1
12. sck.on()
13. sck.off()
實現(xiàn)清屏的函數(shù)為:
1.def OLED_Clear():
2. for i in range(8):
3. OLED_WR_Byte (0xb0+i,OLED_CMD)
4. OLED_WR_Byte (0x00,OLED_CMD)
5. OLED_WR_Byte (0x10,OLED_CMD)
6. for j in range(128):
7. OLED_WR_Byte(0x00,OLED_DATA)
OLED屏的初始化函數(shù)為:
1.def OLED_Init():
2. OLED_WR_Byte(0xAE,OLED_CMD)
3. OLED_WR_Byte(0x02,OLED_CMD)
4. OLED_WR_Byte(0x10,OLED_CMD)
5. OLED_WR_Byte(0x40,OLED_CMD)
6. OLED_WR_Byte(0x81,OLED_CMD)
7. OLED_WR_Byte(0xff,OLED_CMD)
8. OLED_WR_Byte(0xA1,OLED_CMD)
9. OLED_WR_Byte(0xC8,OLED_CMD)
10. OLED_WR_Byte(0xA6,OLED_CMD)
11. OLED_WR_Byte(0xA8,OLED_CMD)
12. OLED_WR_Byte(0x3f,OLED_CMD)
13. OLED_WR_Byte(0xD3,OLED_CMD)
14. OLED_WR_Byte(0x00,OLED_CMD)
15. OLED_WR_Byte(0xd5,OLED_CMD)
16. OLED_WR_Byte(0x80,OLED_CMD)
17. OLED_WR_Byte(0xD9,OLED_CMD)
18. OLED_WR_Byte(0xF1,OLED_CMD)
19. OLED_WR_Byte(0xDA,OLED_CMD)
20. OLED_WR_Byte(0x12,OLED_CMD)
21. OLED_WR_Byte(0xDB,OLED_CMD)
22. OLED_WR_Byte(0x40,OLED_CMD)
23. OLED_WR_Byte(0x20,OLED_CMD)
24. OLED_WR_Byte(0x02,OLED_CMD)
25. OLED_WR_Byte(0x8D,OLED_CMD)
26. OLED_WR_Byte(0x14,OLED_CMD)
27. OLED_WR_Byte(0xA4,OLED_CMD)
28. OLED_WR_Byte(0xA6,OLED_CMD)
29. OLED_WR_Byte(0xAF,OLED_CMD)
30. OLED_WR_Byte(0xAF,OLED_CMD)
31. OLED_Clear()
32. OLED_Set_Pos(0,0)
為了驗證程序的可行性,特將清屏函數(shù)改造為彩條繪制函數(shù),其內(nèi)容為:
1.def OLED_Clear():
2. for i in range(8):
3. OLED_WR_Byte (0xb0+i,OLED_CMD)
4. OLED_WR_Byte (0x00,OLED_CMD)
5. OLED_WR_Byte (0x10,OLED_CMD)
6. for j in range(128):
7. OLED_WR_Byte(0xf0,OLED_DATA) #OLED_DATA
8.
9.def OLED_text():
10. OLED_Init()
11. OLED_Clear()
12.
13.OLED_text ()
經(jīng)上傳測試,其顯示效果如圖2所示,說明驅(qū)動程序是有效的。
圖2 繪制彩條
為了實現(xiàn)字符,需按如下形式來定義字庫:
F8X16=[0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,
0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
** ... **
0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
所設(shè)計的字符串顯示函數(shù)為:
1.def OLED_ShowString(x,y,chr,Char_Size):
2. for character in chr:
3. OLED_ShowChar(x,y,character,Char_Size)
4. x+=8
5. if(x>120):
6. x=0
7. y+=2
實現(xiàn)字符串輸出測試的程序如下:
1.def OLED_text():
2. OLED_Init() 3.OLED_Clear()
4. OLED_ShowString(0,0,'Banana PI ',16)
5. OLED_ShowString(0,2,'Leaf S3',16)
6. OLED_ShowString(0,4,'OLED TEST',16)
7. OLED_ShowString(0,6,'jinglixixi',16)
8.
9. OLED_text()
經(jīng)上傳測試,其顯示效果如圖3所示,說明驅(qū)動程序是有效的。
圖3 顯示字符串
通過OLED屏驅(qū)動程序的設(shè)計,基本上掌握了Thonny的編程方法、函數(shù)的設(shè)計及數(shù)組元素的使用等,收獲還是很多的,后面就可以自主地進(jìn)行功能設(shè)計了。
- 上一篇:【電路設(shè)計】PCB設(shè)計必須考慮的8種安全距離,搞錯1種都出大 2022/12/8
- 下一篇:單片機I/O口驅(qū)動,為什么一般都選用三極管而不是MOS管? 2022/11/30