久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1818|回復(fù): 3
收起左側(cè)

單片機(jī)軟件模擬IIC在OLED12864任意位置顯示字符及漢字oled12864.h下載

[復(fù)制鏈接]
ID:877406 發(fā)表于 2024-5-4 08:21 | 顯示全部樓層 |閱讀模式
制作出來的電路實(shí)物圖如下:
51hei圖片_20240504081312.jpg

STC15F2K60S2單片機(jī)源程序如下:
oled12864.h
  1. /*********************************************************************************************************************
  2. *1.oled12864模塊頭文件( SSD1306驅(qū)動(dòng)IC)
  3. *2.文件:oled12864.h
  4. *4.版本:  V1.0
  5. *************************************************說明事項(xiàng)*****************************************************************
  6. *  ssd1306本身支持多種總線驅(qū)動(dòng)方式包括SPI以及并口等,通過芯片的相應(yīng)IO口拉低拉高來選擇哪一種接口,0x78為IIC接口,0x7A為SOI接口
  7. *使用I2C接口時(shí),SSD1306允許有最多兩個(gè)7位的I2C地址,同樣通過相應(yīng)的IO口拉低拉高來切換,一般默認(rèn)是0x3c,在屏幕模塊的背面,
  8. *可以看到一個(gè)I2C地址切換提示,需要改變模塊I2C地址時(shí),只需要把提示位置的電阻取下焊接到另外一端即可。
  9. *要注意的是板上的I2C地址是加上了第零位讀寫位后的數(shù)值,即0x78 = 0x3c<<1 0x7A = 0x3d<<1,

  10. *SSD1306支持多種控制方式,I2C、6800、8080、4線SPI、3線SPI,通過SSD1306的3個(gè)引腳 BS0、BS1、BS2接不同的電平來選擇控制方式,
  11. *I2C控制:BS0=0、BS1=1、BS2=0;
  12. *6800控制:BS0=0、BS1=0、BS2=1;
  13. *8080控制:BS0=0、BS1=1、BS2=1;
  14. *4線SPI控制:BS0=0、BS1=0、BS2=0;
  15. *3線SPI控制:BS0=1、BS1=0、BS2=0;
  16. *從機(jī)地址是由七個(gè)位組成的,如上圖框起來的高七位,這里說明了SSD1306的從地址高六位是固定的,只有第七位受SA0控制,
  17. *如果這個(gè)位為邏輯0,地址則是0x78,如果為邏輯1則是0x7A。一般情況下看一下背面就可以了,廠家一般會(huì)默認(rèn)選擇搞成0x78

  18. ***********************************************************************************************************************/
  19. #ifndef _OLED12864_H_
  20. #define _OLED12864_H_

  21. #include "IIC.h"
  22. #include "Font.h"
  23. #define BIRGTHNESS        //OLED的亮度  00~255,0xcf;

  24. #define X_WIDTH    128    //屏幕寬度
  25. #define Y_HIGH    (8*8)   //屏幕高度

  26. #define IIC_OLED_ADDR_W  0x78   //OLED器件地址,7位地址,高位為0表示寫,為1表示讀,//通過調(diào)整0R電阻,屏可以0x78和0x7A兩個(gè)地址 -- 默認(rèn)0x78
  27. #define        Brightness        0xCF
  28. //void OLED_Write_Command(unsigned char IIC_Command);
  29. //void OLED_Write_Data(unsigned char IIC_Data);
  30. void OLED_Init(void);
  31. void OLED_Clear(void);
  32. void OLED_ON(void);
  33. void OLED_OFF(void);
  34. //void OLED_ShowStr(unsigned char x, unsigned char y, unsigned char ch[]);
  35. void OLED_ShowChinese(unsigned char x, unsigned char y, unsigned char Num);
  36. void OLED_ShowStr(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize);

  37. /****************************************************************************
  38. *函數(shù)名稱:void  OLED_Write_Command(unsigned char IIC_Command)
  39. *函數(shù)功能:寫OLED命令;  此函數(shù)實(shí)測OK
  40. *輸入:    unsigned char IIC_Command
  41. *輸出:    無
  42. *****************************************************************************/
  43. /***************/

  44. void OLED_Write_Command(unsigned char IIC_Command)
  45. {

  46.           IIC_Start();                     //啟動(dòng)I2C
  47.     IIC_Send_Byte(IIC_OLED_ADDR_W);  //D/C #=0; R/W #=0;寫IIC器件地址
  48.           IIC_Wait_Ack();
  49.                 IIC_Send_Byte(0x00);             //寄存器地址,告訴指令解析器,接下來的是一個(gè)指令
  50.                 IIC_Wait_Ack();
  51.                 IIC_Send_Byte(IIC_Command);      //寫命令
  52.                 IIC_Wait_Ack();
  53.                 IIC_Stop();
  54.                  
  55. }        



  56. /****************************************************************************
  57. *函數(shù)名稱:bit OLED12864_Write_Commmand(unsigned char cmd, bit start, bit stop)
  58. *函數(shù)功能:寫指令函數(shù),第一個(gè)參數(shù)為指令,第二、三個(gè)參數(shù)選擇是否需要通信開始和結(jié)束函數(shù),=1有,=0沒有
  59. *輸入:    unsigned char IIC_Command
  60. *輸出:    無
  61. *****************************************************************************/
  62. /***************/
  63. /*****************************************************
  64. bit OLED12864_Write_Commmand(unsigned char cmd, bit start, bit stop)

  65. {
  66.      if(start)

  67.      {
  68.            IIC_Start();             //啟動(dòng)I2C

  69.            IIC_Send_Byte(IIC_OLED_ADDR_W);//寫從機(jī)地址,并且加上讀寫標(biāo)志位(最后一位)

  70.            if(!Test_ack())

  71.            {

  72.                  return 0;

  73.            }    //執(zhí)行從機(jī)應(yīng)答檢測函數(shù),如果從機(jī)發(fā)送了非應(yīng)答信號,那么就退出數(shù)據(jù)發(fā)送函數(shù)

  74.       }
  75. }
  76. **********************************************************/
  77. /*********************************************************
  78. unsigned char OLED_Write_Command(unsigned char IIC_Command)
  79. {

  80.           I2C_Start();                     //啟動(dòng)I2C
  81.     IIC_Send_Byte(I2C_OLED_ADDR_W);  //D/C #=0; R/W #=0;寫IIC器件地址
  82.           if(IIC_Wait_Ack())
  83.        return 1;
  84.                 IIC_Send_Byte(0x00);  // 告訴指令解析器,接下來的是一個(gè)指令
  85.                 if(IIC_Wait_Ack())
  86.        return 2;
  87.                 IIC_Send_Byte(IIC_Command);  //寫命令
  88.                 if(IIC_Wait_Ack())
  89.        return 3;
  90.                 I2C_Stop();
  91.                    return 0;
  92. }        
  93. ***********************************************************/

  94. /****************************************************************************
  95. *函數(shù)名稱:unsigned char OLED_Write_Data(unsigned char IIC_Data)
  96. *函數(shù)功能:寫OLED數(shù)據(jù);  此函數(shù)實(shí)測OK
  97. *輸入:    unsigned char IIC_Data
  98. *輸出:    無
  99. *****************************************************************************/
  100. /***************/

  101. void OLED_Write_Data(unsigned char IIC_Data)
  102. {

  103.           IIC_Start();                     //啟動(dòng)I2C
  104.     IIC_Send_Byte(IIC_OLED_ADDR_W);  //D/C #=0; R/W #=0;寫IIC器件地址
  105.           IIC_Wait_Ack();
  106.                 IIC_Send_Byte(0x40);      //寄存器地址告訴指令解析器,接下來的是一個(gè)數(shù)據(jù)
  107.                 IIC_Wait_Ack();
  108.                 IIC_Send_Byte(IIC_Data);  //寫數(shù)據(jù)
  109.                 IIC_Wait_Ack();
  110.                 IIC_Stop();
  111.                         
  112. }        

  113. /*****************************************************
  114. static unsigned char OLED_Write_Data(unsigned char IIC_Data)
  115. {
  116.     I2C_Start();                     //啟動(dòng)I2C
  117.     IIC_Send_Byte(I2C_OLED_ADDR_W);  //D/C #=0; R/W #=0;寫IIC器件地址
  118.           if(IIC_Wait_Ack());
  119.        return 1;
  120.                 IIC_Send_Byte(0x40);      //告訴指令解析器,接下來的是一個(gè)指令
  121.                 if(IIC_Wait_Ack());
  122.        return 2;
  123.                 IIC_Send_Byte(IIC_Data);  //寫數(shù)據(jù)
  124.                 if(IIC_Wait_Ack());
  125.        return 3;
  126.                 I2C_Stop();
  127.                    return 0;
  128. }        
  129. *******************************************************/

  130. /****************************************************************************
  131. *函數(shù)名稱:void OLED_SetCursor(unsigned char x,unsigned char y)
  132. *函數(shù)功能:設(shè)置行列的起始地址位置;此函數(shù)實(shí)測OK
  133. *輸入:    unsigned char x,unsigned char y;;// x列,y行
  134. *輸出:    無
  135. *****************************************************************************/
  136. /***************/
  137. void OLED_SetCursor(unsigned char x,unsigned char y)// x列,y行
  138. {
  139.           //x += 4;
  140.           OLED_Write_Command(0xb0|y);             //y就是第y頁,也就是第y行
  141.           OLED_Write_Command(((x&0xf0)>>4)|0x10); //x的高4位
  142.           OLED_Write_Command((x&0x0f));           //x的低4位
  143.          // OLED_Write_Command((x&0x0f)|0x01);  
  144.          //列起始地址由指令0x1m和0x0n來確定,m是高四位,n是低四位,使用12864,則m,n合起來的8位數(shù)數(shù)值范圍在0-127之間
  145. }        

  146. /****************************************************************************
  147. *函數(shù)名稱:void OLED_Clear(void)
  148. *函數(shù)功能:OLED清屏函數(shù),復(fù)位清屏;;此函數(shù)實(shí)測OK
  149. *輸入:    無
  150. *輸出:    無
  151. *****************************************************************************/
  152. /***************/
  153. void OLED_Clear(void)
  154. {
  155.       unsigned char x,y;

  156.       for(y=0;y<Y_HIGH/8;y++)  //OLED_HIGH=8*8
  157.             {
  158.         OLED_Write_Command(0xb0+y); // 從0 ~ 7頁依次寫入
  159.         OLED_Write_Command(0x00);   // 低位列地址
  160.         OLED_Write_Command(0x10);   // 高位列地址
  161.         for(x=0; x<X_WIDTH; x++)    //OLED_WIDTH=128
  162.            OLED_Write_Data(0x00);
  163.      }
  164.                
  165. }


  166. /****************************************************************************
  167. *函數(shù)名稱:void OLED_Fill(unsigned char bmp_dat)
  168. *函數(shù)功能:OLED全屏函數(shù),         此函數(shù)實(shí)測OK
  169. *輸入:    unsigned char bmp_dat,  0XFF為全屏亮,0X00為全屏滅
  170. *輸出:    無
  171. *****************************************************************************/
  172. /***************/

  173. void OLED_Fill(unsigned char bmp_dat)
  174. {
  175.       unsigned char x,y;

  176.       for(y=0;y<Y_HIGH/8;y++)  //OLED_HIGH=8*8
  177.             {
  178.         OLED_Write_Command(0xb0+y);
  179.         OLED_Write_Command(0x00);
  180.         OLED_Write_Command(0x10);
  181.         for(x=0; x<X_WIDTH; x++)//OLED_WIDTH=128
  182.            OLED_Write_Data(bmp_dat);
  183.      }
  184.                
  185. }

  186. /****************************************************************************
  187. *函數(shù)名稱:void OLED_ON(void)
  188. *函數(shù)功能:打開顯示
  189. *輸入:    無
  190. *輸出:    無
  191. *****************************************************************************/
  192. /***************/
  193. /*********
  194. void OLED_ON(void)
  195. {
  196.     OLED_Write_Command(0x8D); //設(shè)置電荷泵
  197.     OLED_Write_Command(0x14); //開啟電荷泵
  198.     OLED_Write_Command(0xAF); //oled喚醒
  199. }
  200. *****************/
  201. /****************************************************************************
  202. *函數(shù)名稱:void OLED_OFF(void)
  203. *函數(shù)功能:打開顯示
  204. *輸入:    無
  205. *輸出:    無
  206. *****************************************************************************/
  207. /***************/

  208. /*****************
  209. void OLED_OFF(void)
  210. {
  211.     OLED_Write_Command(0x8D);//設(shè)置電荷泵
  212.     OLED_Write_Command(0x10); //開啟電荷泵
  213.     OLED_Write_Command(0xAE); //oled休眠
  214. }
  215. ********************/
  216. /****************************************************************************
  217. *函數(shù)名稱:void OLED_Init(void)
  218. *函數(shù)功能:OLED12864初始化,此函數(shù)實(shí)測OK
  219. *輸入:    無
  220. *輸出:    無
  221. *****************************************************************************/
  222. /***************/
  223. void OLED_Init(void)
  224. {
  225.     //IIC_Init();      //iic初始化SDA,SCL的IO口的函數(shù),可要可不要
  226.     delay_ms(100);  //從上電到下面開始初始化要有足夠的時(shí)間,即等待RC復(fù)位完畢  
  227.     /* Init LCD */
  228.         
  229.           //A3H,垂直滾動(dòng)區(qū)域,A是固定區(qū)域的頂行號,B是行數(shù)
  230.     OLED_Write_Command(0xAE); //0xAE為SSD1306關(guān)閉顯示,
  231.         
  232.     OLED_Write_Command(0x20); //設(shè)置存儲(chǔ)地址的模式,水平、豎直、頁、[無效],四種,復(fù)位頁模式
  233.     OLED_Write_Command(0x10); //00,Horizontal Addressing Mode;01,Vertical Addressing Mode;10,Page Addressing Mode (RESET);11,Invalid(無效)
  234.         
  235.     OLED_Write_Command(0xB0); //設(shè)置頁地址,0-7
  236.     OLED_Write_Command(0x00); //設(shè)置起始列地址的低位,00H~0F,只在頁地址模式有效
  237.     OLED_Write_Command(0x10); //設(shè)置起始列地址的高位,10H~1F,只在頁地址模式有效
  238.     OLED_Write_Command(0x40); //設(shè)置顯示的起始行,(0x00~0x3F),40H~7FH總共64行
  239.         
  240.     OLED_Write_Command(0x81); //設(shè)置對比度控制,實(shí)際取值是A[] + 1
  241.     OLED_Write_Command(Brightness); // 這里Brightness=0xcf,Set SEG Output Current Brightness,  256
  242.         
  243.     OLED_Write_Command(0xA1); //設(shè)置段(SEG)重映射,A0H/A1H,A1H是列翻轉(zhuǎn), 0xa0左右反置 0xa1正常
  244.           OLED_Write_Command(0xC8); //設(shè)置COM輸出掃描方向C0H/C8H,C8H是行反轉(zhuǎn)。 0xc0上下反置 0xc8正常,// 重映射模式,COM[N-1]~COM0掃描
  245.     OLED_Write_Command(0xA6); //設(shè)置反白顯示,A6h --- “1”點(diǎn)亮像素點(diǎn),//A7h --- “0”點(diǎn)亮像素點(diǎn),A6H/A7H,0xa7逆顯示,
  246.                
  247.                 OLED_Write_Command(0xA4); //A4/A5設(shè)置全局顯示,A5H強(qiáng)制全局顯示
  248.                
  249.     OLED_Write_Command(0xA8); //設(shè)置驅(qū)動(dòng)路數(shù),起始也就是命令為0xA8,參數(shù)取值16~63,效果是垂直方向顯示的范圍
  250.     OLED_Write_Command(0x3F); //// 64duty
  251.     OLED_Write_Command(0xD3); //設(shè)置顯示偏移,圖像豎直向上偏移,復(fù)位是00H,(0x00~0x3F)
  252.     OLED_Write_Command(0x00); // 無偏移
  253.                 OLED_Write_Command(0xD5); //設(shè)置震蕩器分頻,默認(rèn)值80H
  254.     OLED_Write_Command(0xF0); //--set divide ratio
  255.                 OLED_Write_Command(0xD9); //設(shè)置預(yù)充電周期,同步亮度的,復(fù)位22H
  256.     OLED_Write_Command(0x22); //默認(rèn)值22H,官方推薦值0xF1,/將預(yù)充電設(shè)置為15個(gè)時(shí)鐘加上其放電設(shè)置為1個(gè)時(shí)鐘
  257.     OLED_Write_Command(0xDA); //設(shè)置COM引腳硬件配置,復(fù)位是12H,加上重映射總共八種玩法,
  258.     OLED_Write_Command(0x12); //使用默認(rèn)值
  259.                 OLED_Write_Command(0xDB); //設(shè)置Vcomh取消選擇等級,可調(diào)節(jié)亮度(默認(rèn))
  260.     OLED_Write_Command(0x20); //默認(rèn)值0x20,0x00:0.65*Vcc,0x10:0.71*Vcc,0x20:0.77*Vcc,0x30:0.83*Vcc
  261.                 OLED_Write_Command(0x8D); //電荷泵設(shè)置,復(fù)位是0B,啟用電荷泵需要配置成1B
  262.     OLED_Write_Command(0x14); //開顯示 set(0x10) disable
  263.     OLED_Write_Command(0xAF); //0xAF為SSD1306打開顯示        
  264.                
  265.    
  266.                 //OLED_Fill(0x00);          //初始屏幕填充數(shù)據(jù)0
  267.                 //OLED_SetCursor(0,0);     //
  268.     OLED_Clear();//初始必須清屏
  269.                  
  270. }

  271. /****************************************************************************
  272. *函數(shù)名稱:void OLED_P6x8Str(unsigned char x, y,unsigned char ch[]);此函數(shù)實(shí)測OK
  273. *函數(shù)功能:顯示6*8一組標(biāo)準(zhǔn)寬度x高度=6x8,ASCII字符串        顯示的坐標(biāo)(x,y),x為列范圍,y為頁范圍0~7*
  274. *輸入:    unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組
  275. *輸出:    無
  276. *****************************************************************************/
  277. /***************/
  278. void OLED_P6x8Str(unsigned char x, y,unsigned char ch[])
  279. {
  280.         unsigned char c=0,i=0,j=0;
  281.         while (ch[j]!='\0')
  282.         {
  283.                 c =ch[j]-32;         //減去前面字符串有32個(gè)字符,第33個(gè)字符為A
  284.                 if(x>126){x=0;y++;}
  285.                   OLED_SetCursor(x,y);
  286.                 for(i=0;i<6;i++)       //寫6列數(shù)據(jù)
  287.                   OLED_Write_Data(OLED_F6x8[c][i]);//如果要顯示第1個(gè)6列,則為
  288.                 x+=6;   //列數(shù)+6
  289.                 j++;    //行數(shù)加1
  290.          }
  291. }

  292. //每行顯示數(shù)據(jù):生成數(shù)組的大小,字符的長(頁)x字符的寬(如8*16字體,2頁*8列 = 16;如12*24字體,3頁*12列 = 36;如16*32字體,4頁*16列 = 64)
  293. /****************************************************************************
  294. *函數(shù)名稱:void OLED_Font8x16Str(unsigned char x, unsigned char y, unsigned char ch[])
  295. *函數(shù)功能:顯示8*16一組標(biāo)準(zhǔn)ASCII字符串, 顯示的坐標(biāo)(x,y),y為頁范圍0~7;;此函數(shù)實(shí)測OK
  296. *輸入:    unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組
  297. *輸出:    無
  298. *****************************************************************************/
  299. /***************/
  300. void OLED_P8x16Str(unsigned char x, unsigned char y, unsigned char ch[])
  301. {
  302.     unsigned char c=0,i=0,j=0;

  303.     while (ch[j] != '\0')
  304.                 {   
  305.         c = ch[j]-32;
  306.         if (x>120)
  307.                                 {
  308.               x = 0;
  309.               y++;
  310.         }
  311.         OLED_SetCursor(x,y);   
  312.         for(i=0;i<8;i++)     
  313.             OLED_Write_Data(OLED_F8x16[c*16+i]);
  314.                                 
  315.          OLED_SetCursor(x,y+1);   
  316.         for(i=0; i<8; i++)     
  317.             OLED_Write_Data(OLED_F8x16[c*16+i+8]);  
  318.         
  319.                                 x+=8;
  320.         j++;
  321.     }
  322. }


  323. /*****************************************************************************************************
  324. *函數(shù)名稱:void OLED_ShowStr(unsigned char x,unsigned char y,unsigned char *chr,unsigned char TextSize)
  325. *函數(shù)功能:顯示字符串函數(shù),包括了OLED_P6x8Str(),OLED_P8x16Str()兩個(gè)函數(shù).

  326. *使用方法:只需更改后面的TextSize的值,字符大小(1:6*8 ; 2:8*16)

  327. *輸入:    unsigned char x,unsigned char y,unsigned char *chr,unsigned char TextSize)
  328. *    :     x,y:起點(diǎn)坐標(biāo),x為0-127列,y為頁0-7,*chr:為要顯示的字符串
  329. *          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ù)組。
  330. *          所謂6*8,8*16就是在oled上占格的大小,oled分辨率為64*128,所以在應(yīng)用時(shí)要計(jì)算好格數(shù),以免oled上顯示不全

  331. *          如果 TextSize為1則為6*8,為2,則為8*16
  332. *輸出:    無
  333. ********************************************************************************************************/
  334. /***************/        

  335. void OLED_ShowStr(unsigned char x, unsigned char y, unsigned char ch[], unsigned char TextSize)
  336. {
  337.     unsigned char c = 0,i = 0,j = 0;
  338.     switch(TextSize)
  339.     {
  340.         case 1:
  341.         {
  342.             while(ch[j] != '\0')
  343.             {
  344.                 c = ch[j] - 32;
  345.                 if(x > 126)
  346.                 {
  347.                     x = 0;
  348.                     y++;
  349.                 }
  350.                 OLED_SetCursor(x,y);
  351.                 for(i=0;i<6;i++)
  352.                     OLED_Write_Data(OLED_F6x8[c][i]);
  353.                 x += 6;
  354.                 j++;
  355.             }
  356.         }break;
  357.         case 2:
  358.         {
  359.             while(ch[j] != '\0')
  360.             {
  361.                 c = ch[j] - 32;
  362.                 if(x > 120)
  363.                 {
  364.                     x = 0;
  365.                     y++;
  366.                 }
  367.                 OLED_SetCursor(x,y);
  368.                 for(i=0;i<8;i++)
  369.                     OLED_Write_Data(OLED_F8x16[c*16+i]);
  370.                 OLED_SetCursor(x,y+1);
  371.                 for(i=0;i<8;i++)
  372.                     OLED_Write_Data(OLED_F8x16[c*16+i+8]);
  373.                 x += 8;
  374.                 j++;
  375.             }
  376.         }break;
  377.     }
  378. }


  379. /*****************************************************************************************************
  380. *函數(shù)名稱:void OLED_ShowChinese(unsigned char x, unsigned char y, unsigned char Num)
  381. *函數(shù)功能:顯示 bsp_font.h 中的16*16點(diǎn)陣漢字(宋體), 此函數(shù)實(shí)測OK
  382. *輸入:   unsigned char Line, unsigned char Column, unsigned char Num
  383.           y:起始點(diǎn)行坐標(biāo):0 ~ 7,x:起始點(diǎn)列坐標(biāo):0 ~127,Num為第幾個(gè)字
  384. *輸出:    無
  385. ********************************************************************************************************/
  386. /***************/
  387. /****************************
  388. void  OLED_P16x16Ch(unsigned char x, unsigned char y, unsigned int Num)
  389. {
  390.         
  391.         unsigned char i=0;
  392.         unsigned int wide = 32*Num;      //字寬
  393.         
  394.         OLED_SetCursor(x,y);                //參數(shù)2:把光標(biāo)設(shè)置在第幾頁. 參數(shù)1:把光標(biāo)設(shè)置在第幾列
  395.         
  396.         for (i = 0; i < 16; i++)
  397.         {
  398.                 OLED_Write_Data(OLED_F16x16[wide]);                        //顯示上半部分內(nèi)容
  399.                 wide+=1;
  400.         }
  401.         
  402.                 OLED_SetCursor(x,y+1);                //參數(shù)2:把光標(biāo)設(shè)置在第幾頁. 參數(shù)1:把光標(biāo)設(shè)置在第幾列        
  403.         for (i = 0; i < 16 ; i++)
  404.         {
  405.                 OLED_Write_Data(OLED_F16x16[wide]);                //顯示下半部分內(nèi)容
  406.                 wide+=1;
  407.         }

  408. }
  409. ******************************

  410. /*****************************************************************************************************
  411. *函數(shù)名稱:void  OLED_P16x16Ch(unsigned char x, unsigned char y, unsigned char Num)
  412. *函數(shù)功能:顯示 bsp_font.h 中的漢字(宋體)
  413. *輸入:   unsigned char Line, unsigned char Column, unsigned char Num
  414.           y:起始點(diǎn)行坐標(biāo):1 ~ 8, x:起始點(diǎn)列坐標(biāo):1 ~8,Num為第幾個(gè)字
  415. *輸出:    無
  416. ********************************************************************************************************/
  417. /***************/

  418. void  OLED_P16x16Ch(unsigned char x, unsigned char y, unsigned char Num)
  419. {
  420.         
  421.         unsigned char i=0;
  422.         unsigned char wide = 16; //字寬,如:16x16字體,32x32字體,
  423.         
  424.         OLED_SetCursor((x-1)*wide,(y-1));                   //參數(shù)1:把光標(biāo)設(shè)置在第幾列,參數(shù)2:把光標(biāo)設(shè)置在第幾頁.
  425.         
  426.         for (i = 0; i < wide; i++)
  427.         {
  428.                   OLED_Write_Data(OLED_F16x16[Num][i]);    //顯示上半部分內(nèi)容
  429.                   
  430.         }
  431.         
  432.         OLED_SetCursor((x-1)*wide,(y-1)+1);                                 //參數(shù)2:把光標(biāo)設(shè)置在第幾頁. 參數(shù)1:把光標(biāo)設(shè)置在第幾列        
  433.         
  434.         for (i = 0; i < wide ; i++)
  435.         {
  436.                   OLED_Write_Data(OLED_F16x16[Num][i+wide]); //顯示下半部分內(nèi)容
  437.                  
  438.         }

  439. }

  440. /****************************************************************************
  441. *函數(shù)名稱:void OLED_ShowCHinese(unsigned char x,unsigned char y,unsigned char no,unsigned char font_width,unsigned char font_height)
  442. *函數(shù)功能: 顯示任意大小漢字
  443. ********   x1,y1 -- 起點(diǎn)對角線(結(jié)束點(diǎn))的坐標(biāo)(x1:0~127,y1:0~7)
  444. *輸入:    unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組,
  445. *      :   *no: 表示要顯示的漢字(模組)在hzk[][]數(shù)組中的行號,通過行號來確定在數(shù)組中要顯示的漢字
  446. *          這里字體的寬font_width的值必須與用字模制作軟件生成字模時(shí)的點(diǎn)陣值大小一致
  447. *         font_height的值為用字模制作軟件生成字模時(shí)字體的高,由于我的屏像素為32*128-----0~7共8頁,每頁4個(gè)位
  448. *輸出:    無
  449. *****************************************************************************/
  450. /***************/

  451. void OLED_ShowCHinese(unsigned char x,unsigned char y,unsigned char no,unsigned char font_width,unsigned char font_height)

  452. {                                 
  453.            unsigned char t, i;
  454.      for(i=0;i<(font_height/8);i++)                                /*font_height最大值為32,這張屏只有8個(gè)頁(行),每頁4個(gè)位*/
  455.            {
  456.                              OLED_SetCursor(x,y+i);        
  457.                         
  458.                              
  459.                              for(t=0;t<font_width;t++)                /*font_width最大值為128,屏幕只有這么大*/
  460.                              {        
  461.                                             //OLED_Write_Data(OLED_F32x32[(font_height/8)*no+i][t]);
  462.                                                          if((font_width==16)&(font_height==16))       //16x16字體
  463.                                                          {
  464.                                                             OLED_Write_Data(OLED_F16x16[no][font_width*i+t]);
  465.                                                          }
  466.                                                           else if((font_width==32)&(font_height==16))   //32x16字體
  467.                                                          {
  468.                                                             OLED_Write_Data(OLED_F32x16[no][font_width*i+t]);
  469.                                                          }
  470.                                                          
  471.                                                          
  472.                                                          else if((font_width==32)&(font_height==32))   //32x32字體
  473.                                                          {
  474.                                                             OLED_Write_Data(OLED_F32x32[no][font_width*i+t]);
  475.                                                          }
  476.                                                           else if((font_width==64)&(font_height==32))  //64x32字體
  477.                                                          {
  478.                                                             OLED_Write_Data(OLED_F64x32[no][font_width*i+t]);
  479.                                                          }
  480.                                                          
  481.                                                           else if((font_width==64)&(font_height==64))  //64x64字體
  482.                                                          {
  483.                                                             OLED_Write_Data(OLED_F64x64[no][font_width*i+t]);
  484.                                                          }
  485.                                                          
  486.                              }     
  487.            }               

  488. }

  489. /****************************************************************************
  490. *函數(shù)名稱:void OLED_DrawBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[])
  491. *函數(shù)功能:顯示顯示BMP圖片128×64起始點(diǎn)坐標(biāo)(x0, y0),x的范圍0~127,y為頁的范圍0~7
  492. ********   x1,y1 -- 起點(diǎn)對角線(結(jié)束點(diǎn))的坐標(biāo)(x1:0~127,y1:0~7)
  493. *輸入:    unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組
  494. *輸出:    無
  495. *****************************************************************************/
  496. /***************/


  497. void OLED_DrawBMP(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char BMP[])
  498. {   
  499.     unsigned int j=0;
  500.     unsigned char x, y;

  501.     if(y1%8 == 0)
  502.                         y = y1/8;      
  503.     else
  504.                         y = y1/8+1;
  505.     for (y=y0; y<y1; y++)
  506.     {
  507.          OLED_SetCursor(x0,y);               
  508.          for(x=x0; x<x1; x++)
  509.                            {      
  510.              OLED_Write_Data(BMP[j++]);            
  511.          }
  512.                 }
  513. }        

  514. /*****************************************************************************************************
  515. *函數(shù)名稱:void OLED_ShowChinese(unsigned char Line, unsigned char Column, unsigned char Num)
  516. *函數(shù)功能:顯示 bsp_font.h 中的漢字(宋體)
  517. *輸入:   unsigned char Line, unsigned char Column, unsigned char Num
  518.           Line:起始點(diǎn)行坐標(biāo):0 ~ 7,Column:起始點(diǎn)列坐標(biāo):0 ~127
  519. *輸出:    無
  520. ********************************************************************************************************/
  521. /***************/
  522. /***************************************
  523. void OLED_ShowChinese(unsigned char Line, unsigned char Column, unsigned char Num)
  524. {
  525.         
  526.         unsigned char i=0;
  527.         unsigned char wide = 32;      //字寬
  528.         
  529.         OLED_SetCursor(( Line - 1 ) * 2, ( Column - 1 )* wide);                //參數(shù)1:把光標(biāo)設(shè)置在第幾頁. 參數(shù)2:把光標(biāo)設(shè)置在第幾列
  530.         
  531.         for (i = 0; i < wide; i++)
  532.         {
  533.                 OLED_Write_Data(OLED_F16x16[Num][i]);                        //顯示上半部分內(nèi)容
  534.         }
  535.         
  536.         OLED_SetCursor(( Line - 1 ) * 2 + 1,( Column - 1) * wide);               
  537.         for (i = 0; i < wide ; i++)
  538.         {
  539.                 OLED_Write_Data(OLED_F16x16[Num][i+wide]);                //顯示下半部分內(nèi)容
  540.         }

  541. }
  542. ****************************************/


  543. /**
  544. * 描述:顯示6*8一組標(biāo)準(zhǔn)ASCII字符串,顯示的坐標(biāo)(x,y),y為頁范圍0~7
  545. */

  546. /****************************************************************************
  547. *函數(shù)名稱:void OLED_Font6x8Str(unsigned char x, unsigned char y, unsigned char ch[])
  548. *函數(shù)功能:顯示6*8一組標(biāo)準(zhǔn)ASCII字符串, 顯示的坐標(biāo)(x,y),y為頁范圍0~7
  549. *輸入:    unsigned char x, x為列,unsigned char y,y為行, unsigned char ch[]為字體數(shù)組
  550. *輸出:    無
  551. *****************************************************************************/
  552. /***************/
  553. /****************************
  554. void OLED_Font6x8Str(unsigned char x, unsigned char y, unsigned char ch[])
  555. {
  556.     unsigned char c=0, i=0, j=0;  

  557.     while (ch[j] != '\0')
  558.          {   
  559.         c = ch[j]-32;
  560.         if(x>126) {x=0; y++;}
  561.         OLED_SetCursor(x,y);   
  562.         for(i=0; i<6; i++)     
  563.           OLED_Write_Data(F6x8[c][i]);  
  564.         x += 6;
  565.         j++;
  566.     }
  567. }
  568. **************************/

  569. #endif

