摘要:命令為關(guān)閉顯示命令,為開啟顯示命令包含兩個字節(jié),第一個為命令字,第二個為設(shè)置值,第二個字節(jié)的表示電荷泵的開關(guān)狀態(tài),該位為開啟電荷泵,為則關(guān)閉。命令用于設(shè)置顯示時的起始列地址低四位。這也決定了字模選擇的取模方式為列行式。
OLED即有機發(fā)光管(Organic Light-Emitting Diode,OLED)。OLED顯示技術(shù)具有自發(fā)光、廣視角、幾乎無窮高的對比度、較低功耗、極高反應(yīng)速度、可用于繞曲性面板、使用溫度范圍廣、構(gòu)造及制程簡單等有點,被認為是下一代的平面顯示屏新興應(yīng)用技術(shù)。
OLED顯示和傳統(tǒng)的LCD顯示不同,其可以自發(fā)光,所以不需要背光燈,這使得OLED顯示屏相對于LCD顯示屏尺寸更薄,同時顯示效果更優(yōu)。
常用的OLED屏幕有藍色、黃色、白色等幾種。屏的大小為0.96寸,像素點為128*64,所以我們稱為0.96oled屏或者12864屏。
1.模塊尺寸:23.7 *23.8mm
2.電源電壓:3.3-5.5V
3.驅(qū)動芯片:SSD1306
4.測試平臺:提供 k60/k10,9s12XS128,51,stm32,stm8等單片機
OLED本身是沒有顯存的,他的現(xiàn)存是依賴SSD1306提供的,而SSD1306提供一塊顯存。
SSD1306顯存總共為128*64bit大小,SSD1306將這些顯存分成了8頁。每頁包含了128個字節(jié)。
STM32內(nèi)部建立一個緩存(共128*8個字節(jié)),每次修改的時候,只是修改STM32上的緩存(實際上就是SRAM),修改完后一次性把STM32上的緩存數(shù)據(jù)寫入到OLED的GRAM。
這個方法也有壞處,對于SRAM很小的單片機(51系列)就比較麻煩。
命令0X81: 設(shè)置對比度。包含兩個字節(jié),第一個0X81為命令,隨后方法是的一個字節(jié)要設(shè)置這個對比度,值越大屏幕越亮。
命令0XAE/0XAF: 0XAE為關(guān)閉顯示命令,0XAF為開啟顯示命令
0X8D: 包含兩個字節(jié),第一個為命令字,第二個為設(shè)置值,第二個字節(jié)的BIT2表示電荷泵的開關(guān)狀態(tài),該位為1開啟電荷泵,為0則關(guān)閉。模塊初始化的時候,這個必須要開啟,否則看不到屏幕顯示。
命令0XB0~B7:用于設(shè)置頁地址,其低三位的值對應(yīng)GRAM頁地址。
命令0X00~0X0F:用于設(shè)置顯示時的起始列地址低四位。
命令0X10~0X1F: 用于設(shè)置顯示時的起始列地址高四位。
OLED點陣的點亮方式,舉個顯示”P”的例子,最左邊位最高位P7。
1.可以看出,要想顯示”P”,首先寫入0x1f,則顯示一個豎杠,之后控制器自動水平移動到下一列。
2.再寫入0X05,則出現(xiàn)兩個小橫桿,這個兩個橫桿就是0X05中0000 0101中兩個1所處的位置,寫完第二列后,控制器自動跳到第三列.
3.再寫入0X07,第四列寫入0X00后,P就顯示出來了。這也說明,即使你只想再一列的最上端顯示一個小點,即寫入0X01.
4.即你不能一次性控制一個點陣,只能一次性控制八位點陣,即一列點陣。這也決定了字模選擇的取模方式為“列行式“。
#include "stm32f10x.h"#include "SysTick.h"#include "oled.h"int main(){ unsigned char i = 0; initSysTick(); I2C_Config(); OLED_Init(); delay_ms(2000); OLED_Fill(0XFF); //?á??áá delay_ms(2000); OLED_Fill(0X00); //?á???e delay_ms(2000); // OLED_ShowStr(0, 3, "Hello World", 1);// OLED_ShowStr(0, 4, "Hello World", 2); while (1) { for(i=0;i<3;i++) { OLED_ShowLJJ(i*16, 0, i); } }}
#ifndef _OLED_H_#define _OLED_H_#include "stm32f10x.h"#define OLED_ADDRESS 0x78void I2C_Config(void);void I2C_WriteByte(uint8_t addr,uint8_t data);void I2C_WriteCmd(unsigned char I2C_Command);void I2C_WriteData(unsigned char I2C_Data);void OLED_Init(void);void OLED_SetPos(unsigned char x,unsigned char y);void OLED_Fill(unsigned char Fill_Data);void OLED_CLS(void);void OLED_ON(void);void OLED_OFF(void);void OLED_ShowStr(unsigned char x,unsigned y,unsigned char ch[],unsigned TextSize);void OLED_ShowCN(unsigned char x,unsigned y,unsigned char N);void OLED_ShowMouMou(unsigned char x,unsigned char y,unsigned char N);#endif
#include "stm32f10x.h"#include "oled.h"#include "delay.h"#include "codetab.h"/** *1|?ü£oI2C???? *2?êy£ovoid *·μ???μ£ovoid */void I2C_Config(void){ GPIO_InitTypeDef GPIO_initStruct; I2C_InitTypeDef I2C_initStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB , ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1 , ENABLE); //PB6 -- SCL PB7 -- SDA GPIO_initStruct.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_initStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_initStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_initStruct); I2C_DeInit(I2C1); I2C_initStruct.I2C_Ack = I2C_Ack_Enable; //ó|′eê?·?ê1?ü I2C_initStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; //μ??·£?êy?Y??ê??àéù£?óD7bitoí10bit I2C_initStruct.I2C_ClockSpeed = 400000; //ê±?ó?ù?è 400Kb I2C_initStruct.I2C_DutyCycle = I2C_DutyCycle_2; // 2:1 ?ò??16:9??DD I2C_initStruct.I2C_Mode = I2C_Mode_I2C; //?£ê?I2C?£ê? I2C_initStruct.I2C_OwnAddress1 = 0x30; //?÷?úμ??·£?0x30??±???μ? I2C_Init(I2C1, &I2C_initStruct); I2C_Cmd(I2C1, ENABLE);}/** *1|?ü£oI2CD′×??ú *2?êy£oaddr μ??·£?data êy?Y *·μ???μ£ovoid *//* ?aé???????EV8_2?í?±?ó1?±?á?£?óDwhile?-?·?áμè′yD′íê£??ùò???±?òa */void I2C_WriteByte(uint8_t addr,uint8_t data){ while( I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)); //?ì2éI2C×ü??ê?·?·±?| I2C_GenerateSTART( I2C1, ENABLE); //?a??I2C1 while( !I2C_CheckEvent( I2C1 , I2C_EVENT_MASTER_MODE_SELECT )); //EV5 ?÷?£ê? I2C_Send7bitAddress(I2C1, OLED_ADDRESS , I2C_Direction_Transmitter ); //·¢?í?÷?tμ??· while( !I2C_CheckEvent( I2C1 , I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED )); //EV6 I2C_SendData( I2C1 , addr ); //??′??÷μ??· while( !I2C_CheckEvent( I2C1 , I2C_EVENT_MASTER_BYTE_TRANSMITTING )); //EV8 I2C_SendData( I2C1 , data ); //òa·¢?íμ?êy?Y while( !I2C_CheckEvent( I2C1 , I2C_EVENT_MASTER_BYTE_TRANSMITTING )); //EV8 I2C_GenerateSTOP( I2C1, ENABLE ); //1?±?I2C×ü??}/** *1|?ü£oD′?üá? *2?êy£oI2C_Command DèòaD′è?μ??üá? *·μ???μ£ovoid */void WriteCmd(unsigned char I2C_Command){ I2C_WriteByte(0x00,I2C_Command);}/** *1|?ü£oD′êy?Y *2?êy£oI2C_Data DèòaD′è?μ?êy?Y *·μ???μ£ovoid */void WriteData(unsigned char I2C_Data){ I2C_WriteByte(0x40,I2C_Data);}/** *1|?ü£o3?ê??ˉOLED *2?êy£ovoid *·μ???μ£ovoid */void OLED_Init(void){ delay_ms(100); WriteCmd(0xAE); //display off WriteCmd(0x20); //Set Memory Addressing Mode WriteCmd(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid WriteCmd(0xb0); //Set Page Start Address for Page Addressing Mode,0-7 WriteCmd(0xc8); //Set COM Output Scan Direction WriteCmd(0x00); //---set low column address WriteCmd(0x10); //---set high column address WriteCmd(0x40); //--set start line address WriteCmd(0x81); //--set contrast control register WriteCmd(0xff); //áá?èμ÷?ú 0x00~0xff WriteCmd(0xa1); //--set segment re-map 0 to 127 WriteCmd(0xa6); //--set normal display WriteCmd(0xa8); //--set multiplex ratio(1 to 64) WriteCmd(0x3F); // WriteCmd(0xa4); //0xa4,Output follows RAM content;0xa5,Output ignores RAM content WriteCmd(0xd3); //-set display offset WriteCmd(0x00); //-not offset WriteCmd(0xd5); //--set display clock divide ratio/oscillator frequency WriteCmd(0xf0); //--set divide ratio WriteCmd(0xd9); //--set pre-charge period WriteCmd(0x22); // WriteCmd(0xda); //--set com pins hardware configuration WriteCmd(0x12); WriteCmd(0xdb); //--set vcomh WriteCmd(0x20); //0x20,0.77xVcc WriteCmd(0x8d); //--set DC-DC enable WriteCmd(0x14); // WriteCmd(0xaf); //--turn on oled panel}/** *1|?ü£oéè??×?±ê *2?êy£ox x?á£?y y?á *·μ???μ£ovoid */void OLED_SetPos(unsigned char x,unsigned char y){ WriteCmd(0xb0 + y); WriteCmd((x&0xf0)>>4|0x10); WriteCmd((x&0x0f)|0x01);}/** *1|?ü£oè??áì?3? *2?êy£oFill_Data Dèòaì?3?μ?êy?Y *·μ???μ£ovoid */void OLED_Fill(unsigned char Fill_Data){ unsigned char n; unsigned char m; for(m=0;m<8;m++) { WriteCmd(0xb0 + m); WriteCmd(0x00); WriteCmd(0x10); for(n=0;n<128;n++) { WriteData(Fill_Data); } }}/** *1|?ü£o???á *2?êy£ovoid *·μ???μ£ovoid */void OLED_CLS(void){ OLED_Fill(0x00);}/** *1|?ü£o?a??OLED *2?êy£ovoid *·μ???μ£ovoid */void OLED_ON(void){ WriteCmd(0x8D); //éè??μ?oé±? WriteCmd(0x14); //?a??μ?oé±? WriteCmd(0xAF); //?a????ê?}/** *1|?ü£o1?±?OLED *2?êy£ovoid *·μ???μ£ovoid */void OLED_OFF(void){ WriteCmd(0x8D); //éè??μ?oé±? WriteCmd(0x10); //1?±?μ?oé±? WriteCmd(0xAE); //1?±???ê?}void OLED_ShowStr(unsigned char x,unsigned y,unsigned char ch[],unsigned TextSize){ unsigned char c = 0; unsigned char i = 0; unsigned char j = 0; switch(TextSize) //?????£ê? { case 1: { while(ch[j] != "/0") //?D??ê?·?μ?′?×?oóò??? { c = ch[j] - 32; //′óD?D′×a?? if(x > 126) //?D???á??ê?·?·?μ???,OLEDê?128*8×??ú { x = 0; y++; } OLED_SetPos(x,y);//éè??×?±ê for(i=0;i<6;i++) { WriteData(F6x8[c][i]); } x+=6; j++; } }break; case 2: { while(ch[j] != "/0") //?D??ê?·?μ?′?×?oóò??? { c = ch[j] - 32; //′óD?D′×a?? if(x > 120) //?D???á??ê?·?·?μ???,OLEDê?128*8×??ú { x = 0; y++; } OLED_SetPos(x,y); //éè??×?±ê for(i=0;i<8;i++) //òò?aê?16????μ??ùò?·??aá???8??à′D′£??aê?é?°?2?·? { WriteData(F8X16[c*16+i]); } OLED_SetPos(x,y+1); //éè??×?±ê è?1??aà?éè??μ?ê?y2?ê?y+1?áμ?????ê?μ?×?·?′?????ê?ò?°? for(i=0;i<8;i++) //ì?×aμ???ò?ò3£??aê???°?2?·? { WriteData(F8X16[c*16+i+8]); } x+=8; j++; } }break; }} void OLED_ShowCN(unsigned char x,unsigned y,unsigned char N){ unsigned char i; unsigned int addr = 32*N; OLED_SetPos(x,y); for(i=0;i<16;i++) { WriteData(F16X16[addr]); addr += 1; } OLED_SetPos(x,y+1); for(i=0;i<16;i++) { WriteData(F16X16[addr]); addr += 1; }} void OLED_ShowMouMou(unsigned char x,unsigned char y,unsigned char N){ unsigned char i; unsigned int addr = 32*N; OLED_SetPos(x,y); for(i=0;i<16;i++) { WriteData(MouMou[addr]); addr += 1; } OLED_SetPos(x,y+1); for(i=0;i<16;i++) { WriteData(MouMou[addr]); addr += 1; } }
//unsigned char F16X16[] =//{// 0x10,0x60,0x02,0x8C,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0xFE,0x00,0x00,0x00,// 0x04,0x04,0x7E,0x01,0x40,0x7E,0x42,0x42,0x7E,0x42,0x7E,0x42,0x42,0x7E,0x40,0x00,/*"???è",0*/// 0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,// 0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00,/*"êa?è",1*///};unsigned char F16X16[] ={ 0x00,0xFC,0x04,0x04,0xFC,0x00,0x10,0xD8,0x14,0x13,0xF0,0x14,0x18,0x30,0x00,0x00, 0x00,0x0F,0x04,0x04,0x0F,0x08,0x0A,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x08,0x00,/*"?è",0*/ 0x00,0xFC,0x04,0x04,0xFC,0x00,0x10,0xD8,0x14,0x13,0xF0,0x14,0x18,0x30,0x00,0x00, 0x00,0x0F,0x04,0x04,0x0F,0x08,0x0A,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x08,0x00,/*"?è",1*/};unsigned char MouMou[] ={ 0x00,0xFC,0x04,0x04,0xFC,0x00,0x10,0xD8,0x14,0x13,0xF0,0x14,0x18,0x30,0x00,0x00, 0x00,0x0F,0x04,0x04,0x0F,0x08,0x0A,0x09,0x09,0x09,0xFF,0x09,0x09,0x09,0x08,0x00,/*"?è",0*/ 0x00,0xFC,0x04,0x04,0xFC,0x00,0x10,0xD8,0x14,0x13,0xF0,0x14,0x18,0x30
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://specialneedsforspecialkids.com/yun/121631.html
摘要:如圖所示在了解起始條件和停止條件后,我們再來看看在這個過程中數(shù)據(jù)的傳輸是如何進行的。四參考資料通過接口實現(xiàn)溫濕度的采集硬件和軟件區(qū)別 stm32通過I2C接口實現(xiàn)...
摘要:使用庫讀寫環(huán)境光照度傳感器本文將教大家如何快速使用庫讀取光照度數(shù)據(jù)。五實驗樣機測試展示通過之前配置好的面板,通過涂鴉智能進行配網(wǎng)實時采集光照度傳感器的數(shù)據(jù)。 使用STM32 HAL庫讀寫環(huán)境光照度傳感器(BH1750) 本文將教大家如何快速使用STM32HAL庫讀取光照度數(shù)據(jù)。 實現(xiàn)功能:通...
摘要:文章目錄一原理二實現(xiàn)顯示中文滾動顯示顯示字符串讀取溫濕度顯示溫濕度三結(jié)果開機顯示歡迎信息循環(huán)讀取溫濕度以及滾動顯示我的四總結(jié)五參考六源碼一原理的定義就是串行外圍設(shè)備接口。 ...
摘要:三小結(jié)本次實驗在實現(xiàn)了溫濕度數(shù)據(jù)采集并通過串口顯示和利用屏數(shù)據(jù)顯示代碼的基礎(chǔ)上,完成屏顯示采集的溫濕度數(shù)據(jù)也并不復(fù)雜,其中,溫濕度數(shù)據(jù)采集的過程使用的是模擬,屏的數(shù)據(jù)顯示采用的是。 ...
閱讀 820·2023-04-25 19:49
閱讀 3756·2021-09-30 09:47
閱讀 2741·2021-09-13 10:21
閱讀 2679·2021-08-24 10:04
閱讀 3168·2019-08-30 15:55
閱讀 2295·2019-08-30 15:55
閱讀 2399·2019-08-30 15:54
閱讀 3471·2019-08-30 13:53