找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1567|回复: 2
打印 上一主题 下一主题
收起左侧

atmega128实现oled画点功能 程序编译错误the expression must be a modifiable lvalue

[复制链接]
跳转到指定楼层
楼主
ID:371250 发表于 2019-7-10 15:52 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Error: C:\Users\zxc60\Desktop\avr资料\demo2.0\oled.c(116): the expression must be a modifiable lvalue
Error: C:\Users\zxc60\Desktop\avr资料\demo2.0\oled.c(118): no matching if

这可咋整啊
!!!!
救救孩子!!!!!!
本来想吧我们在128内部定义了一个块GRAM:u8 OLED_GRAM[128][8];此部分GRAM对应OLED模块上的GRAM。在操作的时候,我们只要修改STM32内部的GRAM就可以了,然后通过OLED_Refresh_Gram函数把GRAM一次刷新到OLED 的GRAM上。可是128RAM太小了,老师提醒可以放在FLASH里,。。。可是FLASH要初始化u8 OLED_GRAM[128][8];得怎么写呜呜呜

单片机源程序如下:
  1. #include "oled.h"
  2. //#include "stdlib.h"
  3. #include "oledfont.h"      
  4. #include "delay.h"

  5. //OLED的显存
  6. //存放格式如下.
  7. //[0]0 1 2 3 ... 127   
  8. //[1]0 1 2 3 ... 127   
  9. //[2]0 1 2 3 ... 127   
  10. //[3]0 1 2 3 ... 127   
  11. //[4]0 1 2 3 ... 127   
  12. //[5]0 1 2 3 ... 127   
  13. //[6]0 1 2 3 ... 127   
  14. //[7]0 1 2 3 ... 127               
  15. //void delay_ms(unsigned int ms)
  16. //{                        
  17. //    unsigned int a;
  18. //    while(ms)
  19. //    {
  20. //        a=1800;
  21. //        while(a--);
  22. //        ms--;
  23. //    }
  24. //    return;
  25. //}


  26. #if OLED_MODE==1
  27. //向SSD1106写入一个字节。
  28. //dat:要写入的数据/命令
  29. //cmd:数据/命令标志 0,表示命令;1,表示数据;
  30. void OLED_WR_Byte(u8 dat,u8 cmd)
  31. {
  32.     DATAOUT(dat);        
  33.     if(cmd)
  34.     OLED_DC_Set();
  35.     else
  36.      OLED_DC_Clr();           
  37.     OLED_CS_Clr();
  38.     OLED_WR_Clr();     
  39.     OLED_WR_Set();
  40.     OLED_CS_Set();      
  41.     OLED_DC_Set();     
  42. }                 
  43. #else
  44. //向SSD1306写入一个字节。
  45. //dat:要写入的数据/命令
  46. //cmd:数据/命令标志 0,表示命令;1,表示数据;
  47. void OLED_WR_Byte(u8 dat,u8 cmd)
  48. {   
  49.     u8 i;              
  50.     if(cmd)
  51.     {
  52.     PORTG&=0xf7;PORTG|=0x08;//OLED_DC_Set();
  53.     }
  54.     else
  55.     PORTG&=0xf7;//OLED_DC_Clr();         
  56.     PORTG&=0xef;//OLED_CS_Clr();
  57.     for(i=0;i<8;i++)
  58.     {              
  59.         PORTG&=0xfe;//OLED_SCLK_Clr();
  60.         if(dat&0x80)
  61.         {
  62.         PORTG&=0xfd;PORTG|=0x02;//OLED_SDIN_Set();
  63.         }
  64.         else
  65.         PORTG&=0xfd;//OLED_SDIN_Clr();
  66.         PORTG&=0xfe;PORTG|=0x01;//OLED_SCLK_Set();
  67.         dat<<=1;   
  68.     }                           
  69.     PORTG&=0xef;PORTG|=0x10;//OLED_CS_Set();
  70.     PORTG&=0xf7;PORTG|=0x08;//OLED_DC_Set();         
  71. }
  72. #endif

  73. flash u8 OLED_GRAM[128][8]={0x00};
  74. void OLED_Refresh_Gram(void)

  75. {

  76.        u8 i,n;               

  77.        for(i=0;i<8;i++)  

  78.        {  

  79.               OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)

  80.               OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址

  81.               OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址   

  82.               for(n=0;n<128;n++)OLED_WR_Byte(OLED_GRAM[n][i],OLED_DATA);

  83.        }   

  84. }



  85. void OLED_DrawPoint(u8 x,u8 y,u8 t)

  86. {

  87.        u8 pos,bx,temp=0;

  88.        if(x>127||y>63)return;//超出范围了.

  89.        pos=7-y/8;

  90.        bx=y%8;

  91.        temp=1<<(7-bx);

  92.        if(t)OLED_GRAM[x][pos]|=temp;

  93.        else OLED_GRAM[x][pos]&=~temp;      

  94. }



  95. //确定点亮显示屏的起始位置
  96. void OLED_Set_Pos(unsigned char x, unsigned char y)
  97. {
  98.     OLED_WR_Byte(0xb0+y,OLED_CMD);                 //设置页地址(0~7)
  99.     OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  100.     OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD);
  101. }


  102. //开启OLED显示   
  103. //void OLED_Display_On(void)
  104. //{
  105. //    OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  106. //    OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
  107. //    OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
  108. //}
  109. ////关闭OLED显示     
  110. //void OLED_Display_Off(void)
  111. //{
  112. //    OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  113. //    OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
  114. //    OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
  115. //}                        
  116. //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!      
  117. void OLED_Clear(void)  
  118. {  
  119.     u8 i,n;            
  120.     for(i=0;i<8;i++)  
  121.     {  
  122.         OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址(0~7)
  123.         OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
  124.         OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址   
  125.         for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA);
  126.     } //更新显示
  127. }
  128. //void OLED_DrawPoint(u8 x,u8 y,u8 t)
  129. //
  130. //{
  131. //
  132. //       u8 pos,bx,temp=0;
  133. //
  134. //      if(x>63||y>63)return;//超出范围了.
  135. //
  136. //       pos=7-y/8;
  137. //
  138. //      bx=y%8;
  139. //
  140. //       temp=1<<(7-bx);
  141. //
  142. //      if(t)OLED_GRAM[x][pos]|=temp;
  143. //
  144. //     else OLED_GRAM[x][pos]&=~temp;      
  145. //
  146. //}

  147. //在指定位置显示一个字符,包括部分字符
  148. //x:0~127
  149. //y:0~63
  150. //mode:0,反白显示;1,正常显示                 
  151. //size:选择字体 16/12
  152. void OLED_ShowChar(u8 x,u8 y,u8 chr)
  153. {         
  154.     unsigned char c=0,i=0;   
  155.         c=chr-' ';//得到偏移后的值            
  156.         if(x>Max_Column-1){x=0;y=y+2;}
  157.         if(SIZE ==16)
  158.             {
  159.             OLED_Set_Pos(x,y);   
  160.             for(i=0;i<8;i++)
  161.             OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
  162.             OLED_Set_Pos(x,y+1);
  163.             for(i=0;i<8;i++)
  164.             OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
  165.             }
  166.             else {   
  167.                 OLED_Set_Pos(x,y+1);
  168.                 for(i=0;i<6;i++)
  169.                 OLED_WR_Byte(F6x8[c][i],OLED_DATA);

  170.             }
  171. }
  172. //m^n函数
  173. //u32 oled_pow(u8 m,u8 n)
  174. //{
  175. //    u32 result=1;     
  176. //    while(n--)result*=m;   
  177. //    return result;
  178. //}                  
  179. //显示2个数字
  180. //x,y :起点坐标     
  181. //len :数字的位数
  182. //size:字体大小
  183. //mode:模式    0,填充模式;1,叠加模式
  184. //num:数值(0~4294967295);               
  185. //void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2)
  186. //{            
  187. //    u8 t,temp;
  188. //    u8 enshow=0;                           
  189. //    for(t=0;t<len;t++)
  190. //    {
  191. //        temp=(num/oled_pow(10,len-t-1))%10;
  192. //        if(enshow==0&&t<(len-1))
  193. //        {
  194. //            if(temp==0)
  195. //            {
  196. //                OLED_ShowChar(x+(size2/2)*t,y,' ');
  197. //                continue;
  198. //            }else enshow=1;
  199. //              
  200. //        }
  201. //         OLED_ShowChar(x+(size2/2)*t,y,temp+'0');
  202. //    }
  203. //}
  204. //显示一个字符号串
  205. void OLED_ShowString(u8 x,u8 y,u8 *chr)
  206. {

  207.     unsigned char j=0;
  208.     OLED_Set_Pos(x,y);
  209.     while (chr[j]!='\0')
  210.     {        OLED_ShowChar(x,y,chr[j]);
  211.             x+=8;
  212.         if(x>120){x=0;y+=2;}
  213.             j++;
  214.     }
  215. }
  216. //显示汉字
  217. void OLED_ShowCHinese(u8 x,u8 y,u8 no)
  218. {                     
  219.     u8 t,adder=0;
  220.     OLED_Set_Pos(x,y);   
  221.     for(t=0;t<16;t++)
  222.         {
  223.                 OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
  224.                 adder+=1;
  225.      }   
  226.         OLED_Set_Pos(x,y+1);   
  227.     for(t=0;t<16;t++)
  228.             {   
  229.                 OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
  230.                 adder+=1;
  231.       }                    
  232. }
  233. /***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
  234. //void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[])
  235. //{     
  236. // unsigned int j=0;
  237. // unsigned char x,y;
  238. //  
  239. //  if(y1%8==0) y=y1/8;      
  240. //  else y=y1/8+1;
  241. //    for(y=y0;y<y1;y++)
  242. //    {
  243. //        OLED_Set_Pos(x0,y);
  244. //    for(x=x0;x<x1;x++)
  245. //        {      
  246. //            OLED_WR_Byte(BMP[j++],OLED_DATA);            
  247. //        }
  248. //    }
  249. //}


  250. //初始化SSD1306                        
  251. void OLED_Init(void)
  252. {



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

  288.     OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
  289.     OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  290.     OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  291.     OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  292.     OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
  293.     OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
  294.     OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
  295.     OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
  296.     OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
  297.     OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  298.     OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
  299.     OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset    Shift Mapping RAM Counter (0x00~0x3F)
  300.     OLED_WR_Byte(0x00,OLED_CMD);//-not offset
  301.     OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
  302.     OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
  303.     OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
  304.     OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  305.     OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
  306.     OLED_WR_Byte(0x12,OLED_CMD);
  307.     OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
  308.     OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
  309.     OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
  310.     OLED_WR_Byte(0x02,OLED_CMD);//
  311.     OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
  312.     OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
  313.     OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
  314.     OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
  315.     OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel

  316.     OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/
  317.     OLED_Clear();
  318.     OLED_Set_Pos(0,0);     
  319. }  
复制代码
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:307782 发表于 2019-9-3 07:54 | 只看该作者
楼主解决了吗????我的oled始终不亮  小白求教
回复

使用道具 举报

板凳
ID:307782 发表于 2019-9-3 08:27 | 只看该作者
楼主解决了吗???现在遇到同样的问题,解决了的话,还望更新一下帖子,救救我,,,,,,
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表