復(fù)制代碼
原理圖: 無
仿真: 無
STC15F2K60S2單片機(jī)完整Keil代碼工程文件下載:
STC15F2K60S2 OLED12864任意位置顯示字符和漢字.zip (93.21 KB, 下載次數(shù): 48)

評分

參與人數(shù) 1黑幣 +70 收起 理由
admin + 70 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評分

回復(fù)

使用道具 舉報(bào)

ID:259035 發(fā)表于 2024-8-23 09:48 | 顯示全部樓層
謝謝樓主分享,我還在學(xué)習(xí)中
回復(fù)

使用道具 舉報(bào)

ID:430492 發(fā)表于 2024-8-27 14:57 | 顯示全部樓層
謝謝樓主分享
回復(fù)

使用道具 舉報(bào)

ID:433219 發(fā)表于 2024-8-30 16:51 | 顯示全部樓層
注釋很詳細(xì)很重要!          ssd1306本身支持多種總線驅(qū)動(dòng)方式
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 一级国产精品一级国产精品片 | 新91视频网 | av网站在线看 | 91免费在线视频 | 久久久亚洲| jizz亚洲人 | 日韩在线不卡视频 | 成人在线一区二区 | 免费在线观看h片 | 亚洲欧美视频一区二区 | 日韩在线一区二区三区 | 中文字幕在线一 | 午夜精品一区二区三区在线视频 | 久久久无码精品亚洲日韩按摩 | 欧美一级片免费看 | 亚洲日日夜夜 | 国产精品免费一区二区三区 | 欧美精品在欧美一区二区 | 久久久久久久电影 | 亚洲第一色站 | 亚洲精品久 | 久久久国产精品 | www.9191| 国产精品18久久久久久久 | av黄色国产 | 欧美a在线观看 | 亚洲www| 久久久久九九九女人毛片 | 麻豆成人在线视频 | 日韩欧美国产一区二区三区 | 久久乐国产精品 | 成年人视频免费在线观看 | 日韩欧美精品一区 | 欧美久久一区 | 成年人精品视频 | 中国一级特黄真人毛片 | 久久久精品一区 | 91亚洲精选 | 精品网站999 | 欧美精品一区二区在线观看 | 欧美日韩高清一区 |