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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 7744|回復(fù): 5
打印 上一主題 下一主題
收起左側(cè)

51單片機(jī)驅(qū)動(dòng)0.96OLED_C51_SPI源代碼

  [復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:145511 發(fā)表于 2018-10-26 22:53 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
收藏了個(gè)好用的,OLED 0.91的代碼,給需要的人

單片機(jī)源程序如下:
  1. //////////////////////////////////////////////////////////////////////////////////         
  2. //本程序只供學(xué)習(xí)使用,未經(jīng)作者許可,不得用于其它任何用途
  3. //中景園電子
  4. //
  5. //  文 件 名   : main.c
  6. //  版 本 號(hào)   : v2.0
  7. //  作    者   : HuangKai
  8. //  生成日期   : 2014-0101
  9. //  最近修改   :
  10. //  功能描述   : OLED 4接口演示例程(51系列)
  11. //              說(shuō)明:
  12. //              ----------------------------------------------------------------
  13. //              GND    電源地
  14. //              VCC  接5V或3.3v電源
  15. //              D0   P1^0(SCL)
  16. //              D1   P1^1(SDA)
  17. //              RES  接P12
  18. //              DC   接P13
  19. //              CS   接P14               
  20. //              ----------------------------------------------------------------
  21. // 修改歷史   :
  22. // 日    期   :
  23. // 作    者   : HuangKai
  24. // 修改內(nèi)容   : 創(chuàng)建文件
  25. //版權(quán)所有,盜版必究。
  26. //Copyright(C) 中景園電子2014/3/16
  27. //All rights reserved
  28. //******************************************************************************/。
  29. #include "oled.h"
  30. //#include "stdlib.h"
  31. #include "oledfont.h"           
  32. //#include "delay.h"
  33. //OLED的顯存
  34. //存放格式如下.
  35. //[0]0 1 2 3 ... 127       
  36. //[1]0 1 2 3 ... 127       
  37. //[2]0 1 2 3 ... 127       
  38. //[3]0 1 2 3 ... 127       
  39. //[4]0 1 2 3 ... 127       
  40. //[5]0 1 2 3 ... 127       
  41. //[6]0 1 2 3 ... 127       
  42. //[7]0 1 2 3 ... 127                           
  43. void delay_ms(unsigned int ms)
  44. {                        
  45.         unsigned int a;
  46.         while(ms)
  47.         {
  48.                 a=1800;
  49.                 while(a--);
  50.                 ms--;
  51.         }
  52.         return;
  53. }
  54. #if OLED_MODE==1
  55. //向SSD1106寫(xiě)入一個(gè)字節(jié)。
  56. //dat:要寫(xiě)入的數(shù)據(jù)/命令
  57. //cmd:數(shù)據(jù)/命令標(biāo)志 0,表示命令;1,表示數(shù)據(jù);
  58. void OLED_WR_Byte(u8 dat,u8 cmd)
  59. {
  60.         DATAOUT(dat);            
  61.         if(cmd)
  62.           OLED_DC_Set();
  63.         else
  64.           OLED_DC_Clr();                  
  65.         OLED_CS_Clr();
  66.         OLED_WR_Clr();         
  67.         OLED_WR_Set();
  68.         OLED_CS_Set();          
  69.         OLED_DC_Set();         
  70. }                         
  71. #else
  72. //向SSD1306寫(xiě)入一個(gè)字節(jié)。
  73. //dat:要寫(xiě)入的數(shù)據(jù)/命令
  74. //cmd:數(shù)據(jù)/命令標(biāo)志 0,表示命令;1,表示數(shù)據(jù);
  75. void OLED_WR_Byte(u8 dat,u8 cmd)
  76. {       
  77.         u8 i;                          
  78.         if(cmd)
  79.           OLED_DC_Set();
  80.         else
  81.           OLED_DC_Clr();                  
  82.         OLED_CS_Clr();
  83.         for(i=0;i<8;i++)
  84.         {                          
  85.                 OLED_SCLK_Clr();
  86.                 if(dat&0x80)
  87.                         {
  88.                    OLED_SDIN_Set();
  89.                         }
  90. else
  91.                    OLED_SDIN_Clr();
  92.                                 OLED_SCLK_Set();
  93.                 dat<<=1;   
  94.         }                                                   
  95.         OLED_CS_Set();
  96.         OLED_DC_Set();             
  97. }
  98. #endif
  99.         void OLED_Set_Pos(unsigned char x, unsigned char y)
  100. {
  101.         OLED_WR_Byte(0xb0+y,OLED_CMD);
  102.         OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  103.         OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD);
  104. }             
  105. //開(kāi)啟OLED顯示   
  106. void OLED_Display_On(void)
  107. {
  108.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  109.         OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
  110.         OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
  111. }
  112. //關(guān)閉OLED顯示     
  113. void OLED_Display_Off(void)
  114. {
  115.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  116.         OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
  117.         OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
  118. }                                            
  119. //清屏函數(shù),清完屏,整個(gè)屏幕是黑色的!和沒(méi)點(diǎn)亮一樣!!!          
  120. void OLED_Clear(void)  
  121. {  
  122.         u8 i,n;                    
  123.         for(i=0;i<8;i++)  
  124.         {  
  125.                 OLED_WR_Byte (0xb0+i,OLED_CMD);    //設(shè)置頁(yè)地址(0~7)
  126.                 OLED_WR_Byte (0x00,OLED_CMD);      //設(shè)置顯示位置—列低地址
  127.                 OLED_WR_Byte (0x10,OLED_CMD);      //設(shè)置顯示位置—列高地址   
  128.                 for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA);
  129.         } //更新顯示
  130. }


  131. //在指定位置顯示一個(gè)字符,包括部分字符
  132. //x:0~127
  133. //y:0~63
  134. //mode:0,反白顯示;1,正常顯示                                 
  135. //size:選擇字體 16/12
  136. void OLED_ShowChar(u8 x,u8 y,u8 chr)
  137. {             
  138.         unsigned char c=0,i=0;       
  139.                 c=chr-' ';//得到偏移后的值                       
  140.                 if(x>Max_Column-1){x=0;y=y+2;}
  141.                 if(SIZE ==16)
  142.                         {
  143.                         OLED_Set_Pos(x,y);       
  144.                         for(i=0;i<8;i++)
  145.                         OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
  146.                         OLED_Set_Pos(x,y+1);
  147.                         for(i=0;i<8;i++)
  148.                         OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
  149.                         }
  150.                         else {       
  151.                                 OLED_Set_Pos(x,y+1);
  152.                                 for(i=0;i<6;i++)
  153.                                 OLED_WR_Byte(F6x8[c][i],OLED_DATA);
  154.                                
  155.                         }
  156. }
  157. //m^n函數(shù)
  158. u32 oled_pow(u8 m,u8 n)
  159. {
  160.         u32 result=1;         
  161.         while(n--)result*=m;   
  162.         return result;
  163. }                                  
  164. //顯示2個(gè)數(shù)字
  165. //x,y :起點(diǎn)坐標(biāo)         
  166. //len :數(shù)字的位數(shù)
  167. //size:字體大小
  168. //mode:模式        0,填充模式;1,疊加模式
  169. //num:數(shù)值(0~4294967295);                           
  170. void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2)
  171. {                
  172.         u8 t,temp;
  173.         u8 enshow=0;                                                  
  174.         for(t=0;t<len;t++)
  175.         {
  176.                 temp=(num/oled_pow(10,len-t-1))%10;
  177.                 if(enshow==0&&t<(len-1))
  178.                 {
  179.                         if(temp==0)
  180.                         {
  181.                                 OLED_ShowChar(x+(size2/2)*t,y,' ');
  182.                                 continue;
  183.                         }else enshow=1;
  184.                           
  185.                 }
  186.                  OLED_ShowChar(x+(size2/2)*t,y,temp+'0');
  187.         }
  188. }
  189. //顯示一個(gè)字符號(hào)串
  190. void OLED_ShowString(u8 x,u8 y,u8 *chr)
  191. {
  192.         unsigned char j=0;
  193.         while (chr[j]!='\0')
  194.         {                OLED_ShowChar(x,y,chr[j]);
  195.                         x+=8;
  196.                 if(x>120){x=0;y+=2;}
  197.                         j++;
  198.         }
  199. }
  200. //顯示漢字
  201. void OLED_ShowCHinese(u8 x,u8 y,u8 no)
  202. {                                  
  203.         u8 t,adder=0;
  204.         OLED_Set_Pos(x,y);       
  205.     for(t=0;t<16;t++)
  206.                 {
  207.                                 OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
  208.                                 adder+=1;
  209.      }       
  210.                 OLED_Set_Pos(x,y+1);       
  211.     for(t=0;t<16;t++)
  212.                         {       
  213.                                 OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
  214.                                 adder+=1;
  215.       }                                       
  216. }
  217. /***********功能描述:顯示顯示BMP圖片128×64起始點(diǎn)坐標(biāo)(x,y),x的范圍0~127,y為頁(yè)的范圍0~7*****************/
  218. void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
  219. {        
  220. unsigned int j=0;
  221. unsigned char x,y;
  222.   
  223.   if(y1%8==0) y=y1/8;      
  224.   else y=y1/8+1;
  225.         for(y=y0;y<y1;y++)
  226.         {
  227.                 OLED_Set_Pos(x0,y);
  228.     for(x=x0;x<x1;x++)
  229.             {      
  230.                     OLED_WR_Byte(BMP[j++],OLED_DATA);                   
  231.             }
  232.         }
  233. }


  234. //初始化SSD1306                                            
  235. void OLED_Init(void)
  236. {



  237.   OLED_RST_Set();
  238.         delay_ms(100);
  239.         OLED_RST_Clr();
  240.         delay_ms(100);
  241.         OLED_RST_Set();
  242.         /*                                  
  243.         OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
  244.         OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  245.         OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  246.         OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  247.         OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
  248.         OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
  249.         OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
  250.         OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
  251.         OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
  252.         OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  253.         OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
  254.         OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset        Shift Mapping RAM Counter (0x00~0x3F)
  255.         OLED_WR_Byte(0x00,OLED_CMD);//-not offset
  256.         OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
  257.         OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
  258.         OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
  259.         OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  260.         OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
  261.         OLED_WR_Byte(0x12,OLED_CMD);
  262.         OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
  263.         OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
  264.         OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
  265.         OLED_WR_Byte(0x02,OLED_CMD);//
  266.         OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
  267.         OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
  268.         OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
  269.         OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
  270.         OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
  271.         */

  272.         OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
  273.         OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  274.         OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  275.         OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  276.         OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
  277.         OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
  278.         OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
  279.         OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
  280.         OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
  281.         OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  282.         OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
  283.         OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset        Shift Mapping RAM Counter (0x00~0x3F)
  284.         OLED_WR_Byte(0x00,OLED_CMD);//-not offset
  285.         OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
  286.         OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
  287.         OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
  288.         OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  289.         OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
  290.         OLED_WR_Byte(0x12,OLED_CMD);
  291.         OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
  292.         OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
  293.         OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
  294.         OLED_WR_Byte(0x02,OLED_CMD);//
  295.         OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
  296.         OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
  297.         OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
  298.         OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
  299.         OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
  300.        
  301.         OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/
  302.         OLED_Clear();
  303.         OLED_Set_Pos(0,0);        
  304. }  
