疯狂单片机--用C++写STM32程序-OLED

第一次见到OLED就是在MP3播放器上,那时只有高端大气上档次的机器才用OLED,所以后来对使用OLED的设备总有一种高贵的感觉.
今天就来玩一玩OLED
疯狂单片机--用C++写STM32程序-OLED_第1张图片
型号:PG9639TLBE,
驱动IC:SSD1306
驱动方式:模拟SPI方式,
OLED接口引脚:SCLK,SDIN,CS_N,CMD
SCLK:串行时针信号
SDIN:串行数据信号
CS_N:片选
CMD:命令/数据选择

疯狂单片机--用C++写STM32程序-OLED_第2张图片

型号:QG-2864KLBLG22
驱动IC:SH1106
驱动方式:模拟SPI方式,
OLED接口引脚:SCLK,SDIN,CS_N,CMD
SCLK:串行时针信号
SDIN:串行数据信号
CS_N:片选
CMD:命令/数据选择
 
疯狂单片机--用C++写STM32程序-OLED_第3张图片


接着创建了一个OLED类
 

//OLED.H
//BY wisepragma
//homepage:http://blog.csdn.net/wisepragma
#pragma once
#include "main.h"
#include "math.h"
#include "font_dot.h"			 
#include "string.h"
//
///
// 型号:QG-2864KLBLG22
// 驱动IC:SH1106
// 驱动方式:模拟SPI方式,
// OLED接口引脚:SCLK,SDIN,CS_N,CMD
// SCLK:串行时针信号
// SDIN:串行数据信号
// CS_N:片选
// CMD:命令/数据选择
enum  
{
        MAX_PAGE=8,   //7+8*4 ROWS 范围:0~MAX_PAGE-1
        MAX_COLUMN=128,//96,,//, //分辨率:横向96点  范围:0~MAX_COLUMN-1   128
        MAX_ROW=64,//39,//,//分辨率:纵向39点 范围:0~MAX_ROW-1   64
        COLUMN_OFFSET_ADDRINC=2,
        CHAR_WIDTH=8,
        CHAR_HEIGHT=16, 
        DEFAULT_BRIGHTNESS=0x14,
        MAX_DELAY_POWERUP=30000
}OLED_CONFIG; 
// // //
// // 型号:PG9639TLBE,
// // 驱动IC:SSD1306
// // 驱动方式:模拟SPI方式,
// // OLED接口引脚:SCLK,SDIN,CS_N,CMD
// // SCLK:串行时针信号
// // SDIN:串行数据信号
// // CS_N:片选
// // CMD:命令/数据选择
//   enum  
//   {
//  //OLED PG9639TLBE
//  //PAGE0:D1~D7填入,PAGE1~PAGE4:D0~D7;填入方向从上往下
//  //分辨率为:96x39 即Xpixel:96 columns Ypixel:5pages=7rows+8*(4page) rows=7+8*4=39 rows
//   MAX_PAGE=5,   //7+8*4 ROWS 范围:0~MAX_PAGE-1
//   MAX_COLUMN= 96, //, //分辨率:横向96点  范围:0~MAX_COLUMN-1  96
//   MAX_ROW= 39, //分辨率:纵向39点 范围:0~MAX_ROW-1   39
//    COLUMN_OFFSET_ADDRINC=32,
//   CHAR_WIDTH=8,
//   CHAR_HEIGHT=16, 
//   DEFAULT_BRIGHTNESS=0x14,
//   MAX_DELAY_POWERUP=30000//用户自己调节,加入上电延时保证可靠显示
//  }OLED_CONFIG; 
  
class OLED
{
private:
        enum	 		 
        {
                Charge_Pump_Setting=0x8D,//0x8D,settingbyte [0x10(disable charge pump),0x14(enable charge pump)]
                Set_Contrast_Control=0x81,	//00~0xff
                Entire_Display_On=0xA4,//0xA4 follows RAM,0xA5 ignores RAM
                Entire_Display_Off=0xA5,
                Set_Normal_Display=0xA6,
                Set_Inverse_Display=0xA7,
                Set_Display_On=0xAF,
                Set_Display_Off=0xAE,
                Right_Horizontal_Scroll=0x26,	 //0x26,0x00(DummyByte),StartPage(0~7),interval(0~7),EndPage(0~7),0x00(DummyByte),0xFF(DummyByte)
                Left_Horizontal_Scroll=0x27,	//0x27,0x00(DummyByte),StartPage(0~7),interval(0~7),EndPage(0~7),0x00(DummyByte),0xFF(DummyByte)
                Vertical_And_Right_Horizontal_Scroll=0x29,//0x29,0x00(DummyByte),StartPage(0~7),interval(0~7),EndPage(0~7),VerticalScrollOffset(1~63)
                Vertical_And_Left_Horizontal_Scroll=0x2A, //0x2A,0x00(DummyByte),StartPage(0~7),interval(0~7),EndPage(0~7),VerticalScrollOffset(1~63)
                Deactivate_Scroll=0x2E,//for 0x26,0x27,0x29,0x2A ,RAM NEED TO BE rewritten 
                Activate_Scroll=0x2F,//for 0x26,0x27,0x29,0x2A 
                Set_Vertical_Scroll_Area=0xA3,//p30*0xA3,NoOfRows,VerticalScrollNo
                Set_Memory_Address_Mode=0x20,//0x20,ModeSelect(0, Horizontal Addressing Mode ;1, Vertical Addressing Mode; 2,Page Addressing Mode (default)
                Set_Column_Address=0x21,//0x21,startColumn(0~127),endColumn(0~127) //This command is only for  horizontal or vertical addressing mode.    
                Set_Page_Address=0x22,//0x22,startPage(0~7),endPage(0~7)	    //This command is only for  horizontal or vertical addressing mode. 
                Set_Segment_Remap_ColumnAddress0_Mappedto_SEG0=0xA0,	//default
                Set_Segment_Remap_ColumnAddress0_Mappedto_SEGmax=0xA1,
                Set_Multiplex_Ratio=0xA8,//0xA8,MUXratio(16~64)
                Set_COM_Output_Scan_DirUp=0xC0,		 //default
                Set_COM_Output_Scan_DirDown=0xC8,
                Set_Display_Vertical_Offset=0xD3,//0xD3,Vertical Shift(0~63)
                Set_COMPins_Hardware_Config=0xDA,//p31*config(0x32,0x02,0x12,0x22)
                Set_Display_Clock=0xD5,//p32*0xD5,osc[7:4]|ratio[3:0]
                Set_PreCharge_Period=0xD9,//0xD9,Phase1[3:0]|Phase2[7:4]
                Set_Vcomh_DeselectLevel=0xDB,//0xDB,level[0x00,0x20,0x30]
                NOP=0xE3,
        }OLED_COMMAND; //置顶,否则GRAM[MAX_PAGE][MAX_COLUMN]未定义
        STM32PIN CMD;
        STM32PIN CS_N;
        STM32PIN SCLK;
        STM32PIN SDIN;
        uint8_t GRAM[MAX_PAGE][MAX_COLUMN];
        bool 	m_bSegmentRemapAsAddrInc_fixed;
        bool  m_bflipHorizontal,m_bflipVertical;
        uint8_t m_brightness; 
        uint8_t m_StartColumnAddress;
        //
public: 
        OLED( STM32PIN &p_sclk,STM32PIN &p_sdin,STM32PIN &p_cs,STM32PIN &p_cmd ,uint8_t brightness=DEFAULT_BRIGHTNESS/*0x00(dark)~0xff(light)*/,uint8_t maxpage=8,uint8_t maxcolumn=128 )
        {
                SCLK=p_sclk;
                SDIN=p_sdin;
                CS_N=p_cs;
                CMD=p_cmd; 
                SCLK.reset(GPIO_Mode_Out_PP);
                SDIN.reset(GPIO_Mode_Out_PP);
                CS_N.reset(GPIO_Mode_Out_PP);
                CMD.reset(GPIO_Mode_Out_PP);
                m_brightness=brightness;
                m_bflipHorizontal=false;
                m_bflipVertical=false;
                PowerUp(); 
        }
        ///
        
