|
制作出來的電路實(shí)物圖如下:
STC15F2K60S2單片機(jī)源程序如下:
oled12864.h
- /*********************************************************************************************************************
- *1.oled12864模塊頭文件( SSD1306驅(qū)動(dòng)IC)
- *2.文件:oled12864.h
- *4.版本: V1.0
- *************************************************說明事項(xiàng)*****************************************************************
- * ssd1306本身支持多種總線驅(qū)動(dòng)方式包括SPI以及并口等,通過芯片的相應(yīng)IO口拉低拉高來選擇哪一種接口,0x78為IIC接口,0x7A為SOI接口
- *使用I2C接口時(shí),SSD1306允許有最多兩個(gè)7位的I2C地址,同樣通過相應(yīng)的IO口拉低拉高來切換,一般默認(rèn)是0x3c,在屏幕模塊的背面,
- *可以看到一個(gè)I2C地址切換提示,需要改變模塊I2C地址時(shí),只需要把提示位置的電阻取下焊接到另外一端即可。
- *要注意的是板上的I2C地址是加上了第零位讀寫位后的數(shù)值,即0x78 = 0x3c<<1 0x7A = 0x3d<<1,
- *SSD1306支持多種控制方式,I2C、6800、8080、4線SPI、3線SPI,通過SSD1306的3個(gè)引腳 BS0、BS1、BS2接不同的電平來選擇控制方式,
- *I2C控制:BS0=0、BS1=1、BS2=0;
- *6800控制:BS0=0、BS1=0、BS2=1;
- *8080控制:BS0=0、BS1=1、BS2=1;
- *4線SPI控制:BS0=0、BS1=0、BS2=0;
- *3線SPI控制:BS0=1、BS1=0、BS2=0;
- *從機(jī)地址是由七個(gè)位組成的,如上圖框起來的高七位,這里說明了SSD1306的從地址高六位是固定的,只有第七位受SA0控制,
- *如果這個(gè)位為邏輯0,地址則是0x78,如果為邏輯1則是0x7A。一般情況下看一下背面就可以了,廠家一般會(huì)默認(rèn)選擇搞成0x78
- ***********************************************************************************************************************/
- #ifndef _OLED12864_H_
- #define _OLED12864_H_
- #include "IIC.h"
- #include "Font.h"
- #define BIRGTHNESS //OLED的亮度 00~255,0xcf;
- #define X_WIDTH 128 //屏幕寬度
- #define Y_HIGH (8*8) //屏幕高度
- #define IIC_OLED_ADDR_W 0x78 //OLED器件地址,7位地址,高位為0表示寫,為1表示讀,//通過調(diào)整0R電阻,屏可以0x78和0x7A兩個(gè)地址 -- 默認(rèn)0x78
- #define Brightness 0xCF
- //void OLED_Write_Command(unsigned char IIC_Command);
- //void OLED_Write_Data(unsigned char IIC_Data);
- void OLED_Init(void);
- void OLED_Clear(void);
- void OLED_ON(void);
- void OLED_OFF(void);
- //void OLED_ShowStr(unsigned char x, unsigned char y, unsigned char ch[]);
- void OLED_ShowChinese(unsigned char x, unsigned char y, unsigned char Num);
- void OLED_ShowStr(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize);
- /****************************************************************************
- *函數(shù)名稱:void OLED_Write_Command(unsigned char IIC_Command)
- *函數(shù)功能:寫OLED命令; 此函數(shù)實(shí)測OK
- *輸入: unsigned char IIC_Command
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_Write_Command(unsigned char IIC_Command)
- {
-
- IIC_Start(); //啟動(dòng)I2C
- IIC_Send_Byte(IIC_OLED_ADDR_W); //D/C #=0; R/W #=0;寫IIC器件地址
- IIC_Wait_Ack();
- IIC_Send_Byte(0x00); //寄存器地址,告訴指令解析器,接下來的是一個(gè)指令
- IIC_Wait_Ack();
- IIC_Send_Byte(IIC_Command); //寫命令
- IIC_Wait_Ack();
- IIC_Stop();
-
- }
- /****************************************************************************
- *函數(shù)名稱:bit OLED12864_Write_Commmand(unsigned char cmd, bit start, bit stop)
- *函數(shù)功能:寫指令函數(shù),第一個(gè)參數(shù)為指令,第二、三個(gè)參數(shù)選擇是否需要通信開始和結(jié)束函數(shù),=1有,=0沒有
- *輸入: unsigned char IIC_Command
- *輸出: 無
- *****************************************************************************/
- /***************/
- /*****************************************************
- bit OLED12864_Write_Commmand(unsigned char cmd, bit start, bit stop)
- {
- if(start)
- {
- IIC_Start(); //啟動(dòng)I2C
- IIC_Send_Byte(IIC_OLED_ADDR_W);//寫從機(jī)地址,并且加上讀寫標(biāo)志位(最后一位)
- if(!Test_ack())
- {
- return 0;
- } //執(zhí)行從機(jī)應(yīng)答檢測函數(shù),如果從機(jī)發(fā)送了非應(yīng)答信號,那么就退出數(shù)據(jù)發(fā)送函數(shù)
- }
- }
- **********************************************************/
- /*********************************************************
- unsigned char OLED_Write_Command(unsigned char IIC_Command)
- {
-
- I2C_Start(); //啟動(dòng)I2C
- IIC_Send_Byte(I2C_OLED_ADDR_W); //D/C #=0; R/W #=0;寫IIC器件地址
- if(IIC_Wait_Ack())
- return 1;
- IIC_Send_Byte(0x00); // 告訴指令解析器,接下來的是一個(gè)指令
- if(IIC_Wait_Ack())
- return 2;
- IIC_Send_Byte(IIC_Command); //寫命令
- if(IIC_Wait_Ack())
- return 3;
- I2C_Stop();
- return 0;
- }
- ***********************************************************/
- /****************************************************************************
- *函數(shù)名稱:unsigned char OLED_Write_Data(unsigned char IIC_Data)
- *函數(shù)功能:寫OLED數(shù)據(jù); 此函數(shù)實(shí)測OK
- *輸入: unsigned char IIC_Data
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_Write_Data(unsigned char IIC_Data)
- {
-
- IIC_Start(); //啟動(dòng)I2C
- IIC_Send_Byte(IIC_OLED_ADDR_W); //D/C #=0; R/W #=0;寫IIC器件地址
- IIC_Wait_Ack();
- IIC_Send_Byte(0x40); //寄存器地址告訴指令解析器,接下來的是一個(gè)數(shù)據(jù)
- IIC_Wait_Ack();
- IIC_Send_Byte(IIC_Data); //寫數(shù)據(jù)
- IIC_Wait_Ack();
- IIC_Stop();
-
- }
- /*****************************************************
- static unsigned char OLED_Write_Data(unsigned char IIC_Data)
- {
- I2C_Start(); //啟動(dòng)I2C
- IIC_Send_Byte(I2C_OLED_ADDR_W); //D/C #=0; R/W #=0;寫IIC器件地址
- if(IIC_Wait_Ack());
- return 1;
- IIC_Send_Byte(0x40); //告訴指令解析器,接下來的是一個(gè)指令
- if(IIC_Wait_Ack());
- return 2;
- IIC_Send_Byte(IIC_Data); //寫數(shù)據(jù)
- if(IIC_Wait_Ack());
- return 3;
- I2C_Stop();
- return 0;
- }
- *******************************************************/
- /****************************************************************************
- *函數(shù)名稱:void OLED_SetCursor(unsigned char x,unsigned char y)
- *函數(shù)功能:設(shè)置行列的起始地址位置;此函數(shù)實(shí)測OK
- *輸入: unsigned char x,unsigned char y;;// x列,y行
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_SetCursor(unsigned char x,unsigned char y)// x列,y行
- {
- //x += 4;
- OLED_Write_Command(0xb0|y); //y就是第y頁,也就是第y行
- OLED_Write_Command(((x&0xf0)>>4)|0x10); //x的高4位
- OLED_Write_Command((x&0x0f)); //x的低4位
- // OLED_Write_Command((x&0x0f)|0x01);
- //列起始地址由指令0x1m和0x0n來確定,m是高四位,n是低四位,使用12864,則m,n合起來的8位數(shù)數(shù)值范圍在0-127之間
- }
- /****************************************************************************
- *函數(shù)名稱:void OLED_Clear(void)
- *函數(shù)功能:OLED清屏函數(shù),復(fù)位清屏;;此函數(shù)實(shí)測OK
- *輸入: 無
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_Clear(void)
- {
- unsigned char x,y;
- for(y=0;y<Y_HIGH/8;y++) //OLED_HIGH=8*8
- {
- OLED_Write_Command(0xb0+y); // 從0 ~ 7頁依次寫入
- OLED_Write_Command(0x00); // 低位列地址
- OLED_Write_Command(0x10); // 高位列地址
- for(x=0; x<X_WIDTH; x++) //OLED_WIDTH=128
- OLED_Write_Data(0x00);
- }
-
- }
- /****************************************************************************
- *函數(shù)名稱:void OLED_Fill(unsigned char bmp_dat)
- *函數(shù)功能:OLED全屏函數(shù), 此函數(shù)實(shí)測OK
- *輸入: unsigned char bmp_dat, 0XFF為全屏亮,0X00為全屏滅
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_Fill(unsigned char bmp_dat)
- {
- unsigned char x,y;
- for(y=0;y<Y_HIGH/8;y++) //OLED_HIGH=8*8
- {
- OLED_Write_Command(0xb0+y);
- OLED_Write_Command(0x00);
- OLED_Write_Command(0x10);
- for(x=0; x<X_WIDTH; x++)//OLED_WIDTH=128
- OLED_Write_Data(bmp_dat);
- }
-
- }
- /****************************************************************************
- *函數(shù)名稱:void OLED_ON(void)
- *函數(shù)功能:打開顯示
- *輸入: 無
- *輸出: 無
- *****************************************************************************/
- /***************/
- /*********
- void OLED_ON(void)
- {
- OLED_Write_Command(0x8D); //設(shè)置電荷泵
- OLED_Write_Command(0x14); //開啟電荷泵
- OLED_Write_Command(0xAF); //oled喚醒
- }
- *****************/
- /****************************************************************************
- *函數(shù)名稱:void OLED_OFF(void)
- *函數(shù)功能:打開顯示
- *輸入: 無
- *輸出: 無
- *****************************************************************************/
- /***************/
- /*****************
- void OLED_OFF(void)
- {
- OLED_Write_Command(0x8D);//設(shè)置電荷泵
- OLED_Write_Command(0x10); //開啟電荷泵
- OLED_Write_Command(0xAE); //oled休眠
- }
- ********************/
- /****************************************************************************
- *函數(shù)名稱:void OLED_Init(void)
- *函數(shù)功能:OLED12864初始化,此函數(shù)實(shí)測OK
- *輸入: 無
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_Init(void)
- {
- //IIC_Init(); //iic初始化SDA,SCL的IO口的函數(shù),可要可不要
- delay_ms(100); //從上電到下面開始初始化要有足夠的時(shí)間,即等待RC復(fù)位完畢
- /* Init LCD */
-
- //A3H,垂直滾動(dòng)區(qū)域,A是固定區(qū)域的頂行號,B是行數(shù)
- OLED_Write_Command(0xAE); //0xAE為SSD1306關(guān)閉顯示,
-
- OLED_Write_Command(0x20); //設(shè)置存儲(chǔ)地址的模式,水平、豎直、頁、[無效],四種,復(fù)位頁模式
- OLED_Write_Command(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid(無效)
-
- OLED_Write_Command(0xB0); //設(shè)置頁地址,0-7
- OLED_Write_Command(0x00); //設(shè)置起始列地址的低位,00H~0F,只在頁地址模式有效
- OLED_Write_Command(0x10); //設(shè)置起始列地址的高位,10H~1F,只在頁地址模式有效
- OLED_Write_Command(0x40); //設(shè)置顯示的起始行,(0x00~0x3F),40H~7FH總共64行
-
- OLED_Write_Command(0x81); //設(shè)置對比度控制,實(shí)際取值是A[] + 1
- OLED_Write_Command(Brightness); // 這里Brightness=0xcf,Set SEG Output Current Brightness, 256
-
- OLED_Write_Command(0xA1); //設(shè)置段(SEG)重映射,A0H/A1H,A1H是列翻轉(zhuǎn), 0xa0左右反置 0xa1正常
- OLED_Write_Command(0xC8); //設(shè)置COM輸出掃描方向C0H/C8H,C8H是行反轉(zhuǎn)。 0xc0上下反置 0xc8正常,// 重映射模式,COM[N-1]~COM0掃描
- OLED_Write_Command(0xA6); //設(shè)置反白顯示,A6h --- “1”點(diǎn)亮像素點(diǎn),//A7h --- “0”點(diǎn)亮像素點(diǎn),A6H/A7H,0xa7逆顯示,
-
- OLED_Write_Command(0xA4); //A4/A5設(shè)置全局顯示,A5H強(qiáng)制全局顯示
-
- OLED_Write_Command(0xA8); //設(shè)置驅(qū)動(dòng)路數(shù),起始也就是命令為0xA8,參數(shù)取值16~63,效果是垂直方向顯示的范圍
- OLED_Write_Command(0x3F); //// 64duty
- OLED_Write_Command(0xD3); //設(shè)置顯示偏移,圖像豎直向上偏移,復(fù)位是00H,(0x00~0x3F)
- OLED_Write_Command(0x00); // 無偏移
- OLED_Write_Command(0xD5); //設(shè)置震蕩器分頻,默認(rèn)值80H
- OLED_Write_Command(0xF0); //--set divide ratio
- OLED_Write_Command(0xD9); //設(shè)置預(yù)充電周期,同步亮度的,復(fù)位22H
- OLED_Write_Command(0x22); //默認(rèn)值22H,官方推薦值0xF1,/將預(yù)充電設(shè)置為15個(gè)時(shí)鐘加上其放電設(shè)置為1個(gè)時(shí)鐘
- OLED_Write_Command(0xDA); //設(shè)置COM引腳硬件配置,復(fù)位是12H,加上重映射總共八種玩法,
- OLED_Write_Command(0x12); //使用默認(rèn)值
- OLED_Write_Command(0xDB); //設(shè)置Vcomh取消選擇等級,可調(diào)節(jié)亮度(默認(rèn))
- OLED_Write_Command(0x20); //默認(rèn)值0x20,0x00:0.65*Vcc,0x10:0.71*Vcc,0x20:0.77*Vcc,0x30:0.83*Vcc
- OLED_Write_Command(0x8D); //電荷泵設(shè)置,復(fù)位是0B,啟用電荷泵需要配置成1B
- OLED_Write_Command(0x14); //開顯示 set(0x10) disable
- OLED_Write_Command(0xAF); //0xAF為SSD1306打開顯示
-
-
- //OLED_Fill(0x00); //初始屏幕填充數(shù)據(jù)0
- //OLED_SetCursor(0,0); //
- OLED_Clear();//初始必須清屏
-
- }
- /****************************************************************************
- *函數(shù)名稱:void OLED_P6x8Str(unsigned char x, y,unsigned char ch[]);此函數(shù)實(shí)測OK
- *函數(shù)功能:顯示6*8一組標(biāo)準(zhǔn)寬度x高度=6x8,ASCII字符串 顯示的坐標(biāo)(x,y),x為列范圍,y為頁范圍0~7*
- *輸入: unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_P6x8Str(unsigned char x, y,unsigned char ch[])
- {
- unsigned char c=0,i=0,j=0;
- while (ch[j]!='\0')
- {
- c =ch[j]-32; //減去前面字符串有32個(gè)字符,第33個(gè)字符為A
- if(x>126){x=0;y++;}
- OLED_SetCursor(x,y);
- for(i=0;i<6;i++) //寫6列數(shù)據(jù)
- OLED_Write_Data(OLED_F6x8[c][i]);//如果要顯示第1個(gè)6列,則為
- x+=6; //列數(shù)+6
- j++; //行數(shù)加1
- }
- }
- //每行顯示數(shù)據(jù):生成數(shù)組的大小,字符的長(頁)x字符的寬(如8*16字體,2頁*8列 = 16;如12*24字體,3頁*12列 = 36;如16*32字體,4頁*16列 = 64)
- /****************************************************************************
- *函數(shù)名稱:void OLED_Font8x16Str(unsigned char x, unsigned char y, unsigned char ch[])
- *函數(shù)功能:顯示8*16一組標(biāo)準(zhǔn)ASCII字符串, 顯示的坐標(biāo)(x,y),y為頁范圍0~7;;此函數(shù)實(shí)測OK
- *輸入: unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_P8x16Str(unsigned char x, unsigned char y, unsigned char ch[])
- {
- unsigned char c=0,i=0,j=0;
- while (ch[j] != '\0')
- {
- c = ch[j]-32;
- if (x>120)
- {
- x = 0;
- y++;
- }
- OLED_SetCursor(x,y);
- for(i=0;i<8;i++)
- OLED_Write_Data(OLED_F8x16[c*16+i]);
-
- OLED_SetCursor(x,y+1);
- for(i=0; i<8; i++)
- OLED_Write_Data(OLED_F8x16[c*16+i+8]);
-
- x+=8;
- j++;
- }
- }
- /*****************************************************************************************************
- *函數(shù)名稱:void OLED_ShowStr(unsigned char x,unsigned char y,unsigned char *chr,unsigned char TextSize)
- *函數(shù)功能:顯示字符串函數(shù),包括了OLED_P6x8Str(),OLED_P8x16Str()兩個(gè)函數(shù).
- *使用方法:只需更改后面的TextSize的值,字符大小(1:6*8 ; 2:8*16)
- *輸入: unsigned char x,unsigned char y,unsigned char *chr,unsigned char TextSize)
- * : x,y:起點(diǎn)坐標(biāo),x為0-127列,y為頁0-7,*chr:為要顯示的字符串
- * TextSize為字號可以填入1與2,當(dāng)填入1時(shí),函數(shù)調(diào)用的為codetab.h中的6*8點(diǎn)陣數(shù)組,當(dāng)填入2時(shí)調(diào)用的是8*16點(diǎn)陣數(shù)組。
- * 所謂6*8,8*16就是在oled上占格的大小,oled分辨率為64*128,所以在應(yīng)用時(shí)要計(jì)算好格數(shù),以免oled上顯示不全
- * 如果 TextSize為1則為6*8,為2,則為8*16
- *輸出: 無
- ********************************************************************************************************/
- /***************/
- void OLED_ShowStr(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize)
- {
- unsigned char c = 0,i = 0,j = 0;
- switch(TextSize)
- {
- case 1:
- {
- while(ch[j] != '\0')
- {
- c = ch[j] - 32;
- if(x > 126)
- {
- x = 0;
- y++;
- }
- OLED_SetCursor(x,y);
- for(i=0;i<6;i++)
- OLED_Write_Data(OLED_F6x8[c][i]);
- x += 6;
- j++;
- }
- }break;
- case 2:
- {
- while(ch[j] != '\0')
- {
- c = ch[j] - 32;
- if(x > 120)
- {
- x = 0;
- y++;
- }
- OLED_SetCursor(x,y);
- for(i=0;i<8;i++)
- OLED_Write_Data(OLED_F8x16[c*16+i]);
- OLED_SetCursor(x,y+1);
- for(i=0;i<8;i++)
- OLED_Write_Data(OLED_F8x16[c*16+i+8]);
- x += 8;
- j++;
- }
- }break;
- }
- }
- /*****************************************************************************************************
- *函數(shù)名稱:void OLED_ShowChinese(unsigned char x, unsigned char y, unsigned char Num)
- *函數(shù)功能:顯示 bsp_font.h 中的16*16點(diǎn)陣漢字(宋體), 此函數(shù)實(shí)測OK
- *輸入: unsigned char Line, unsigned char Column, unsigned char Num
- y:起始點(diǎn)行坐標(biāo):0 ~ 7,x:起始點(diǎn)列坐標(biāo):0 ~127,Num為第幾個(gè)字
- *輸出: 無
- ********************************************************************************************************/
- /***************/
- /****************************
- void OLED_P16x16Ch(unsigned char x, unsigned char y, unsigned int Num)
- {
-
- unsigned char i=0;
- unsigned int wide = 32*Num; //字寬
-
- OLED_SetCursor(x,y); //參數(shù)2:把光標(biāo)設(shè)置在第幾頁. 參數(shù)1:把光標(biāo)設(shè)置在第幾列
-
- for (i = 0; i < 16; i++)
- {
- OLED_Write_Data(OLED_F16x16[wide]); //顯示上半部分內(nèi)容
- wide+=1;
- }
-
- OLED_SetCursor(x,y+1); //參數(shù)2:把光標(biāo)設(shè)置在第幾頁. 參數(shù)1:把光標(biāo)設(shè)置在第幾列
- for (i = 0; i < 16 ; i++)
- {
- OLED_Write_Data(OLED_F16x16[wide]); //顯示下半部分內(nèi)容
- wide+=1;
- }
- }
- ******************************
- /*****************************************************************************************************
- *函數(shù)名稱:void OLED_P16x16Ch(unsigned char x, unsigned char y, unsigned char Num)
- *函數(shù)功能:顯示 bsp_font.h 中的漢字(宋體)
- *輸入: unsigned char Line, unsigned char Column, unsigned char Num
- y:起始點(diǎn)行坐標(biāo):1 ~ 8, x:起始點(diǎn)列坐標(biāo):1 ~8,Num為第幾個(gè)字
- *輸出: 無
- ********************************************************************************************************/
- /***************/
- void OLED_P16x16Ch(unsigned char x, unsigned char y, unsigned char Num)
- {
-
- unsigned char i=0;
- unsigned char wide = 16; //字寬,如:16x16字體,32x32字體,
-
- OLED_SetCursor((x-1)*wide,(y-1)); //參數(shù)1:把光標(biāo)設(shè)置在第幾列,參數(shù)2:把光標(biāo)設(shè)置在第幾頁.
-
- for (i = 0; i < wide; i++)
- {
- OLED_Write_Data(OLED_F16x16[Num][i]); //顯示上半部分內(nèi)容
-
- }
-
- OLED_SetCursor((x-1)*wide,(y-1)+1); //參數(shù)2:把光標(biāo)設(shè)置在第幾頁. 參數(shù)1:把光標(biāo)設(shè)置在第幾列
-
- for (i = 0; i < wide ; i++)
- {
- OLED_Write_Data(OLED_F16x16[Num][i+wide]); //顯示下半部分內(nèi)容
-
- }
- }
- /****************************************************************************
- *函數(shù)名稱:void OLED_ShowCHinese(unsigned char x,unsigned char y,unsigned char no,unsigned char font_width,unsigned char font_height)
- *函數(shù)功能: 顯示任意大小漢字
- ******** x1,y1 -- 起點(diǎn)對角線(結(jié)束點(diǎn))的坐標(biāo)(x1:0~127,y1:0~7)
- *輸入: unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組,
- * : *no: 表示要顯示的漢字(模組)在hzk[][]數(shù)組中的行號,通過行號來確定在數(shù)組中要顯示的漢字
- * 這里字體的寬font_width的值必須與用字模制作軟件生成字模時(shí)的點(diǎn)陣值大小一致
- * font_height的值為用字模制作軟件生成字模時(shí)字體的高,由于我的屏像素為32*128-----0~7共8頁,每頁4個(gè)位
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_ShowCHinese(unsigned char x,unsigned char y,unsigned char no,unsigned char font_width,unsigned char font_height)
- {
- unsigned char t, i;
- for(i=0;i<(font_height/8);i++) /*font_height最大值為32,這張屏只有8個(gè)頁(行),每頁4個(gè)位*/
- {
- OLED_SetCursor(x,y+i);
-
-
- for(t=0;t<font_width;t++) /*font_width最大值為128,屏幕只有這么大*/
- {
- //OLED_Write_Data(OLED_F32x32[(font_height/8)*no+i][t]);
- if((font_width==16)&(font_height==16)) //16x16字體
- {
- OLED_Write_Data(OLED_F16x16[no][font_width*i+t]);
- }
- else if((font_width==32)&(font_height==16)) //32x16字體
- {
- OLED_Write_Data(OLED_F32x16[no][font_width*i+t]);
- }
-
-
- else if((font_width==32)&(font_height==32)) //32x32字體
- {
- OLED_Write_Data(OLED_F32x32[no][font_width*i+t]);
- }
- else if((font_width==64)&(font_height==32)) //64x32字體
- {
- OLED_Write_Data(OLED_F64x32[no][font_width*i+t]);
- }
-
- else if((font_width==64)&(font_height==64)) //64x64字體
- {
- OLED_Write_Data(OLED_F64x64[no][font_width*i+t]);
- }
-
- }
- }
- }
- /****************************************************************************
- *函數(shù)名稱:void OLED_DrawBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[])
- *函數(shù)功能:顯示顯示BMP圖片128×64起始點(diǎn)坐標(biāo)(x0, y0),x的范圍0~127,y為頁的范圍0~7
- ******** x1,y1 -- 起點(diǎn)對角線(結(jié)束點(diǎn))的坐標(biāo)(x1:0~127,y1:0~7)
- *輸入: unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組
- *輸出: 無
- *****************************************************************************/
- /***************/
- void OLED_DrawBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[])
- {
- unsigned int j=0;
- unsigned char x, y;
- if(y1%8 == 0)
- y = y1/8;
- else
- y = y1/8+1;
- for (y=y0; y<y1; y++)
- {
- OLED_SetCursor(x0,y);
- for(x=x0; x<x1; x++)
- {
- OLED_Write_Data(BMP[j++]);
- }
- }
- }
- /*****************************************************************************************************
- *函數(shù)名稱:void OLED_ShowChinese(unsigned char Line, unsigned char Column, unsigned char Num)
- *函數(shù)功能:顯示 bsp_font.h 中的漢字(宋體)
- *輸入: unsigned char Line, unsigned char Column, unsigned char Num
- Line:起始點(diǎn)行坐標(biāo):0 ~ 7,Column:起始點(diǎn)列坐標(biāo):0 ~127
- *輸出: 無
- ********************************************************************************************************/
- /***************/
- /***************************************
- void OLED_ShowChinese(unsigned char Line, unsigned char Column, unsigned char Num)
- {
-
- unsigned char i=0;
- unsigned char wide = 32; //字寬
-
- OLED_SetCursor(( Line - 1 ) * 2, ( Column - 1 )* wide); //參數(shù)1:把光標(biāo)設(shè)置在第幾頁. 參數(shù)2:把光標(biāo)設(shè)置在第幾列
-
- for (i = 0; i < wide; i++)
- {
- OLED_Write_Data(OLED_F16x16[Num][i]); //顯示上半部分內(nèi)容
- }
-
- OLED_SetCursor(( Line - 1 ) * 2 + 1,( Column - 1) * wide);
- for (i = 0; i < wide ; i++)
- {
- OLED_Write_Data(OLED_F16x16[Num][i+wide]); //顯示下半部分內(nèi)容
- }
- }
- ****************************************/
- /**
- * 描述:顯示6*8一組標(biāo)準(zhǔn)ASCII字符串,顯示的坐標(biāo)(x,y),y為頁范圍0~7
- */
-
- /****************************************************************************
- *函數(shù)名稱:void OLED_Font6x8Str(unsigned char x, unsigned char y, unsigned char ch[])
- *函數(shù)功能:顯示6*8一組標(biāo)準(zhǔn)ASCII字符串, 顯示的坐標(biāo)(x,y),y為頁范圍0~7
- *輸入: unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組
- *輸出: 無
- *****************************************************************************/
- /***************/
- /****************************
- void OLED_Font6x8Str(unsigned char x, unsigned char y, unsigned char ch[])
- {
- unsigned char c=0, i=0, j=0;
- while (ch[j] != '\0')
- {
- c = ch[j]-32;
- if(x>126) {x=0; y++;}
- OLED_SetCursor(x,y);
- for(i=0; i<6; i++)
- OLED_Write_Data(F6x8[c][i]);
- x += 6;
- j++;
- }
- }
- **************************/
- #endif
-
復(fù)制代碼 原理圖: 無
仿真: 無
STC15F2K60S2單片機(jī)完整Keil代碼工程文件下載:
STC15F2K60S2 OLED12864任意位置顯示字符和漢字.zip
(93.21 KB, 下載次數(shù): 48)
2024-5-4 08:09 上傳
點(diǎn)擊文件名下載附件
|
評分
-
查看全部評分
|