復(fù)制代碼

所有資料51hei提供下載:
0.96OLED_C51_SPI.rar (128.77 KB, 下載次數(shù): 253)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏10 分享淘帖 頂1 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:557850 發(fā)表于 2019-6-8 19:25 | 只看該作者
多謝分享
回復(fù)

使用道具 舉報(bào)

板凳
ID:585455 發(fā)表于 2019-7-22 15:52 | 只看該作者
正想學(xué)SPI通信,感謝分享。
回復(fù)

使用道具 舉報(bào)

地板
ID:776844 發(fā)表于 2020-6-12 05:01 | 只看該作者

多謝分享
回復(fù)

使用道具 舉報(bào)

5#
ID:754694 發(fā)表于 2020-6-24 22:38 來(lái)自手機(jī) | 只看該作者
謝謝樓主分享,剛著~
回復(fù)

使用道具 舉報(bào)

6#
ID:151348 發(fā)表于 2020-10-11 14:42 | 只看該作者
主控:STC15W408AS,測(cè)試可用
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 在线播放中文字幕 | 亚洲 中文 欧美 | 毛片网络| 亚洲精品乱 | 色偷偷噜噜噜亚洲男人 | 一本色道精品久久一区二区三区 | 亚洲成人99 | 欧美日韩成人在线 | 拍真实国产伦偷精品 | 天天综合久久 | 欧美国产精品 | 91婷婷韩国欧美一区二区 | 成人网av | 国产精品99久久久久久动医院 | 亚洲国产一区二区三区在线观看 | 亚洲高清在线播放 | 国产毛片久久久久久久久春天 | 四虎影院久久 | 成人av片在线观看 | 在线国产视频 | 无码一区二区三区视频 | 久久精品久久久久久 | 国产成人久久精品 | 久久躁日日躁aaaaxxxx | 精品久久精品 | 颜色网站在线观看 | 蜜臀av日日欢夜夜爽一区 | 久久99久久99 | 97成人免费 | 真人毛片| 国产精品一区二区不卡 | 99精品在线观看 | 成人妇女免费播放久久久 | av网站在线播放 | 精品欧美一区二区三区久久久小说 | 成人激情视频免费观看 | 亚洲 中文 欧美 日韩 在线观看 | 精品欧美一区免费观看α√ | 久久免费精品 | 在线播放一区 | 中文字幕人成人 |