        void PowerUp(void)
        {
                for(int i=0;i>4) & 0x0f);/*set higher column address*/
                FlipHorizontal(false);  	 			//0xA0 or 0xA1	水平翻转显示 /*set segment remap*///	startColumn+=32; //magic number,i don't know why//SegmentRemapAsAddrInc(false); 时要加这句
                FlipVertical(false);						//0xC8 or 0xC0( //default)   垂直翻转显示 	/*Com scan direction*/	
                //180度转向显示FlipVertical(true);			FlipHorizontal(true); 
                //SWSetHV(true,true);软件翻转
                EnableChargePump(true);  				//0x8D(0x14),启用内部电压泵 Enable Embedded DC/DC Converter 
                SetMultiplexRatio(MAX_ROW-1); 	//0xA8(64d=0x3F)参数近似要显示的行数 QG-2864KLBLG22(SH1106)-- set multiplex ratio: 1/64 duty//PG9639TLBE(SSD1306)   0xA8(0x27=39D)	 
                SetClockDivideRatio(0x80); 			//0xD5(0x80) Set Clock as 100 Frames/Sec
                SetCOMPinsHardwareConfig(0x12);	//0xDA(0x12)//?p31*config(0x32,0x02,0x12,0x22)//SH1106:0XDA,0X02隔行扫描
                SetBrightness(m_brightness);		//0x81(0xAF)亮度即Contrast Control,Brightness:0x00(dark)~0xff(light)
                SetPreChargePeriod(0x25);			//0xD9(0x25)//?p32*Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
                SetVcomhDeselectLevel(0x20);	//0xDB(0x20)//00h  ~ 0.65 x Vcc  //20h  ~ 0.77 x Vcc (RESET) //30h  ~ 0.83 x Vcc
                SwitchEntireDisplayOn(true);  	//0xA4 or 0xA5 ,false全亮显示
                SwitchInverseDisplay(false);  	//0xA6 or 0xA7 反相显示
                SwitchDisplayOn(true);  				//0xAF	开启显示 	
                clear(true/*flush*/);//清屏
        }
        void PowerDown(void)
        {
                sleep();
                for(int i=0;i<300000;i++);		//20ms延时 
        }
        void sleep(void)  //在sleep状态下还是能写入东西的
        {
                SwitchDisplayOn(false);	 		//AE
                EnableChargePump(false);  		//8D(10) Enable Embedded DC/DC Converter 
        }
        void wake(void)
        {
                EnableChargePump(true);  		//8D(14) Enable Embedded DC/DC Converter 
                SwitchDisplayOn(true);  		//AF
        }
        // **************configuation functions**********************************=
        void SetMemoryAddressMode(uint8_t mode=0x02)	
        {  
                //ModeSelect SH1106不支持
                //0, Horizontal Addressing Mode ;	//写入数据,column 自增到末尾(MAX_COLUMN-1),[column回0,page自增,到末尾(MAX_PAGE-1)回0	  ]
                //1, Vertical Addressing Mode; 	   // 写入数据,page自增,到末尾(MAX_PAGE-1)[page回0,column 自增到末尾(MAX_COLUMN-1),回0 ]
                //2,Page Addressing Mode (default)	  //page不变,写入数据,column自增,到末尾(MAX_PAGE-1)后回0
                WR1BCmd( Set_Memory_Address_Mode );
                WR1BCmd( mode );  	  
        }
        void FlipHorizontal(bool bOn=true)
        {
                m_bSegmentRemapAsAddrInc_fixed=bOn;	 
                WR1BCmd( bOn? Set_Segment_Remap_ColumnAddress0_Mappedto_SEG0:Set_Segment_Remap_ColumnAddress0_Mappedto_SEGmax);
        }
        void FlipVertical(bool bOn=true)
        {
                WR1BCmd( bOn? 	Set_COM_Output_Scan_DirUp:  Set_COM_Output_Scan_DirDown);
        }  	
        void SetStartPage(uint8_t page=0)	 //页模式下,设置起始页
        {
                WR1BCmd( 0xB0 | (page&0x0F) );
        }		
        void SetDisplayStartLine(uint8_t ixLine=0)
        {
                WR1BCmd(0x40 | ixLine); //ixLine:0~63
        }	
        void SetDisplayStartColumn(uint8_t ColumnAddress=0)//SH1106,X轴偏移-2,ssd1306 x轴偏移-32
        {		
                m_StartColumnAddress=(0= MAX_COLUMN ) return;
                WR1BCmd(0x0f & 	ColumnAddress );				//Set Lower Column (00H - 0FH) 
                WR1BCmd(0x0f & (ColumnAddress>>4) |	0x10 );	//Set Higher Column  (10H - 1FH) 	
        }
        uint8_t GetBrightness(void)
        {
                return 	 m_brightness;
        }
        void light(int8_t dlight)
        {
                m_brightness+=dlight;
                SetBrightness(m_brightness);
        }
        void SetBrightness(uint8_t light=0x10) //亮度 Brightness:0x00(dark)~0xff(light)	  
        {
                m_brightness=light;
                WR1BCmd( Set_Contrast_Control );
                WR1BCmd( light );
        }
        //___________________________________________________________________________________________
        void EnableChargePump( bool bEnable=true)
        { 
                //0x8D,settingbyte [0x10(disable charge pump,default),0x14(enable charge pump)]
                WR1BCmd( Charge_Pump_Setting );	//someone use(0xad);/*set charge pump enable*/ 
                WR1BCmd( bEnable? 0x14: 0x10);
        }  
        void SetVppLevel(uint8_t level)//这个也可以调节亮度SH1106
        {
                WR1BCmd( 0x30|(level&0x03) );/*0X30---0X33 set VPP 9V*/
        }
        void SwitchEntireDisplayOn(bool bOn=false)
        {
                WR1BCmd( bOn ? Entire_Display_On:Entire_Display_Off );
        }
        void SwitchInverseDisplay(bool bOn=false)
        {
                WR1BCmd( bOn ? Set_Inverse_Display:Set_Normal_Display );
        }  	
        void SetMultiplexRatio(uint8_t MUXratio=0x3F)
        {
                WR1BCmd(Set_Multiplex_Ratio);
                WR1BCmd( MUXratio );
        } 	
        void SwitchDisplayOn(bool bOn=false)
        {
                WR1BCmd( bOn ? Set_Display_On:Set_Display_Off );
        }
        void SetDisplayVerticalOffset(uint8_t offset)
        {
                WR1BCmd(Set_Display_Vertical_Offset);
                WR1BCmd( offset );
        }
        //2 FUNC FOR Set_Display_Clock
        void SetClockDivideRatio(uint8_t osc,uint8_t ratio)
        {
                WR1BCmd(Set_Display_Clock);
                WR1BCmd ( ( osc & 0xf0 )|(ratio & 0x0f) );
        }
        void SetClockDivideRatio(uint8_t oscratio)
        {
                WR1BCmd(Set_Display_Clock);
                WR1BCmd( oscratio );
        }  	
        void SetPreChargePeriod(uint8_t phase=0x25)
        {
                WR1BCmd(Set_PreCharge_Period); 
                WR1BCmd(phase);
        } 
        void SetCOMPinsHardwareConfig (uint8_t config)//sh1106只支持0xda,0x02或0XDA,0X12
        {
                WR1BCmd( Set_COMPins_Hardware_Config );
                WR1BCmd( config );
        }		
        void SetVcomhDeselectLevel(uint8_t  level=0x12)
        {  
                WR1BCmd(Set_Vcomh_DeselectLevel); 
                WR1BCmd(level);
        } 	
        //++++++++++++++useless functions+++++++++++++++++++++++++++++++++++
        void Nop(void)
        {
                WR1BCmd(NOP);
        }
        void ActivateScroll(void)
        {
                WR1BCmd( Activate_Scroll );
        }
        void DeactivateScroll(void)
        {
                WR1BCmd( Deactivate_Scroll );
        }
        void SetColumnAddressRange(uint8_t startColumn,uint8_t endColumn) //横/竖模式下使用,设定列范围 column:0~127
        {	 
                WR1BCmd(Set_Column_Address);
                WR1BCmd(  startColumn );	//default:0
                WR1BCmd(  endColumn  );		//default:127		
        }
        void SetPageAddressRange(uint8_t startPage=0,uint8_t endPage=MAX_PAGE-1)	 //横/竖模式下使用,设定页范围 Page:0~7
        {	This command is only for  horizontal or vertical addressing mode.  
                WR1BCmd(Set_Page_Address);
                WR1BCmd(startPage);	  //default:0
                WR1BCmd(endPage);	  //default:7
        }
        void VerticalRightScroll(uint8_t StartPage,uint8_t EndPage,uint8_t Speed,uint8_t VerticalScrollOffset) 	//斜着,不知作什么用
        {	  	
                //VerticalScrollOffset(0~63),若取0就等于RightScroll()
                DeactivateScroll();
                WR1BCmd( Vertical_And_Right_Horizontal_Scroll );
                WR1BCmd( 0x00 );//DummyByte
                WR1BCmd( StartPage );//page(0~7)  y轴方向从上向下分八页,分别为page0..page7,
                WR1BCmd( Speed );//interval(0~7)
                WR1BCmd( EndPage ); //page(0~7)
                WR1BCmd( VerticalScrollOffset );
                ActivateScroll();
        }
        void VerticalLeftScroll(uint8_t StartPage,uint8_t EndPage,uint8_t Speed,uint8_t VerticalScrollOffset) //斜着,不知作什么用
        {	
                //VerticalScrollOffset(0~63),若取0就等于LeftScroll()
                DeactivateScroll();
                WR1BCmd( Vertical_And_Left_Horizontal_Scroll );
                WR1BCmd( 0x00 );//DummyByte
                WR1BCmd( StartPage );//page(0~7)  y轴方向从上向下分八页,分别为page0..page7,
                WR1BCmd( Speed );//interval(0~7)
                WR1BCmd( EndPage ); //page(0~7)
                WR1BCmd( VerticalScrollOffset );
                ActivateScroll();
        }
        void RightScroll(uint8_t StartPage,uint8_t EndPage,uint8_t Speed )	//page(0~7)   speed(0~7)
        {		
                DeactivateScroll();
                WR1BCmd( Right_Horizontal_Scroll );
                WR1BCmd( 0x00 );//DummyByte
                WR1BCmd( StartPage );//page(0~7)  y轴方向从上向下分八页,分别为page0..page7,
                WR1BCmd( Speed );//interval(0~7)
                WR1BCmd( EndPage ); //page(0~7)
                WR1BCmd( 0x00 );//DummyByte
                WR1BCmd( 0xFF );
                ActivateScroll();
        }
        void LeftScroll(uint8_t StartPage,uint8_t EndPage,uint8_t Speed )
        {
                DeactivateScroll();
                WR1BCmd( Left_Horizontal_Scroll );
                WR1BCmd( 0x00 );//DummyByte
                WR1BCmd( StartPage );
                WR1BCmd( Speed );//interval(0~7)
                WR1BCmd( EndPage );
                WR1BCmd( 0x00 );//DummyByte
                WR1BCmd( 0xFF );
                ActivateScroll();
        }	
        /// **************useful functions**********************************=
        void fill(uint8_t dat=0xff,bool bFlushAtOnce=true)
        {
                memset(GRAM,dat,sizeof(GRAM));
                if( bFlushAtOnce ) flush();	
        }	   
        void clear(bool bFlushAtOnce=true)
        {
                memset(GRAM,0,sizeof(GRAM));
                if( bFlushAtOnce ) flush();	
        }
        void dot(uint8_t page,uint8_t column,uint8_t byDot)  //不经GRAM直接写OLED		  
        {	   
                //page:0~4,column:0~95
                //SetDisplayStartLine(0);
                SetStartPage(page);        
                SetStartColumn(column);
                WR1BData(byDot);
        }
        //
        //	void direct_putascii(uint8_t basePage,uint8_t baseColumn,char ch) //不经GRAM直接写OLED		 
        //	{					    
        //		signed char  iAlpha=ch-0x20;	  //ascii字模从0x20开始
        //		if(	iAlpha<0 || iAlpha>Total_Ascii8x16dot_Font)
        //		{
        //			return;//0~0x19非ASCII符不处理
        //		}
        //	    //按字节写入column自增的方式,先画字模的第一行,再画第二行 ,(字模是纵向扫描的)
        //		SetStartPage(basePage);		   
        //		SetStartColumn(baseColumn); 	
        //		for(uint8_t i=0;i<=14;i+=2)
        //		{
        //			 WR1BData( Ascii8x16dot[iAlpha][i]);
        //		}
        //		SetStartPage(basePage+1);
        //		SetStartColumn(baseColumn); 
        //		for(uint8_t i=1;i<=15;i+=2)
        //		{
        //			 WR1BData( Ascii8x16dot[iAlpha][i]);
        //		}
        //	}
        //	
        //	void direct_putstr(uint8_t basePage,uint8_t baseColumn, const  char  *str)	  不经GRAM直接写OLED 
        //	{
        //		int len=strlen(str);
        //		for(int i=0;iMAX_COLUMN-CHAR_WIDTH)
        //			{	
        //				basePage+=2;
        //				baseColumn=0;
        //			}
        //			if(basePage>4)break; 
        //			putascii(basePage,baseColumn,str[i]);
        //			baseColumn+=CHAR_WIDTH;		   
        //		}
        //	}
        void putstr(uint8_t ix,uint8_t iy, const  char  *str,bool bSingleLine=false,bool bFlushAtOnce=false,bool bDot=true )
        {
                int len=strlen(str);
                for(int i=0;iMAX_COLUMN-CHAR_WIDTH)
                        {	
                                if(bSingleLine) break;
                                iy+=CHAR_HEIGHT;
                                ix=0;
                        }
                        if(iy>MAX_ROW)break; 
                        putchar(ix,iy,str[i],bDot);
                        ix+=CHAR_WIDTH;		   
                }
                if( bFlushAtOnce ) flush();	
        }
        void lineSrolling(uint8_t y,const char *str,int &istr,int delay=0,bool bLeftScroll=true,bool bFlushAtOnce=false )
        {
                const int MaxStr=strlen(str);
                const int ToatalCharsIn1line= MAX_COLUMN / CHAR_WIDTH;
                char linestr[ToatalCharsIn1line];
                //从str中第istr个字开始取ToatalCharsIn1line个字符装入linestr
                if( istr>=MaxStr ) istr=0;
                if( istr<0 ) istr=MaxStr-1;		   	
                int ishow=istr;
                for(uint8_t n=0;n=MaxStr) ishow=0;
                        if(ishow<0) ishow=MaxStr-1;
                }										
                if(bLeftScroll)
                {
                        istr++;	
                } else 
                {
                        istr--;
                }
                putstr(0,y,linestr,true);
                for(int i=0;i>1)&0x08 | 
                        (dat>>3)&0x04 | 
                        (dat>>5)&0x02 | 
                        (dat>>7)&0x01 );
        }
        void SWFlipVertical()//GRAM上翻转上下
        {
                uint8_t tmp;
                for(uint8_t page=0;page<(MAX_PAGE+1)/2;page++)
                {
                        for(uint8_t column=0;columnTotal_Ascii8x16dot_Font)
                {
                        return;//非ASCII符不处理
                }  
                uint8_t imod=0;
                for(uint8_t width=0;width<8;width++)
                {
                        for(int8_t height=0;height<16/8;height++)
                        {
                                for(uint8_t dy=0;dy<=7;dy++)
                                { 
                                        bool dot= (1<Total_icon24x24 || ixIcon<0)return;
                uint8_t imod=0;				   //以ICON的长宽为索引,而非以模的元素下标
                for(uint8_t width=0;width<24;width++)
                {
                        for(int8_t height=0;height<24/8;height++)
                        {
                                for(uint8_t dy=0;dy<=7;dy++)
                                { 
                                        bool dot= (1<=MAX_COLUMN|| y>=MAX_ROW  )break;	   
                        SetPixel(x,y,bDot);
                        if( x==x2 && y==y2 ) break;//为了在相等时还能打印那一点
                        if( xx2 )x--;	
                        if( yy2 )y--; 	
                } 	
                if(bFlushAtOnce)	flush();
        }   
        ********************************************************///
        void ResetPixel(uint8_t ix,uint8_t iy)//ix,ix中的i代表索引
        {
                SetPixel(ix,iy,false);
        }	  
        void SetPixel(uint8_t ix/*0~95*/,uint8_t iy/*0~38*/,bool bDot=true)//ix,ix中的i代表索引
        {  
                //为加快显示速度,本函数只刷入GRAM
                //函数说明:在GRAM(x,y)打点,不影响其他点,不刷新flush();情况下不显示			
                //  PG9639TLBE,  分辨率: ix:0~95  iy:0~38	
                //	QG-2864KLBLG22, 分辨率: ix:0~127  iy:0~63	
                //	PG-9639有效点阵分布如下图(QG-2864类似,略)
                //  y //
                // 	D1	0	x:0................PAGE0....................95	    
                //	D2	1 
                //	D3	2
                //	D4	3
                //	D5	4
                //	D6 	5
                //	D7	6
                // 
                //	D0	7	x:0................PAGE1....................95	
                //	D1	8
                //	D2 	9
                //	D3	10
                //	D4	11
                //	D5	12
                //	D6	13
                //	D7	14
                // 
                //	D0	15	x:0................PAGE2....................95	
                //	D1 	16
                //	D2	17
                //	D3 	18
                //	D4	19
                //	D5	20
                //	D6	21
                //	D7	22
                // 
                //	D0	23	x:0................PAGE3....................95	
                //	D1	24
                //	D2	25
                //	D3	26
                //	D4	27
                //	D5	28
                //	D6	29
                //	D7	30
                // 
                //	D0	31	x:0................PAGE4....................95	
                //	D1	32
                //	D2	33
                //	D3	34
                //	D4	35
                //	D5	36
                //	D6	37
                //	D7	38 [D7不显示]	 
                / 	 
                if( iy>MAX_ROW || ix>MAX_COLUMN  )	return;
                uint8_t page=iy/8;
                uint8_t bitDn=iy%8;
                if(bDot)
                {
                        GRAM[page][ix]|=(1<0;i>>=1) //OLED从字节的高位D7输入,至到D0 -- SPI模拟
                {
                        SCLK.low();	 
                        SDIN.set(i&dat); 		
                        uDelay(15);
                        SCLK.high();		
                        uDelay(15);	 	 	 	     
                }
                //uDelay(50);
                ChipUnselected(); 
        }				 
        /TEST FUNCTION///
        void test() 
        {	
                for(uint8_t page=0;page7)i=0;
        // 				dot(page,column,bydot<7)i=0;
        // 				dot(page,column,bydot<


字符和图标字模定义如下

 

 

 

//OLED.H
//BY wisepragma
//homepage:http://blog.csdn.net/wisepragma
#pragma once
// !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

 const uint8_t Ascii8x16dot[][16]=	//加const 定义在代码空间 CHAR_WIDTH*CHAR_HEIGHT=8*16    
  //不加const  Ascii8x16dot                                    0x2000005c   Data        1520  main.o(.data)
  // 加const   Ascii8x16dot                                    0x08001d08   Data        1520  main.o(.constdata)
 
 //字体取模顺序12,34四个半字节,显示填充顺序为13,24
 // 13
 // 24

{ //@BatangChe
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*" ",0*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x33,0x00,0x00,0x00,0x00,0x00,0x00,/*"!",1*/
0x00,0x00,0x00,0x00,0x0C,0x00,0x3C,0x00,0x00,0x00,0x0C,0x00,0x3C,0x00,0x00,0x00,/*""",2*/
0x00,0x04,0x20,0x7C,0xE0,0x07,0x3E,0x04,0x20,0x7C,0xE0,0x07,0x3E,0x04,0x20,0x00,/*"#",3*/
0x00,0x00,0x30,0x08,0x48,0x30,0x84,0x20,0xFE,0x7F,0x84,0x20,0x0C,0x11,0x10,0x0E,/*"$",4*/
0x00,0x00,0x30,0x20,0x48,0x18,0x24,0x06,0x98,0x19,0x68,0x24,0x18,0x12,0x04,0x0C,/*"%",5*/
0x00,0x00,0x00,0x1E,0xB8,0x21,0xC4,0x20,0x24,0x23,0x98,0x1C,0x80,0x27,0x80,0x10,/*"&",6*/
0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"'",7*/
0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x07,0x18,0x18,0x04,0x20,0x02,0x40,0x00,0x00,/*"(",8*/
0x00,0x00,0x02,0x40,0x04,0x20,0x18,0x18,0xE0,0x07,0x00,0x00,0x00,0x00,0x00,0x00,/*")",9*/
0x00,0x00,0x00,0x00,0x20,0x02,0x40,0x01,0xF0,0x07,0x40,0x01,0x20,0x02,0x00,0x00,/*"*",10*/
0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xF8,0x0F,0x80,0x00,0x80,0x00,0x80,0x00,/*"+",11*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,/*",",12*/
0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,/*"-",13*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,/*".",14*/
0x00,0x00,0x00,0x30,0x00,0x0C,0x00,0x03,0xC0,0x00,0x30,0x00,0x0C,0x00,0x00,0x00,/*"/",15*/
0x00,0x00,0xF0,0x0F,0x08,0x10,0x04,0x20,0x04,0x20,0x04,0x20,0x08,0x10,0xF0,0x0F,/*"0",16*/
0x00,0x00,0x00,0x00,0x08,0x20,0x08,0x20,0xFC,0x3F,0x00,0x20,0x00,0x20,0x00,0x00,/*"1",17*/
0x00,0x00,0x30,0x38,0x08,0x24,0x04,0x22,0x04,0x21,0x84,0x20,0x48,0x30,0x30,0x08,/*"2",18*/
0x00,0x00,0x10,0x08,0x08,0x10,0x84,0x20,0x84,0x20,0x84,0x20,0x48,0x11,0x30,0x0E,/*"3",19*/
0x00,0x00,0x00,0x04,0x00,0x07,0xC0,0x04,0x30,0x04,0x08,0x24,0xFC,0x3F,0x00,0x24,/*"4",20*/
0x00,0x00,0xFC,0x19,0x84,0x20,0x44,0x20,0x44,0x20,0x44,0x20,0x84,0x10,0x00,0x0F,/*"5",21*/
0x00,0x00,0xF0,0x0F,0x88,0x10,0x44,0x20,0x44,0x20,0x44,0x20,0x84,0x10,0x18,0x0F,/*"6",22*/
0x00,0x00,0x10,0x00,0x0C,0x00,0x04,0x00,0x04,0x3C,0x84,0x03,0x64,0x00,0x1C,0x00,/*"7",23*/
0x00,0x00,0x30,0x0E,0x48,0x11,0x84,0x20,0x84,0x20,0x84,0x20,0x48,0x11,0x30,0x0E,/*"8",24*/
0x00,0x00,0xF0,0x08,0x08,0x11,0x04,0x22,0x04,0x22,0x04,0x22,0x08,0x11,0xF0,0x0F,/*"9",25*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,/*":",26*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x30,0x18,0x00,0x00,0x00,0x00,0x00,0x00,/*";",27*/
0x00,0x00,0x80,0x00,0x40,0x01,0x40,0x01,0x20,0x02,0x20,0x02,0x10,0x04,0x10,0x04,/*"<",28*/
0x00,0x00,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,0x40,0x02,/*"=",29*/
0x00,0x00,0x10,0x04,0x10,0x04,0x20,0x02,0x20,0x02,0x40,0x01,0x40,0x01,0x80,0x00,/*">",30*/
0x00,0x00,0x18,0x00,0x04,0x00,0x02,0x00,0x02,0x37,0x82,0x00,0x44,0x00,0x38,0x00,/*"?",31*/
0x00,0x00,0xF0,0x1F,0x08,0x20,0xC4,0x47,0x24,0x48,0xE4,0x47,0x08,0x48,0xF0,0x2F,/*"@",32*/
0x00,0x00,0x00,0x20,0x00,0x3F,0xE0,0x24,0x1C,0x04,0xE0,0x24,0x00,0x3F,0x00,0x20,/*"A",33*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x84,0x20,0x84,0x20,0x84,0x20,0x84,0x20,0x78,0x1F,/*"B",34*/
0x00,0x00,0xF0,0x0F,0x08,0x10,0x04,0x20,0x04,0x20,0x04,0x20,0x0C,0x10,0x10,0x0C,/*"C",35*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x04,0x20,0x04,0x20,0x04,0x20,0x08,0x10,0xF0,0x0F,/*"D",36*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x84,0x20,0x84,0x20,0x84,0x20,0xCC,0x31,0x10,0x08,/*"E",37*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x84,0x20,0x84,0x20,0x84,0x00,0xCC,0x01,0x10,0x00,/*"F",38*/
0x00,0x00,0xF0,0x0F,0x08,0x10,0x04,0x20,0x04,0x20,0x08,0x11,0x0C,0x3F,0x10,0x01,/*"G",39*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x84,0x20,0x80,0x00,0x84,0x20,0xFC,0x3F,0x04,0x20,/*"H",40*/
0x00,0x00,0x00,0x00,0x04,0x20,0x04,0x20,0xFC,0x3F,0x04,0x20,0x04,0x20,0x00,0x00,/*"I",41*/
0x00,0x00,0x00,0x18,0x00,0x20,0x04,0x20,0x04,0x20,0xFC,0x1F,0x04,0x00,0x04,0x00,/*"J",42*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x84,0x20,0x40,0x01,0x34,0x26,0x0C,0x38,0x04,0x20,/*"K",43*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x04,0x20,0x00,0x20,0x00,0x20,0x00,0x30,0x00,0x08,/*"L",44*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x70,0x20,0x80,0x03,0x70,0x20,0xFC,0x3F,0x04,0x20,/*"M",45*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x70,0x20,0x80,0x01,0x04,0x0E,0xFC,0x3F,0x04,0x00,/*"N",46*/
0x00,0x00,0xF0,0x0F,0x08,0x10,0x04,0x20,0x04,0x20,0x04,0x20,0x08,0x10,0xF0,0x0F,/*"O",47*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x04,0x21,0x04,0x01,0x04,0x01,0x88,0x00,0x70,0x00,/*"P",48*/
0x00,0x00,0xF0,0x0F,0x08,0x10,0x04,0x28,0x04,0x28,0x04,0x28,0x08,0x30,0xF0,0x4F,/*"Q",49*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x04,0x21,0x04,0x01,0x88,0x02,0x70,0x3C,0x00,0x20,/*"R",50*/
0x00,0x00,0x30,0x08,0x48,0x30,0x84,0x20,0x84,0x20,0x04,0x21,0x0C,0x11,0x10,0x0E,/*"S",51*/
0x00,0x00,0x10,0x00,0x0C,0x00,0x04,0x20,0xFC,0x3F,0x04,0x20,0x0C,0x00,0x10,0x00,/*"T",52*/
0x00,0x00,0x04,0x00,0xFC,0x1F,0x04,0x20,0x00,0x20,0x04,0x20,0xFC,0x1F,0x04,0x00,/*"U",53*/
0x00,0x00,0x04,0x00,0x7C,0x00,0x84,0x07,0x00,0x38,0x84,0x07,0x7C,0x00,0x04,0x00,/*"V",54*/
0x00,0x00,0x04,0x00,0xFC,0x03,0x04,0x3C,0xF0,0x03,0x04,0x3C,0xFC,0x03,0x04,0x00,/*"W",55*/
0x00,0x00,0x04,0x20,0x1C,0x38,0x64,0x26,0x80,0x01,0x64,0x26,0x1C,0x38,0x04,0x20,/*"X",56*/
0x00,0x00,0x04,0x00,0x1C,0x00,0xE4,0x20,0x00,0x3F,0xE4,0x20,0x1C,0x00,0x04,0x00,/*"Y",57*/
0x00,0x00,0x10,0x38,0x0C,0x24,0x04,0x23,0x84,0x20,0x64,0x20,0x1C,0x30,0x04,0x08,/*"Z",58*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x7F,0x02,0x40,0x02,0x40,0x00,0x00,/*"[",59*/
0x0C,0x00,0x30,0x00,0xC0,0x00,0x00,0x03,0x00,0x0C,0x00,0x30,0x00,0x00,0x00,0x00,/*"\"fixed,60*/
0x00,0x00,0x00,0x00,0x02,0x40,0x02,0x40,0xFE,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,/*"]",61*/
0x00,0x00,0x08,0x00,0x04,0x00,0x02,0x00,0x02,0x00,0x04,0x00,0x08,0x00,0x00,0x00,/*"^",62*/
0x00,0x00,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,0x00,0x40,/*"_",63*/
0x00,0x00,0x00,0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"`",64*/
0x00,0x00,0x80,0x1C,0x40,0x22,0x40,0x22,0x40,0x22,0x40,0x12,0x80,0x3F,0x00,0x20,/*"a",65*/
0x00,0x00,0x04,0x00,0xFC,0x3F,0x80,0x10,0x40,0x20,0x40,0x20,0x80,0x10,0x00,0x0F,/*"b",66*/
0x00,0x00,0x00,0x0F,0x80,0x10,0x40,0x20,0x40,0x20,0x40,0x20,0x80,0x10,0x00,0x00,/*"c",67*/
0x00,0x00,0x00,0x0F,0x80,0x10,0x40,0x20,0x40,0x20,0x84,0x10,0xFC,0x3F,0x00,0x20,/*"d",68*/
0x00,0x00,0x80,0x1F,0x40,0x22,0x40,0x22,0x40,0x22,0x40,0x22,0x80,0x13,0x00,0x00,/*"e",69*/
0x00,0x00,0x40,0x00,0x40,0x20,0xF8,0x3F,0x44,0x20,0x44,0x00,0x08,0x00,0x00,0x00,/*"f",70*/
0x00,0x00,0x00,0x34,0x80,0x4B,0x40,0x4A,0x40,0x4A,0x40,0x4A,0x80,0x49,0x40,0x30,/*"g",71*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x80,0x20,0x40,0x00,0x40,0x20,0x80,0x3F,0x00,0x20,/*"h",72*/
0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x20,0xCC,0x3F,0x00,0x20,0x00,0x00,0x00,0x00,/*"i",73*/
0x00,0x00,0x00,0x20,0x00,0x40,0x40,0x40,0xCC,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,/*"j",74*/
0x00,0x00,0x04,0x20,0xFC,0x3F,0x00,0x22,0x40,0x05,0xC0,0x28,0x40,0x30,0x00,0x20,/*"k",75*/
0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x20,0xFC,0x3F,0x00,0x20,0x00,0x00,0x00,0x00,/*"l",76*/
0x80,0x20,0xC0,0x3F,0x80,0x20,0x40,0x00,0x80,0x3F,0x40,0x00,0x40,0x20,0x80,0x3F,/*"m",77*/
0x00,0x00,0x80,0x20,0xC0,0x3F,0x80,0x20,0x40,0x00,0x40,0x20,0x80,0x3F,0x00,0x20,/*"n",78*/
0x00,0x00,0x00,0x0F,0x80,0x10,0x40,0x20,0x40,0x20,0x40,0x20,0x80,0x10,0x00,0x0F,/*"o",79*/
0x00,0x00,0x40,0x40,0xC0,0x7F,0x80,0x48,0x40,0x10,0x40,0x10,0x80,0x08,0x00,0x07,/*"p",80*/
0x00,0x00,0x00,0x07,0x80,0x08,0x40,0x10,0x40,0x10,0x80,0x48,0xC0,0x7F,0x40,0x40,/*"q",81*/
0x00,0x00,0x00,0x00,0x40,0x20,0xC0,0x3F,0x80,0x20,0x40,0x00,0x40,0x00,0x00,0x00,/*"r",82*/
0x00,0x00,0x80,0x09,0x40,0x32,0x40,0x22,0x40,0x24,0xC0,0x24,0x00,0x19,0x00,0x00,/*"s",83*/
0x00,0x00,0x40,0x00,0x40,0x00,0xF8,0x1F,0x40,0x20,0x40,0x20,0x00,0x10,0x00,0x00,/*"t",84*/
0x00,0x00,0x40,0x00,0xC0,0x1F,0x00,0x20,0x00,0x20,0x00,0x20,0x40,0x10,0xC0,0x3F,/*"u",85*/
0x00,0x00,0x40,0x00,0xC0,0x01,0x40,0x0E,0x00,0x30,0x40,0x0E,0xC0,0x01,0x40,0x00,/*"v",86*/
0x00,0x00,0x40,0x00,0xC0,0x07,0x40,0x38,0x00,0x06,0x40,0x38,0xC0,0x07,0x40,0x00,/*"w",87*/
0x00,0x00,0x40,0x20,0xC0,0x30,0x40,0x29,0x00,0x06,0x40,0x29,0xC0,0x30,0x40,0x20,/*"x",88*/
0x00,0x00,0x40,0x60,0xC0,0x41,0x40,0x26,0x00,0x18,0x40,0x06,0xC0,0x01,0x40,0x00,/*"y",89*/
0x00,0x00,0x00,0x31,0xC0,0x28,0x40,0x24,0x40,0x22,0x40,0x21,0xC0,0x30,0x40,0x08,/*"z",90*/
0x00,0x00,0x00,0x00,0x80,0x00,0x80,0x00,0x7C,0x3F,0x02,0x40,0x02,0x40,0x00,0x00,/*"{",91*/
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,/*"|",92*/
0x00,0x00,0x02,0x40,0x02,0x40,0x7C,0x3F,0x80,0x00,0x80,0x00,0x00,0x00,0x00,0x00,/*"}",93*/
0x00,0x00,0x00,0x01,0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x01,0x00,0x01,0x80,0x00,/*"~",94*/
};

const uint8_t icon24x24[][3*24]=
{
//clear(0),
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,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, 
//bluetooth_black(1),
0x00,0x7E,0x00,0xC0,0xFF,0x03,0xE0,0xFF,0x0F,0xF8,0xFF,0x1F,0xD8,0xFF,0x1B,0xBC,0xFF,0x3D,0x7E,0xFF,0x7E,0xFE,0x7E,0x7F,
0xFF,0xBD,0xFF,0xFF,0xDB,0xFF,0x01,0x00,0x80,0xFD,0xE7,0xBF,0xFB,0xDB,0x9F,0xF6,0xBD,0x6F,0xEE,0x7E,0x77,0x5C,0xFF,0x3A,
0xB8,0xFF,0x1D,0xF8,0xFF,0x1F,0xE0,0xFF,0x07,0xC0,0xFF,0x03,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
//bluetooth white(2),
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x08,0x20,0x00,0x04,0x40,0x00,0x02,0x80,0x00,0x01,0x00,0x81,0x00,
0x00,0x42,0x00,0x00,0x24,0x00,0xFF,0xFF,0xFF,0x02,0x18,0x40,0x04,0x24,0x20,0x08,0x42,0x10,0x10,0x81,0x08,0xA0,0x00,0x05,
0x40,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
//brightness(3),
0x00,0x10,0x00,0x04,0x10,0x20,0x08,0x10,0x10,0x10,0x00,0x08,0x20,0x3C,0x04,0x00,0xC3,0x00,0x80,0x00,0x01,0x40,0x00,0x02,
0x40,0x00,0x02,0x20,0x00,0x04,0x20,0x00,0x04,0x2F,0x00,0xF4,0x20,0x00,0x04,0x20,0x00,0x04,0x40,0x00,0x02,0x40,0x00,0x02,
0x80,0x00,0x01,0x00,0xC3,0x00,0x10,0x3C,0x04,0x08,0x00,0x08,0x04,0x10,0x10,0x02,0x10,0x20,0x00,0x10,0x00,0x00,0x00,0x00, 
//hand(4),
0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x09,0x00,0x00,0x31,0x00,0x00,0xC2,0x00,0x00,0x02,0x03,0x00,0x04,0x0C,0xFE,0x1F,0xF8,
0x01,0x00,0x80,0x01,0x00,0x80,0xFE,0x03,0x80,0x30,0x00,0x80,0x10,0x00,0x80,0xE0,0x07,0x80,0x60,0x00,0x80,0x20,0x00,0x80,
0xC0,0x0F,0xF0,0x80,0x01,0x1C,0x80,0x01,0x03,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
//loudspeaker(5),
0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xFF,0x0F,0xF0,0xFF,0x0F,0xF0,0xFF,0x0F,0xF0,0xFF,0x0F,0xF0,0xFF,0x0F,0xF0,0xFF,0x0F,
0xF0,0xFF,0x0F,0x10,0x00,0x08,0x08,0x00,0x10,0x04,0x00,0x20,0x02,0x00,0x40,0x01,0x00,0x80,0xFF,0xFF,0xFF,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, 
//music(6),
0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x7C,0x00,0x00,0x7C,0x00,0x00,0x7C,0xE0,0xFF,0x3F,0x20,0x00,0x00,0x10,0x00,0x00,
0x10,0x00,0x00,0x10,0x00,0x00,0x10,0x00,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x04,0x00,0x0E,0x04,0x00,0x1F,
0x04,0x00,0x1F,0x04,0x00,0x1F,0xFC,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 
//paper(7),
0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFF,0x7F,0x02,0x00,0x40,0x02,0x00,0x40,0x02,0x00,0x40,0x02,0x00,0x40,0x02,0x00,0x40,
0x02,0x00,0x40,0x02,0x00,0x40,0x02,0x00,0x40,0x02,0x00,0x40,0x02,0x00,0x40,0x02,0x00,0x40,0xFE,0x03,0x40,0x04,0x02,0x40,
0x08,0x02,0x40,0x10,0x02,0x40,0x20,0x02,0x40,0x40,0x02,0x40,0x80,0x02,0x40,0x00,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,
//tree(8),
0x00,0x00,0x00,0x00,0x80,0x03,0x30,0x40,0x06,0x48,0x5E,0x04,0xCC,0x61,0x46,0xE2,0xC0,0x43,0x62,0x86,0x40,0x24,0x8F,0x60,
0x9C,0xB8,0x78,0xD0,0xA4,0x7C,0x90,0xFC,0x7E,0x90,0x41,0x7F,0x20,0x21,0x67,0x20,0x9E,0x63,0xC0,0xC0,0x61,0x80,0xFF,0x60,
0xD8,0x48,0x60,0x34,0xE4,0x40,0x54,0x34,0x41,0xD8,0x6C,0x41,0x84,0x98,0x41,0x64,0xF4,0x00,0x18,0x78,0x00,0x00,0x00,0x00,
//USB(9),
0x00,0x1C,0x00,0x00,0x3E,0x00,0x00,0x3E,0x00,0x00,0x1C,0x00,0x00,0x08,0x00,0x00,0x0E,0x00,0x00,0x0B,0x00,0x80,0x38,0x00,
0x80,0x68,0x00,0x40,0x88,0x00,0x60,0x08,0x01,0xF0,0x08,0x02,0xF0,0x08,0x02,0x60,0x88,0x07,0x00,0x88,0x07,0x00,0x88,0x07,
0x00,0x88,0x07,0x00,0x08,0x00,0x00,0x08,0x00,0x80,0x88,0x00,0x00,0x49,0x00,0x00,0x2A,0x00,0x00,0x1C,0x00,0x00,0x08,0x00, 
//wlan(10),
0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x03,0x00,0x80,0x18,0x00,0x40,0x06,0x00,0x20,0x31,0x00,0xA0,0x08,0x00,0x50,0x04,0x00,
0x50,0x12,0x00,0x50,0xCA,0x01,0x28,0xE5,0x03,0x28,0xF5,0x07,0x28,0xF5,0x07,0x28,0xE5,0x03,0x50,0xCA,0x01,0x50,0x12,0x00,
0x50,0x04,0x00,0xA0,0x08,0x00,0x20,0x31,0x00,0x40,0x06,0x00,0x80,0x18,0x00,0x00,0x03,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,  
//setting(11),
0x00,0x00,0x00,0x00,0x3C,0x00,0x00,0x24,0x00,0x10,0xFF,0x08,0xE8,0xFF,0x17,0xC4,0xFF,0x23,0xE8,0xE7,0x17,0xF0,0x81,0x0F,
0xF0,0x00,0x0F,0x78,0x00,0x1E,0x3E,0x00,0x7E,0x3A,0x00,0x5C,0x3A,0x00,0x5C,0x3E,0x00,0x7E,0x78,0x00,0x1E,0xF0,0x00,0x0F,
0xF0,0x81,0x0F,0xE8,0xE7,0x17,0xC4,0xFF,0x23,0xE8,0xFF,0x17,0x10,0xFF,0x08,0x00,0x24,0x00,0x00,0x3C,0x00,0x00,0x00,0x00, 
//setting2(12),
0x00,0x00,0x00,0x80,0x3C,0x01,0x20,0xA5,0x04,0x50,0x7E,0x0A,0x88,0xFF,0x11,0xD0,0xFF,0x0B,0xF0,0xC3,0x4F,0xF4,0x81,0x2F,
0xF8,0x00,0x1F,0x78,0x00,0x1E,0x7E,0x00,0x7E,0x3A,0x00,0x5C,0x3A,0x00,0x5C,0x7E,0x00,0x7E,0x78,0x00,0x1E,0xF8,0x00,0x1F,
0xF8,0x81,0x2F,0xF4,0xE7,0x4F,0xD0,0xFF,0x0B,0x88,0xFF,0x11,0x50,0xFE,0x0A,0x20,0xA5,0x04,0x80,0x3C,0x01,0x00,0x00,0x00, 
//setting3(13),
0x00,0x00,0x00,0x80,0x3C,0x01,0x20,0xA5,0x04,0x50,0x7E,0x0A,0x88,0xFF,0x11,0xD0,0xFF,0x0B,0xF0,0xC3,0x4F,0xF4,0x81,0x2F,
0xF8,0x00,0x1F,0x78,0x00,0x1E,0x7E,0x00,0x7E,0x3A,0x00,0x5C,0x3A,0x00,0x5C,0x7E,0x00,0x7E,0x78,0x00,0x1E,0xF8,0x00,0x1F,
0xF8,0x81,0x2F,0xF4,0xE7,0x4F,0xD0,0xFF,0x0B,0x88,0xFF,0x11,0x50,0xFE,0x0A,0x20,0xA5,0x04,0x80,0x3C,0x01,0x00,0x00,0x00, 
//setting4(14),
0x00,0x18,0x00,0x80,0x18,0x01,0xC0,0xBD,0x03,0x90,0xC3,0x09,0x78,0x00,0x1E,0x30,0x00,0x0C,0x54,0x00,0x2A,0x8E,0x00,0x71,
0x0C,0x81,0x30,0x08,0x42,0x10,0x04,0x3C,0x20,0x0F,0x24,0xE0,0x0F,0x24,0xE0,0x04,0x3C,0x20,0x08,0x42,0x10,0x0C,0x81,0x30,
0x8E,0x00,0x71,0x54,0x00,0x2A,0x30,0x00,0x0C,0x78,0x00,0x1E,0x90,0xC3,0x09,0xC0,0xBD,0x03,0x80,0x18,0x01,0x00,0x18,0x00,
//setting5(15),	  x0.bmp(0)	 
0x00,0x18,0x00,0x80,0x18,0x01,0xC0,0xBD,0x03,0x90,0xCB,0x09,0x78,0x10,0x1E,0x30,0x08,0x0C,0x14,0x10,0x28,0x0E,0x08,0x70,
0x0C,0x10,0x30,0x08,0x08,0x10,0x04,0x3C,0x20,0x5F,0xA5,0xEA,0xAF,0x66,0xF5,0x04,0x3C,0x20,0x08,0x08,0x10,0x0C,0x10,0x30,
0x0E,0x08,0x70,0x14,0x10,0x28,0x30,0x08,0x0C,0x78,0x10,0x1E,0x90,0xCB,0x09,0xC0,0xBD,0x03,0x80,0x18,0x01,0x00,0x18,0x00,
//电池0(16),
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x04,0x00,0x40,0x06,0x00,0x40,
0x06,0x00,0x40,0x06,0x00,0x40,0x06,0x00,0x40,0x06,0x00,0x40,0x06,0x00,0x40,0x06,0x00,0x40,0x06,0x00,0x40,0x06,0x00,0x40,
0x06,0x00,0x40,0x04,0x00,0x40,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//电池0(17),
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x04,0x00,0x40,0x06,0x00,0x58,
0x06,0x00,0x58,0x06,0x00,0x58,0x06,0x00,0x58,0x06,0x00,0x58,0x06,0x00,0x58,0x06,0x00,0x58,0x06,0x00,0x58,0x06,0x00,0x58,
0x06,0x00,0x58,0x04,0x00,0x40,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//电池0(18),
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x04,0x00,0x40,0x06,0x00,0x5B,
0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,
0x06,0x00,0x5B,0x04,0x00,0x40,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//电池0(19),
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x04,0x00,0x40,0x06,0x00,0x5B,
0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,0x06,0x00,0x5B,
0x06,0x00,0x5B,0x04,0x00,0x40,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//电池0(20),
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x04,0x00,0x40,0x06,0x60,0x5B,
0x06,0x60,0x5B,0x06,0x60,0x5B,0x06,0x60,0x5B,0x06,0x60,0x5B,0x06,0x60,0x5B,0x06,0x60,0x5B,0x06,0x60,0x5B,0x06,0x60,0x5B,
0x06,0x60,0x5B,0x04,0x00,0x40,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//电池0(21),
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x04,0x00,0x40,0x06,0x6C,0x5B,
0x06,0x6C,0x5B,0x06,0x6C,0x5B,0x06,0x6C,0x5B,0x06,0x6C,0x5B,0x06,0x6C,0x5B,0x06,0x6C,0x5B,0x06,0x6C,0x5B,0x06,0x6C,0x5B,
0x06,0x6C,0x5B,0x04,0x00,0x40,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//电池0(22),
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x04,0x00,0x40,0x86,0x6D,0x5B,
0x86,0x6D,0x5B,0x86,0x6D,0x5B,0x86,0x6D,0x5B,0x86,0x6D,0x5B,0x86,0x6D,0x5B,0x86,0x6D,0x5B,0x86,0x6D,0x5B,0x86,0x6D,0x5B,
0x86,0x6D,0x5B,0x04,0x00,0x40,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//电池0(23),
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x04,0x00,0x40,0xB6,0x6D,0x5B,
0xB6,0x6D,0x5B,0xB6,0x6D,0x5B,0xB6,0x6D,0x5B,0xB6,0x6D,0x5B,0xB6,0x6D,0x5B,0xB6,0x6D,0x5B,0xB6,0x6D,0x5B,0xB6,0x6D,0x5B,
0xB6,0x6D,0x5B,0x04,0x00,0x40,0xFC,0xFF,0x7F,0xFC,0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
  											   
const int Total_icon24x24=sizeof(icon24x24)/sizeof(icon24x24[0]);//[ERROR]	sizeof(icon24x24)/sizeof(icon24x24[0][3*24]);
const int Total_Ascii8x16dot_Font=sizeof(Ascii8x16dot)/sizeof(Ascii8x16dot[0]);	 //[ERROR]sizeof(Ascii8x16dot)/sizeof(Ascii8x16dot[0][16]);	


使用PG9639TLBE的OLED_CONFIG,测试代码

 

 

 

 	enum	 
 	{
	//OLED PG9639TLBE
	//PAGE0:D1~D7填入,PAGE1~PAGE4:D0~D7;填入方向从上往下
	//分辨率为:96x39 即Xpixel:96 columns Ypixel:5pages=7rows+8*(4page) rows=7+8*4=39 rows
		MAX_PAGE=5,	  //7+8*4 ROWS 范围:0~MAX_PAGE-1
		MAX_COLUMN= 96, //, //分辨率:横向96点  范围:0~MAX_COLUMN-1  96
		MAX_ROW= 39, //分辨率:纵向39点 范围:0~MAX_ROW-1   39
 		COLUMN_OFFSET_ADDRINC=32,
		CHAR_WIDTH=8,
		CHAR_HEIGHT=16,	
		DEFAULT_BRIGHTNESS=0x14,
		MAX_DELAY_POWERUP=30000//用户自己调节,加入上电延时保证可靠显示
	}OLED_CONFIG;	

 

 

 

 

 

//MAIN.CPP
#include "stm32f10x.h"
#include "stm32pin.h"
#include "oled.h"

void  test_oled(OLED &oledx)
{
		oledx.drawicon(0,0,4,false/*bFlushAtOnce*/,true/*bDot*/);  
		oledx.drawicon(24,0,6,false/*bFlushAtOnce*/,true/*bDot*/);  
		oledx.drawicon(48,0,14,false/*bFlushAtOnce*/,true/*bDot*/);  
		oledx.drawicon(72,0,8,false/*bFlushAtOnce*/,true/*bDot*/);  
		oledx.putstr(0,24, "wisepragma:)",true/*bSingleLine*/,true/*bFlushAtOnce*/,false/*bDot*/ );
}


int main()
{
		STM32PIN sclk(PC,8);
		STM32PIN sdin(PA,8);
		STM32PIN ncs(PE,6);
		STM32PIN cmd(PC,9); 
		OLED oled(sclk,sdin,ncs,cmd,0);
 
		test_oled(oled);
		while(true);
}

 

 


疯狂单片机--用C++写STM32程序-OLED_第4张图片

 

 

 

 

 

 

 

 

使用QG-2864KLBLG22的测试代码

enum  
{
        MAX_PAGE=8,  
        MAX_COLUMN=128, 
        MAX_ROW=64, 
        COLUMN_OFFSET_ADDRINC=2,
        CHAR_WIDTH=8,
        CHAR_HEIGHT=16,
        DEFAULT_BRIGHTNESS=0x14,
        MAX_DELAY_POWERUP=30000
}OLED_CONFIG;
 

//MAIN.CPP
//BY wisepragma
//homepage:http://blog.csdn.net/wisepragma
#include "stm32f10x.h"
#include "stm32pin.h"
#include "oled.h"

void  test_oled(OLED &oledx)
{
		oledx.drawicon(0,0,4,false/*bFlushAtOnce*/,true/*bDot*/);  
		oledx.drawicon(24,0,6,false/*bFlushAtOnce*/,true/*bDot*/);  
		oledx.drawicon(48,0,14,false/*bFlushAtOnce*/,true/*bDot*/);  
		oledx.drawicon(72,0,8,false/*bFlushAtOnce*/,true/*bDot*/);  
		oledx.putstr(0,24, "wisepragma:)",true/*bSingleLine*/,true/*bFlushAtOnce*/,false/*bDot*/ );
}

	//局部定义下面text堆栈不够黑屏
	const  char text[]="[START][In the east there is a shark which is larger than all other fish. It changes into a bird whose winds are like clouds filling the sky. When this bird moves across the land, it brings a message from Corporate Headquarters. This message it drops into the midst of the program- mers, like a seagull making its mark upon the beach. Then the bird mounts on the wind and, with the blue sky at its back, returns home. The novice programmer stares in wonder at the bird, for he understands it not. The average programmer dreads the coming of the bird, for he fears its message. The master programmer continues to work at his terminal, for he does not know that the bird has come and gone.When you have learned to snatch the error code from the trap frame, it will be time for you to leave.[The highest sounds are the hardest to hear. Going forward is a way to retreat.Greater talent shows itself late in life. Even a perfect program still has bugs.Grand Master Turing once dreamed that he was a machine. When he awoke he exclaimed: \"I don't know whether I am Turing dreaming that I am a machine, or a machine dreaming that I am Turing!\"][END]";
	const  char homepage[]="HOME PAGE:  ^_^   http://blog.csdn.net/wisepragma  ";
 
	void OLED_IconTextRolling_loop(OLED &oledx)
	{
		int  cnt=0;//滚动索引 
		int iScroll[3]={0};//滚动索引 
		int icon[5]={1,14,8,16,4};//滚动索引 
		bool bop=false;
		oledx.fill();
	 	while(true) 
		 {	

				if(iScroll[0]%50==0)bop=!bop; 					 
				oledx .drawicon(0,0,icon[0],false/*bFlushAtOnce*/,bop/*bDot*/);	  					
				oledx .drawicon(24,0,icon[1],false/*bFlushAtOnce*/,bop/*bDot*/);	   
				oledx .drawicon(48,0,icon[2],false/*bFlushAtOnce*/,bop/*bDot*/);		  		
				oledx .drawicon(72,0,icon[3],false/*bFlushAtOnce*/,bop/*bDot*/);   					  
				oledx .drawicon(100,0,icon[4],false/*bFlushAtOnce*/,!bop/*bDot*/);   					  
				icon[3]++;if(icon[3]>23)icon[3]=16; 
				icon[1]++;if(icon[1]>15)icon[1]=14;
				cnt++;
				if(cnt>30)
				{ 
					cnt=0;
					icon[0]++;
					if(icon[0]>10)icon[0]=1;
				}
				icon[2]=(icon[2]==8)?0:8;
				oledx.lineSrolling(26,homepage,iScroll[0],0/*delay*/,false/*bLeftScroll*/,false/*bFlushAtOnce*/);		
				oledx.lineSrolling(45,text,iScroll[1],0/*delay*/,true/*bLeftScroll*/,true/*bFlushAtOnce*/);		
				for(uint32_t t=0;t<1000000;t++);
		}
	}

int main()
{
		STM32PIN sclk(PC,8);
		STM32PIN sdin(PA,8);
		STM32PIN ncs(PE,6);
		STM32PIN cmd(PC,9); 
		OLED oled(sclk,sdin,ncs,cmd,0);
		OLED_IconTextRolling_loop(oled);
		//test_oled(oled);
		//while(true);
}


使用模拟时序的好处就是,可以使用任意的GPIO引脚驱动OLED

完整工程文件

 

 

 

 

 

 

 

 

你可能感兴趣的:([单片机编程],stm32,单片机,c++,OLED)