C51 COMPILER V9.00   OLED                                                                  01/27/2016 22:39:08 PAGE 1   


C51 COMPILER V9.00, COMPILATION OF MODULE OLED
OBJECT MODULE PLACED IN oled.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE SRC\oled.c BROWSE INCDIR(.\SRC) DEBUG OBJECTEXTEND PRINT(.\oled.lst) TABS(2
                    -) OBJECT(oled.obj)

line level    source

   1          //////////////////////////////////////////////////////////////////////////////////   
   2          //本程序只供学习使用，未经作者许可，不得用于其它任何用途
   3          //  文 件 名   : main.c
   4          //  版 本 号   : v2.0
   5          //  作    者   : 
   6          //  生成日期   : 2014-0101
   7          //  最近修改   : 
   8          //  功能描述   : OLED 4接口演示例程(51系列)
   9          //              说明: 
  10          //              ----------------------------------------------------------------
  11          //              GND    电源地
  12          //              VCC  接5V或3.3v电源
  13          //              SCL   P1^0
  14          //              SDA   P1^1
  15          //              RES  接P12
  16          //              DC   接P13
  17          //              CS   接P14   -----本模块片选脚已经帮用户接地，无需再接               
  18          //              ----------------------------------------------------------------
  19          //******************************************************************************/。
  20          #include "oled.h"
  21          //#include "stdlib.h"
  22          #include "oledfont.h"    
  23          //#include "delay.h"
  24          //OLED的显存
  25          //存放格式如下.
  26          //[0]0 1 2 3 ... 127  
  27          //[1]0 1 2 3 ... 127  
  28          //[2]0 1 2 3 ... 127  
  29          //[3]0 1 2 3 ... 127  
  30          //[4]0 1 2 3 ... 127  
  31          //[5]0 1 2 3 ... 127  
  32          //[6]0 1 2 3 ... 127  
  33          //[7]0 1 2 3 ... 127         
  34          void delay_ms(unsigned int ms)
  35          {                         
  36   1        unsigned int a;
  37   1        while(ms)
  38   1        {
  39   2          a=1800;
  40   2          while(a--);
  41   2          ms--;
  42   2        }
  43   1        return;
  44   1      }
  45          #if OLED_MODE==1
              //向SSD1106写入一个字节。
              //dat:要写入的数据/命令
              //cmd:数据/命令标志 0,表示命令;1,表示数据;
              void OLED_WR_Byte(u8 dat,u8 cmd)
              {
                DATAOUT(dat);     
                if(cmd)
                  OLED_DC_Set();
                else 
C51 COMPILER V9.00   OLED                                                                  01/27/2016 22:39:08 PAGE 2   

                  OLED_DC_Clr();       
                OLED_CS_Clr();
                OLED_WR_Clr();   
                OLED_WR_Set();
                OLED_CS_Set();    
                OLED_DC_Set();   
              }             
              #else
  63          //向SSD1306写入一个字节。
  64          //dat:要写入的数据/命令
  65          //cmd:数据/命令标志 0,表示命令;1,表示数据;
  66          void OLED_WR_Byte(u8 dat,u8 cmd)
  67          { 
  68   1        u8 i;       
  69   1        if(cmd)
  70   1          OLED_DC_Set();
  71   1        else 
  72   1          OLED_DC_Clr();      
  73   1        OLED_CS_Clr();
  74   1        for(i=0;i<8;i++)
  75   1        {       
  76   2          OLED_SCLK_Clr();
  77   2          if(dat&0x80)
  78   2            {
  79   3             OLED_SDIN_Set();
  80   3            }
  81   2      else
  82   2             OLED_SDIN_Clr();
  83   2              OLED_SCLK_Set();
  84   2          dat<<=1;   
  85   2        }             
  86   1        OLED_CS_Set();
  87   1        OLED_DC_Set();      
  88   1      } 
  89          #endif
  90            void OLED_Set_Pos(unsigned char x, unsigned char y) 
  91          { 
  92   1        OLED_WR_Byte(0xb0+y,OLED_CMD);
  93   1        OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  94   1        OLED_WR_Byte((x&0x0f)|0x01,OLED_CMD); 
  95   1      }       
  96          //开启OLED显示    
  97          void OLED_Display_On(void)
  98          {
  99   1        OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
 100   1        OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
 101   1        OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
 102   1      }
 103          //关闭OLED显示     
 104          void OLED_Display_Off(void)
 105          {
 106   1        OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
 107   1        OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
 108   1        OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
 109   1      }            
 110          //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!    
 111          void OLED_Clear(void)  
 112          {  
 113   1        u8 i,n;       
 114   1        for(i=0;i<8;i++)  
 115   1        {  
 116   2          OLED_WR_Byte (0xb0+i,OLED_CMD);    //设置页地址（0~7）
C51 COMPILER V9.00   OLED                                                                  01/27/2016 22:39:08 PAGE 3   

 117   2          OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
 118   2          OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址   
 119   2          for(n=0;n<131;n++)OLED_WR_Byte(0,OLED_DATA); 
 120   2        } //更新显示
 121   1      }
 122          
 123          
 124          //在指定位置显示一个字符,包括部分字符
 125          //x:0~127
 126          //y:0~63
 127          //mode:0,反白显示;1,正常显示         
 128          //size:选择字体 16/12 
 129          void OLED_ShowChar(u8 x,u8 y,u8 chr)
 130          {       
 131   1        unsigned char c=0,i=0;  
 132   1          c=chr-' ';//得到偏移后的值      
 133   1          if(x>Max_Column-1){x=0;y=y+2;}
 134   1          if(SIZE ==16)
 135   1            {
 136   2            OLED_Set_Pos(x,y);  
 137   2            for(i=0;i<8;i++)
 138   2            OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
 139   2            OLED_Set_Pos(x,y+1);
 140   2            for(i=0;i<8;i++)
 141   2            OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
 142   2            }
 143   1            else {  
 144   2              OLED_Set_Pos(x,y+1);
 145   2              for(i=0;i<6;i++)
 146   2              OLED_WR_Byte(F6x8[c][i],OLED_DATA);
 147   2              
 148   2            }
 149   1      }
 150          //m^n函数
 151          u32 oled_pow(u8 m,u8 n)
 152          {
 153   1        u32 result=1;  
 154   1        while(n--)result*=m;    
 155   1        return result;
 156   1      }         
 157          //显示2个数字
 158          //x,y :起点坐标  
 159          //len :数字的位数
 160          //size:字体大小
 161          //mode:模式 0,填充模式;1,叠加模式
 162          //num:数值(0~4294967295);       
 163          void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2)
 164          {           
 165   1        u8 t,temp;
 166   1        u8 enshow=0;               
 167   1        for(t=0;t<len;t++)
 168   1        {
 169   2          temp=(num/oled_pow(10,len-t-1))%10;
 170   2          if(enshow==0&&t<(len-1))
 171   2          {
 172   3            if(temp==0)
 173   3            {
 174   4              OLED_ShowChar(x+(size2/2)*t,y,' ');
 175   4              continue;
 176   4            }else enshow=1; 
 177   3             
 178   3          }
C51 COMPILER V9.00   OLED                                                                  01/27/2016 22:39:08 PAGE 4   

 179   2          OLED_ShowChar(x+(size2/2)*t,y,temp+'0'); 
 180   2        }
 181   1      } 
 182          //显示一个字符号串
 183          void OLED_ShowString(u8 x,u8 y,u8 *chr)
 184          {
 185   1        unsigned char j=0;
 186   1        while (chr[j]!='\0')
 187   1        {   OLED_ShowChar(x,y,chr[j]);
 188   2            x+=8;
 189   2          if(x>120){x=0;y+=2;}
 190   2            j++;
 191   2        }
 192   1      }
 193          //显示汉字
 194          void OLED_ShowCHinese(u8 x,u8 y,u8 no)
 195          {               
 196   1        u8 t,adder=0;
 197   1        OLED_Set_Pos(x,y);  
 198   1          for(t=0;t<16;t++)
 199   1          {
 200   2              OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
 201   2              adder+=1;
 202   2           }  
 203   1          OLED_Set_Pos(x,y+1);  
 204   1          for(t=0;t<16;t++)
 205   1            { 
 206   2              OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
 207   2              adder+=1;
 208   2            }         
 209   1      }
 210          /***********功能描述：显示显示BMP图片128×64起始点坐标(x,y),x的范围0～127，y为页的范围0～7****************
             -*/
 211          void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[
             -])
 212          {   
 213   1       unsigned int j=0;
 214   1       unsigned char x,y;
 215   1        
 216   1        if(y1%8==0) y=y1/8;      
 217   1        else y=y1/8+1;
 218   1        for(y=y0;y<y1;y++)
 219   1        {
 220   2          OLED_Set_Pos(x0,y);
 221   2          for(x=x0;x<x1;x++)
 222   2            {      
 223   3              OLED_WR_Byte(BMP[j++],OLED_DATA);       
 224   3            }
 225   2        }
 226   1      } 
 227          
 228          
 229          //初始化SSD1306             
 230          void OLED_Init(void)
 231          {
 232   1       
 233   1      
 234   1       
 235   1        OLED_RST_Set();
 236   1        delay_ms(100);
 237   1        OLED_RST_Clr();
 238   1        delay_ms(100);
C51 COMPILER V9.00   OLED                                                                  01/27/2016 22:39:08 PAGE 5   

 239   1        OLED_RST_Set(); 
 240   1        /*          
 241   1        OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
 242   1        OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
 243   1        OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
 244   1        OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
 245   1        OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
 246   1        OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
 247   1        OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
 248   1        OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
 249   1        OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
 250   1        OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
 251   1        OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
 252   1        OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
 253   1        OLED_WR_Byte(0x00,OLED_CMD);//-not offset
 254   1        OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
 255   1        OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
 256   1        OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
 257   1        OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
 258   1        OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
 259   1        OLED_WR_Byte(0x12,OLED_CMD);
 260   1        OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
 261   1        OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
 262   1        OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
 263   1        OLED_WR_Byte(0x02,OLED_CMD);//
 264   1        OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
 265   1        OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
 266   1        OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
 267   1        OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7) 
 268   1        OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
 269   1        */
 270   1      
 271   1        OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
 272   1        OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
 273   1        OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
 274   1        OLED_WR_Byte(0x40,OLED_CMD);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
 275   1        OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
 276   1        OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
 277   1        OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
 278   1        OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
 279   1        OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
 280   1        OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
 281   1        OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
 282   1        OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
 283   1        OLED_WR_Byte(0x00,OLED_CMD);//-not offset
 284   1        OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
 285   1        OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
 286   1        OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
 287   1        OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
 288   1        OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
 289   1        OLED_WR_Byte(0x12,OLED_CMD);
 290   1        OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
 291   1        OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
 292   1        OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
 293   1        OLED_WR_Byte(0x02,OLED_CMD);//
 294   1        OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
 295   1        OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
 296   1        OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
 297   1        OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7) 
 298   1        OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
 299   1        
 300   1        OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/ 
C51 COMPILER V9.00   OLED                                                                  01/27/2016 22:39:08 PAGE 6   

 301   1        OLED_Clear();
 302   1        OLED_Set_Pos(0,0);  
 303   1      }  
 304          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    832    ----
   CONSTANT SIZE    =   2520    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----      27
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
