1024手机基地看电影,午夜福利视频导航,国产精品福利在线一区,亚洲欧美日韩另类成人,在线观看午夜日本理论片,成年超爽免费网站,国产精品成人免费,精品动作一级毛片,成人免费观看网站,97精品伊人久久大香蕉

標(biāo)題: 51單片機(jī)和OLED仿真 芯片SSD1306 [打印本頁]

作者: 15961840023    時(shí)間: 2020-5-6 12:22
標(biāo)題: 51單片機(jī)和OLED仿真 芯片SSD1306
用的是7Pin的OLED,就那個(gè)寶買的那種。用的是不是中景園的程序我就不知道了。芯片應(yīng)該是用SSD1306,但是用仿真里面的SSD1306總是不對(duì)。我隨便試了試SSD1308到時(shí)對(duì)了!


單片機(jī)源程序如下:
  1. #include "xianshispi.h"
  2. #include "oledfont.h"

  3. void delay_ms(unsigned int ms)
  4. {                        
  5.         unsigned int a;
  6.         while(ms)
  7.         {
  8.                 a=1800;
  9.                 while(a--);
  10.                 ms--;
  11.         }
  12.         return;
  13. }

  14. void OLED_WR_Byte(unsigned char dat,unsigned char cmd)                                           //寫數(shù)據(jù) 或 指令
  15. {                                                   //        數(shù)據(jù)                          指令
  16.         unsigned char i;                          
  17.         if(cmd) {OLED_DC(1);}
  18.         else  {OLED_DC(0);        }          
  19.         OLED_CS(0);
  20.         for(i=0;i<8;i++)
  21.         {                          
  22.                 OLED_SCL(0);
  23.                 if(dat&0x80)
  24.                         {
  25.                    OLED_SDIN(1);
  26.                         }
  27.                 else
  28.                 OLED_SDIN(0);
  29.                 OLED_SCL(1);
  30.                 dat<<=1;   
  31.         }                                                   
  32.         OLED_CS(1);
  33.         OLED_DC(1);             
  34. }
  35. void OLED_Set_Pos(unsigned char x, unsigned char y)                                    // 定位 —(軸)
  36. {
  37.         OLED_WR_Byte(0xb0+y,OLED_CMD);
  38.         OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  39.         OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD);
  40. }             
  41. void OLED_Display_On(void)
  42. {
  43.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC??
  44.         OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
  45.         OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
  46. }   
  47. void OLED_Display_Off(void)
  48. {
  49.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC??
  50.         OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
  51.         OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
  52. }                                                      
  53. void OLED_Clear(void)                                                                                                           //清屏(全)
  54. {  
  55.         unsigned char i,n;                    
  56.         for(i=0;i<8;i++)  
  57.         {  
  58.                 OLED_WR_Byte (0xb0+i,OLED_CMD);
  59.                 OLED_WR_Byte (0x02,OLED_CMD);     
  60.                 OLED_WR_Byte (0x10,OLED_CMD);        
  61.                 for(n=0;n<128;n++)OLED_WR_Byte(0x00,OLED_DATA);
  62.         }
  63. }
  64. void OLED_Clear2(void)                                                                                                   //清屏(一般)
  65. {  
  66.         unsigned char i,n;                    
  67.         for(i=0;i<2;i++)  
  68.         {  
  69.                 OLED_WR_Byte (0xb0+i,OLED_CMD);
  70.                 OLED_WR_Byte (0x02,OLED_CMD);   
  71.                 OLED_WR_Byte (0x10,OLED_CMD);      
  72.                 for(n=0;n<128;n++)OLED_WR_Byte(0xff,OLED_DATA);
  73.         }
  74. }
  75. void OLED_ShowChar(unsigned char x,unsigned char y,unsigned int chr)                          //字符取反  (背景和數(shù)據(jù))
  76. {             
  77.         unsigned int c=0,i=0;       
  78.         c=chr-' ';                       
  79.         if(x>Max_Column-1){x=0;y=y+2;}
  80.         if(SIZE==16)
  81.         {
  82.                 OLED_Set_Pos(x,y);       
  83.                 for(i=0;i<8;i++)
  84.                 OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
  85.                 OLED_Set_Pos(x,y+1);
  86.                 for(i=0;i<8;i++)
  87.                 OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
  88.         }
  89.         else
  90.         {       
  91.                 OLED_Set_Pos(x,y+1);
  92.                 for(i=0;i<6;i++)
  93.                 {
  94.                         OLED_WR_Byte(F6x8[c][i],OLED_DATA);
  95.                 }
  96.         }
  97. }
  98. void OLED_ShowChar111(unsigned char x,unsigned char y,unsigned int chr)                          //字符取反  (背景和數(shù)據(jù))
  99. {             
  100.         unsigned int c=0,i=0;       
  101.         c=chr-' ';                       
  102.         if(x>Max_Column-1){x=0;y=y+2;}
  103.         if(SIZE==16)
  104.         {
  105.                 OLED_Set_Pos(x,y);       
  106.                 for(i=0;i<8;i++)
  107.                 OLED_WR_Byte(~F8X16[c*16+i],OLED_DATA);
  108.                 OLED_Set_Pos(x,y+1);
  109.                 for(i=0;i<8;i++)
  110.                 OLED_WR_Byte(~F8X16[c*16+i+8],OLED_DATA);
  111.         }
  112.         else
  113.         {       
  114.                 OLED_Set_Pos(x,y+1);
  115.                 for(i=0;i<6;i++)
  116.                 {
  117.                         OLED_WR_Byte(~F6x8[c][i],OLED_DATA);
  118.                 }
  119.         }
  120. }
  121. unsigned int oled_pow(unsigned char m,unsigned char n)
  122. {
  123.         unsigned int result=1;         
  124.         while(n--)result*=m;   
  125.         return result;
  126. }                                                    
  127. void OLED_ShowNum(unsigned char x,unsigned char y,unsigned int num,unsigned char len,unsigned char size)
  128. {                
  129.         unsigned char t,temp;
  130.         unsigned char enshow=0;                                                  
  131.         for(t=0;t<len;t++)
  132.         {
  133.                 temp=(num/oled_pow(10,len-t-1))%10;
  134.                 if(enshow==0&&t<(len-1))
  135.                 {
  136.                         if(temp==0)
  137.                         {
  138.                                 OLED_ShowChar(x+(size/2)*t,y,' ');
  139.                                 continue;
  140.                         }else enshow=1;  
  141.                 }
  142.                  OLED_ShowChar(x+(size/2)*t,y,temp+'0');
  143.         }
  144. }
  145. //????????
  146. void OLED_ShowString(unsigned char x,unsigned char y,unsigned char *chr,unsigned char no)                   //顯示字符串
  147. {
  148.         unsigned int j=0;
  149.         while (chr[j]!='\0')
  150.         {               
  151.                         if(no)
  152.                         {OLED_ShowChar(x,y,chr[j]);}
  153.                         else{OLED_ShowChar111(x,y,chr[j]);}
  154.                
  155.                 x+=8;
  156.                 if(x>120){x=0;y+=2;}
  157.                 j++;
  158.         }
  159. }
  160. void OLED_ShowCHinese(unsigned char x,unsigned char y,unsigned char *z,unsigned char no1)                          //顯示中文
  161. {                                  
  162.         unsigned char t,i,adder=0;
  163.         while(*z != '\0')
  164.         {
  165.                 for(t=0;t<20;t++)
  166.                 {
  167.                         if(Hzk[t].hzk_2[0]==*z && Hzk[t].hzk_2[1]==*(z+1))
  168.                         {
  169.                                 if(no1 == 1)
  170.                                 {
  171.                                         OLED_Set_Pos(x,y);                for(i=0;i<16;i++){OLED_WR_Byte(Hzk[t].hzk_32[i],OLED_DATA);adder+=1;}
  172.                                         OLED_Set_Pos(x,y+1);        for(i=0;i<16;i++){OLED_WR_Byte(Hzk[t].hzk_32[i+16],OLED_DATA);adder+=1;}       
  173.                                 }
  174.                                 else{
  175.                                         OLED_Set_Pos(x,y);                for(i=0;i<16;i++){OLED_WR_Byte(~Hzk[t].hzk_32[i],OLED_DATA);adder+=1;}
  176.                                         OLED_Set_Pos(x,y+1);        for(i=0;i<16;i++){OLED_WR_Byte(~Hzk[t].hzk_32[i+16],OLED_DATA);adder+=1;}                                       
  177.                                 }                               
  178.                         }
  179.                 }
  180.                 x+=16;
  181.                 z+=2;
  182.         }
  183. }
  184. //void OLED_ShowCHinese1(unsigned char x,unsigned char y,unsigned char z,unsigned char no)
  185. //{                                  
  186. //        unsigned char t,i,adder=0;
  187. //        for(i=0;i<z;i++)
  188. //        {
  189. //
  190. //                        OLED_Set_Pos(x+i*16,y);                for(t=0;t<16;t++){OLED_WR_Byte(Hzk1[2*no+i*2][t],OLED_DATA);adder+=1;}
  191. //                        OLED_Set_Pos(x+i*16,y+1);        for(t=0;t<16;t++){OLED_WR_Byte(Hzk1[2*no+i*2+1][t],OLED_DATA);adder+=1;}       
  192. //        }                                               
  193. //}
  194. void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char *p)                //顯示圖片
  195. {        
  196.         unsigned int j=0;
  197.         unsigned char x,y;
  198.         if(y1%8==0) y=y1/8;      
  199.         else y=y1/8+1;
  200.         for(y=y0;y<y1;y++)
  201.         {
  202.                 OLED_Set_Pos(x0,y);
  203.                     for(x=x0;x<x1;x++)
  204.             {      
  205.                     OLED_WR_Byte(*p++,OLED_DATA);                   
  206.             }
  207.         }
  208. }                                     
  209. void OLED_Init(void)
  210. {
  211.   delay_ms(1);
  212.   OLED_RST(1);
  213.         delay_ms(1);
  214.         OLED_RST(0);
  215.         delay_ms(1);
  216.         OLED_RST(1);
  217.         delay_ms(1);
  218.         OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
  219.         OLED_WR_Byte(0x02,OLED_CMD);//---set low column address
  220.         OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  221. ……………………

  222. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼

所有資料51hei提供下載:
OLED_4SPI.zip (89.91 KB, 下載次數(shù): 463)



作者: myemcu    時(shí)間: 2020-5-7 11:06
請(qǐng)問,如何顯示字庫里第二個(gè)字?
作者: Coses    時(shí)間: 2020-5-7 13:24
還不錯(cuò),試試看
作者: myemcu    時(shí)間: 2020-5-8 17:32
例程不錯(cuò),通過調(diào)試。
作者: 15961840023    時(shí)間: 2020-5-9 18:35
myemcu 發(fā)表于 2020-5-7 11:06
請(qǐng)問,如何顯示字庫里第二個(gè)字?

啥意思啊,顯示中文的話直接輸入要顯示的中文字就行了,這個(gè)看程序怎么設(shè)置
作者: 宇宙君    時(shí)間: 2020-5-19 22:03
樓主你的proteus用的是什么版本的啊 我這邊打不開
作者: 憑欄靜聽瀟瀟雨    時(shí)間: 2020-5-25 23:05
樓主能把完整的proteus原理圖分享出來嗎?
作者: 15961840023    時(shí)間: 2020-7-3 20:40
宇宙君 發(fā)表于 2020-5-19 22:03
樓主你的proteus用的是什么版本的啊 我這邊打不開

用的是8.7版本的
作者: 15961840023    時(shí)間: 2020-7-3 20:41
憑欄靜聽瀟瀟雨 發(fā)表于 2020-5-25 23:05
樓主能把完整的proteus原理圖分享出來嗎?

protues就只有顯示的,其他的就沒有了,我發(fā)的就是完整的
作者: 阿giao    時(shí)間: 2020-7-5 12:59
例程不錯(cuò),通過調(diào)試,感謝樓主
作者: paladina    時(shí)間: 2020-10-10 14:11
很好學(xué)習(xí)了,有沒有IIC的驅(qū)動(dòng)
作者: silentky    時(shí)間: 2020-11-28 15:24
謝謝樓主,終于成功了

作者: fby188    時(shí)間: 2021-1-3 17:20
謝謝,感謝解決了我的難題
作者: taotie    時(shí)間: 2021-1-3 18:14
1306    UG-2864HSWEG01 SPI  可以運(yùn)行的并且沒有警告提示
你是否選錯(cuò)了模型!
作者: taotie    時(shí)間: 2021-1-3 19:23
本帖最后由 taotie 于 2021-1-3 21:13 編輯

[SSD1306] Reset of Controller. [LCD1_U1_U1]



作者: taotie    時(shí)間: 2021-1-3 21:56
SSD1306   spi接口OLED  




作者: mygold    時(shí)間: 2021-3-10 10:34
taotie 發(fā)表于 2021-1-3 21:56
SSD1306   spi接口OLED

請(qǐng)問SSD1306的4針I(yè)IC接口oled,用proteus仿真怎么接線?(主控是STM32f103c8t6,我用中景園的IIC程序無法驅(qū)動(dòng))
作者: 15961840023    時(shí)間: 2021-3-14 13:06
taotie 發(fā)表于 2021-1-3 21:56
SSD1306   spi接口OLED

我也不清楚,我用這個(gè)的時(shí)候沒成功,反倒是用我貼出的那個(gè)成功了,可能是我軟件問題把
作者: xuanhao    時(shí)間: 2021-4-26 22:00
15961840023 發(fā)表于 2021-3-14 13:06
我也不清楚,我用這個(gè)的時(shí)候沒成功,反倒是用我貼出的那個(gè)成功了,可能是我軟件問題把

樓主 這個(gè)實(shí)際電路接1306的是可以用的吧?  我供電5V會(huì)有問題嗎,超過3.3V了

作者: cczjw    時(shí)間: 2021-11-8 10:52
本帖最后由 cczjw 于 2021-11-8 10:58 編輯
taotie 發(fā)表于 2021-1-3 21:56
SSD1306   spi接口OLED

請(qǐng)問 P10-P14各腳與SPI的 SCK、SDO、SDI、CS 是怎樣對(duì)應(yīng)的呢?謝謝!

作者: xxjs120    時(shí)間: 2022-4-26 05:39
謝謝提供的例程,我用atmega8仿真成功
作者: bhjyqjs    時(shí)間: 2022-7-18 09:19


作者: timeisenough    時(shí)間: 2024-3-21 14:59
例程寫的太好啦,借鑒一下大佬的工作!




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1