397 lines
16 KiB
Plaintext
397 lines
16 KiB
Plaintext
C51 COMPILER V9.52.0.0 OLED 05/03/2018 10:40:51 PAGE 1
|
||
|
||
|
||
C51 COMPILER V9.52.0.0, COMPILATION OF MODULE OLED
|
||
OBJECT MODULE PLACED IN oled.obj
|
||
COMPILER INVOKED BY: D:\KEIL_51\C51\BIN\C51.EXE SRC\oled.c BROWSE INCDIR(.\SRC) DEBUG OBJECTEXTEND PRINT(.\oled.lst) TAB
|
||
-S(2) OBJECT(oled.obj)
|
||
|
||
line level source
|
||
|
||
1
|
||
2 #include "oled.h"
|
||
3 //#include "stdlib.h"
|
||
4 #include "oledfont.h"
|
||
5 //#include "delay.h"
|
||
6 //OLEDµÄÏÔ´æ
|
||
7 //´æ·Å¸ñʽÈçÏÂ.
|
||
8 //[0]0 1 2 3 ... 127
|
||
9 //[1]0 1 2 3 ... 127
|
||
10 //[2]0 1 2 3 ... 127
|
||
11 //[3]0 1 2 3 ... 127
|
||
12 //[4]0 1 2 3 ... 127
|
||
13 //[5]0 1 2 3 ... 127
|
||
14 //[6]0 1 2 3 ... 127
|
||
15 //[7]0 1 2 3 ... 127
|
||
16 void delay_ms(unsigned int ms)
|
||
17 {
|
||
18 1 unsigned int a;
|
||
19 1 while(ms)
|
||
20 1 {
|
||
21 2 a=1800;
|
||
22 2 while(a--);
|
||
23 2 ms--;
|
||
24 2 }
|
||
25 1 return;
|
||
26 1 }
|
||
27 /**********************************************
|
||
28 //IIC Start
|
||
29 **********************************************/
|
||
30 void IIC_Start()
|
||
31 {
|
||
32 1
|
||
33 1 OLED_SCLK_Set() ;
|
||
34 1 OLED_SDIN_Set();
|
||
35 1 OLED_SDIN_Clr();
|
||
36 1 OLED_SCLK_Clr();
|
||
37 1 }
|
||
38
|
||
39 /**********************************************
|
||
40 //IIC Stop
|
||
41 **********************************************/
|
||
42 void IIC_Stop()
|
||
43 {
|
||
44 1 OLED_SCLK_Set() ;
|
||
45 1 // OLED_SCLK_Clr();
|
||
46 1 OLED_SDIN_Clr();
|
||
47 1 OLED_SDIN_Set();
|
||
48 1
|
||
49 1 }
|
||
50
|
||
51 void IIC_Wait_Ack()
|
||
52 {
|
||
53 1
|
||
54 1 //GPIOB->CRH &= 0XFFF0FFFF; //ÉèÖÃPB12ΪÉÏÀÊäÈëģʽ
|
||
C51 COMPILER V9.52.0.0 OLED 05/03/2018 10:40:51 PAGE 2
|
||
|
||
55 1 //GPIOB->CRH |= 0x00080000;
|
||
56 1 // OLED_SDA = 1;
|
||
57 1 // delay_us(1);
|
||
58 1 //OLED_SCL = 1;
|
||
59 1 //delay_us(50000);
|
||
60 1 /* while(1)
|
||
61 1 {
|
||
62 1 if(!OLED_SDA) //ÅжÏÊÇ·ñ½ÓÊÕµ½OLED Ó¦´ðÐźÅ
|
||
63 1 {
|
||
64 1 //GPIOB->CRH &= 0XFFF0FFFF; //ÉèÖÃPB12ΪͨÓÃÍÆÃâÊä³öģʽ
|
||
65 1 //GPIOB->CRH |= 0x00030000;
|
||
66 1 return;
|
||
67 1 }
|
||
68 1 }
|
||
69 1 */
|
||
70 1 OLED_SCLK_Set() ;
|
||
71 1 OLED_SCLK_Clr();
|
||
72 1 }
|
||
73 /**********************************************
|
||
74 // IIC Write byte
|
||
75 **********************************************/
|
||
76
|
||
77 void Write_IIC_Byte(unsigned char IIC_Byte)
|
||
78 {
|
||
79 1 unsigned char i;
|
||
80 1 unsigned char m,da;
|
||
81 1 da=IIC_Byte;
|
||
82 1 OLED_SCLK_Clr();
|
||
83 1 for(i=0;i<8;i++)
|
||
84 1 {
|
||
85 2 m=da;
|
||
86 2 // OLED_SCLK_Clr();
|
||
87 2 m=m&0x80;
|
||
88 2 if(m==0x80)
|
||
89 2 {OLED_SDIN_Set();}
|
||
90 2 else OLED_SDIN_Clr();
|
||
91 2 da=da<<1;
|
||
92 2 OLED_SCLK_Set();
|
||
93 2 OLED_SCLK_Clr();
|
||
94 2 }
|
||
95 1
|
||
96 1
|
||
97 1 }
|
||
98 /**********************************************
|
||
99 // IIC Write Command
|
||
100 **********************************************/
|
||
101 void Write_IIC_Command(unsigned char IIC_Command)
|
||
102 {
|
||
103 1 IIC_Start();
|
||
104 1 Write_IIC_Byte(0x78); //Slave address,SA0=0
|
||
105 1 IIC_Wait_Ack();
|
||
106 1 Write_IIC_Byte(0x00); //write command
|
||
107 1 IIC_Wait_Ack();
|
||
108 1 Write_IIC_Byte(IIC_Command);
|
||
109 1 IIC_Wait_Ack();
|
||
110 1 IIC_Stop();
|
||
111 1 }
|
||
112 /**********************************************
|
||
113 // IIC Write Data
|
||
114 **********************************************/
|
||
115 void Write_IIC_Data(unsigned char IIC_Data)
|
||
116 {
|
||
C51 COMPILER V9.52.0.0 OLED 05/03/2018 10:40:51 PAGE 3
|
||
|
||
117 1 IIC_Start();
|
||
118 1 Write_IIC_Byte(0x78); //D/C#=0; R/W#=0
|
||
119 1 IIC_Wait_Ack();
|
||
120 1 Write_IIC_Byte(0x40); //write data
|
||
121 1 IIC_Wait_Ack();
|
||
122 1 Write_IIC_Byte(IIC_Data);
|
||
123 1 IIC_Wait_Ack();
|
||
124 1 IIC_Stop();
|
||
125 1 }
|
||
126 void OLED_WR_Byte(unsigned dat,unsigned cmd)
|
||
127 {
|
||
*** WARNING C235 IN LINE 127 OF SRC\oled.c: parameter 1: different types
|
||
*** WARNING C235 IN LINE 127 OF SRC\oled.c: parameter 2: different types
|
||
128 1 if(cmd)
|
||
129 1 {
|
||
130 2
|
||
131 2 Write_IIC_Data(dat);
|
||
132 2
|
||
133 2 }
|
||
134 1 else {
|
||
135 2 Write_IIC_Command(dat);
|
||
136 2
|
||
137 2 }
|
||
138 1
|
||
139 1
|
||
140 1 }
|
||
141 void OLED_Set_Pos(unsigned char x, unsigned char y)
|
||
142 {
|
||
143 1 OLED_WR_Byte(0xb0+y,OLED_CMD);
|
||
144 1 OLED_WR_Byte((((x+2)&0xf0)>>4)|0x10,OLED_CMD);
|
||
145 1 OLED_WR_Byte(((x+2)&0x0f),OLED_CMD);
|
||
146 1 }
|
||
147 //¿ªÆôOLEDÏÔʾ
|
||
148 void OLED_Display_On(void)
|
||
149 {
|
||
150 1 OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDCÃüÁî
|
||
151 1 OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON
|
||
152 1 OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON
|
||
153 1 }
|
||
154 //¹Ø±ÕOLEDÏÔʾ
|
||
155 void OLED_Display_Off(void)
|
||
156 {
|
||
157 1 OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDCÃüÁî
|
||
158 1 OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF
|
||
159 1 OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF
|
||
160 1 }
|
||
161 //ÇåÆÁº¯Êý,ÇåÍêÆÁ,Õû¸öÆÁÄ»ÊǺÚÉ«µÄ!ºÍûµãÁÁÒ»Ñù!!!
|
||
162 void OLED_Clear(void)
|
||
163 {
|
||
164 1 u8 i,n;
|
||
165 1 for(i=0;i<8;i++)
|
||
166 1 {
|
||
167 2 OLED_WR_Byte (0xb0+i,OLED_CMD); //ÉèÖÃÒ³µØÖ·£¨0~7£©
|
||
168 2 OLED_WR_Byte (0x02,OLED_CMD); //ÉèÖÃÏÔʾλÖáªÁе͵ØÖ·
|
||
169 2 OLED_WR_Byte (0x10,OLED_CMD); //ÉèÖÃÏÔʾλÖáªÁиߵØÖ·
|
||
170 2 for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA);
|
||
171 2 } //¸üÐÂÏÔʾ
|
||
172 1 }
|
||
173
|
||
174
|
||
175 //ÔÚÖ¸¶¨Î»ÖÃÏÔʾһ¸ö×Ö·û,°üÀ¨²¿·Ö×Ö·û
|
||
176 //x:0~127
|
||
C51 COMPILER V9.52.0.0 OLED 05/03/2018 10:40:51 PAGE 4
|
||
|
||
177 //y:0~63
|
||
178 //mode:0,·´°×ÏÔʾ;1,Õý³£ÏÔʾ
|
||
179 //size:Ñ¡Ôñ×ÖÌå 16/12
|
||
180 void OLED_ShowChar(u8 x,u8 y,u8 chr)
|
||
181 {
|
||
182 1 unsigned char c=0,i=0;
|
||
183 1 c=chr-' ';//µÃµ½Æ«ÒƺóµÄÖµ
|
||
184 1 if(x>Max_Column-1){x=0;y=y+2;}
|
||
185 1 if(SIZE ==16)
|
||
186 1 {
|
||
187 2 OLED_Set_Pos(x,y);
|
||
188 2 for(i=0;i<8;i++)
|
||
189 2 OLED_WR_Byte(F8X16[c*16+i],OLED_DATA);
|
||
190 2 OLED_Set_Pos(x,y+1);
|
||
191 2 for(i=0;i<8;i++)
|
||
192 2 OLED_WR_Byte(F8X16[c*16+i+8],OLED_DATA);
|
||
193 2 }
|
||
194 1 else {
|
||
195 2 OLED_Set_Pos(x,y+1);
|
||
196 2 for(i=0;i<6;i++)
|
||
197 2 OLED_WR_Byte(F6x8[c][i],OLED_DATA);
|
||
198 2
|
||
199 2 }
|
||
200 1 }
|
||
201 //m^nº¯Êý
|
||
202 u32 oled_pow(u8 m,u8 n)
|
||
203 {
|
||
204 1 u32 result=1;
|
||
205 1 while(n--)result*=m;
|
||
206 1 return result;
|
||
207 1 }
|
||
208 //ÏÔʾ2¸öÊý×Ö
|
||
209 //x,y :Æðµã×ø±ê
|
||
210 //len :Êý×ÖµÄλÊý
|
||
211 //size:×ÖÌå´óС
|
||
212 //mode:ģʽ 0,Ìî³äģʽ;1,µþ¼Óģʽ
|
||
213 //num:ÊýÖµ(0~4294967295);
|
||
214 void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 size2)
|
||
215 {
|
||
216 1 u8 t,temp;
|
||
217 1 u8 enshow=0;
|
||
218 1 for(t=0;t<len;t++)
|
||
219 1 {
|
||
220 2 temp=(num/oled_pow(10,len-t-1))%10;
|
||
221 2 if(enshow==0&&t<(len-1))
|
||
222 2 {
|
||
223 3 if(temp==0)
|
||
224 3 {
|
||
225 4 OLED_ShowChar(x+(size2/2)*t,y,' ');
|
||
226 4 continue;
|
||
227 4 }else enshow=1;
|
||
228 3
|
||
229 3 }
|
||
230 2 OLED_ShowChar(x+(size2/2)*t,y,temp+'0');
|
||
231 2 }
|
||
232 1 }
|
||
233 //ÏÔʾһ¸ö×Ö·ûºÅ´®
|
||
234 void OLED_ShowString(u8 x,u8 y,u8 *chr)
|
||
235 {
|
||
236 1 unsigned char j=0;
|
||
237 1 while (chr[j]!='\0')
|
||
238 1 { OLED_ShowChar(x,y,chr[j]);
|
||
C51 COMPILER V9.52.0.0 OLED 05/03/2018 10:40:51 PAGE 5
|
||
|
||
239 2 x+=8;
|
||
240 2 if(x>120){x=0;y+=2;}
|
||
241 2 j++;
|
||
242 2 }
|
||
243 1 }
|
||
244 //ÏÔʾºº×Ö
|
||
245 void OLED_ShowCHinese(u8 x,u8 y,u8 no)
|
||
246 {
|
||
247 1 u8 t,adder=0;
|
||
248 1 OLED_Set_Pos(x,y);
|
||
249 1 for(t=0;t<16;t++)
|
||
250 1 {
|
||
251 2 OLED_WR_Byte(Hzk[2*no][t],OLED_DATA);
|
||
252 2 adder+=1;
|
||
253 2 }
|
||
254 1 OLED_Set_Pos(x,y+1);
|
||
255 1 for(t=0;t<16;t++)
|
||
256 1 {
|
||
257 2 OLED_WR_Byte(Hzk[2*no+1][t],OLED_DATA);
|
||
258 2 adder+=1;
|
||
259 2 }
|
||
260 1 }
|
||
261 /***********¹¦ÄÜÃèÊö£ºÏÔʾÏÔʾBMPͼƬ128¡Á64Æðʼµã×ø±ê(x,y),xµÄ·¶Î§0¡«127£¬yΪҳµÄ·¶Î§0¡«7****************
|
||
-*/
|
||
262 void OLED_DrawBMP(unsigned char x0, unsigned char y0,unsigned char x1, unsigned char y1,unsigned char BMP[
|
||
-])
|
||
263 {
|
||
264 1 unsigned int j=0;
|
||
265 1 unsigned char x,y;
|
||
266 1
|
||
267 1 if(y1%8==0) y=y1/8;
|
||
268 1 else y=y1/8+1;
|
||
269 1 for(y=y0;y<y1;y++)
|
||
270 1 {
|
||
271 2 OLED_Set_Pos(x0,y);
|
||
272 2 for(x=x0;x<x1;x++)
|
||
273 2 {
|
||
274 3 OLED_WR_Byte(BMP[j++],OLED_DATA);
|
||
275 3 }
|
||
276 2 }
|
||
277 1 }
|
||
278
|
||
279
|
||
280 //³õʼ»¯SSD1306
|
||
281 void OLED_Init(void)
|
||
282 {
|
||
283 1
|
||
284 1
|
||
285 1
|
||
286 1 OLED_RST_Set();
|
||
287 1 delay_ms(100);
|
||
288 1 OLED_RST_Clr();
|
||
289 1 delay_ms(100);
|
||
290 1 OLED_RST_Set();
|
||
291 1 /*
|
||
292 1 OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
|
||
293 1 OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
|
||
294 1 OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
|
||
295 1 OLED_WR_Byte(0x40,OLED_CMD);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
|
||
296 1 OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
|
||
297 1 OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
|
||
298 1 OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping 0xa0×óÓÒ·´ÖÃ 0xa1Õý³£
|
||
C51 COMPILER V9.52.0.0 OLED 05/03/2018 10:40:51 PAGE 6
|
||
|
||
299 1 OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction 0xc0ÉÏÏ·´Öà 0xc8Õý³£
|
||
300 1 OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
|
||
301 1 OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
|
||
302 1 OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
|
||
303 1 OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
|
||
304 1 OLED_WR_Byte(0x00,OLED_CMD);//-not offset
|
||
305 1 OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
|
||
306 1 OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
|
||
307 1 OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
|
||
308 1 OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
|
||
309 1 OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
|
||
310 1 OLED_WR_Byte(0x12,OLED_CMD);
|
||
311 1 OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
|
||
312 1 OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
|
||
313 1 OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
|
||
314 1 OLED_WR_Byte(0x02,OLED_CMD);//
|
||
315 1 OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
|
||
316 1 OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
|
||
317 1 OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
|
||
318 1 OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
|
||
319 1 OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
|
||
320 1 */
|
||
321 1
|
||
322 1 OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
|
||
323 1 OLED_WR_Byte(0x02,OLED_CMD);//---set low column address
|
||
324 1 OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
|
||
325 1 OLED_WR_Byte(0x40,OLED_CMD);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
|
||
326 1 OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
|
||
327 1 OLED_WR_Byte(0xCF,OLED_CMD); // Set SEG Output Current Brightness
|
||
328 1 OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping 0xa0×óÓÒ·´ÖÃ 0xa1Õý³£
|
||
329 1 OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction 0xc0ÉÏÏ·´Öà 0xc8Õý³£
|
||
330 1 OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
|
||
331 1 OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
|
||
332 1 OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
|
||
333 1 OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
|
||
334 1 OLED_WR_Byte(0x00,OLED_CMD);//-not offset
|
||
335 1 OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
|
||
336 1 OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
|
||
337 1 OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
|
||
338 1 OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
|
||
339 1 OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
|
||
340 1 OLED_WR_Byte(0x12,OLED_CMD);
|
||
341 1 OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
|
||
342 1 OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
|
||
343 1 OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
|
||
344 1 OLED_WR_Byte(0x02,OLED_CMD);//
|
||
345 1 OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
|
||
346 1 OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
|
||
347 1 OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
|
||
348 1 OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
|
||
349 1 OLED_WR_Byte(0xAF,OLED_CMD);//--turn on oled panel
|
||
350 1
|
||
351 1 OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/
|
||
352 1 OLED_Clear();
|
||
353 1 OLED_Set_Pos(0,0);
|
||
354 1 }
|
||
355
|
||
*** WARNING C294 IN LINE 195 OF SRC\oled.c: unreachable code
|
||
|
||
|
||
MODULE INFORMATION: STATIC OVERLAYABLE
|
||
CODE SIZE = 1111 ----
|
||
C51 COMPILER V9.52.0.0 OLED 05/03/2018 10:40:51 PAGE 7
|
||
|
||
CONSTANT SIZE = 2520 ----
|
||
XDATA SIZE = ---- ----
|
||
PDATA SIZE = ---- ----
|
||
DATA SIZE = ---- 35
|
||
IDATA SIZE = ---- ----
|
||
BIT SIZE = ---- ----
|
||
END OF MODULE INFORMATION.
|
||
|
||
|
||
C51 COMPILATION COMPLETE. 3 WARNING(S), 0 ERROR(S)
|