oled.lst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 1
  2. C51 COMPILER V9.54, COMPILATION OF MODULE OLED
  3. OBJECT MODULE PLACED IN .\Objects\oled.obj
  4. COMPILER INVOKED BY: D:\Keil5 C51\C51\BIN\C51.EXE oled.c LARGE OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND PRINT(.\Listi
  5. -ngs\oled.lst) TABS(2) OBJECT(.\Objects\oled.obj)
  6. line level source
  7. 1 #include "STC8XXXX.H"
  8. 2 #include "oled.h"
  9. 3 #include "oledfont.h"
  10. 4 #include <math.h>
  11. 5 #include <stdlib.h>
  12. 6 #include <string.h>
  13. 7
  14. 8 unsigned char _buf[128*8]=0;
  15. 9
  16. 10 unsigned char code height=8;
  17. 11 unsigned char code width=128;
  18. 12
  19. 13 bit _OLED_Reverse = 0;
  20. 14 bit _OLED_Overlap = 1;
  21. 15
  22. 16 static char __x, __y;
  23. 17
  24. 18 void delay_ms(unsigned int ms)
  25. 19 {
  26. 20 1 unsigned int a;
  27. 21 1 while(ms)
  28. 22 1 {
  29. 23 2 a=1800;
  30. 24 2 while(a--);
  31. 25 2 ms--;
  32. 26 2 }
  33. 27 1 return;
  34. 28 1 }
  35. 29
  36. 30 //反显函数
  37. 31 void OLED_ColorTurn(u8 i)
  38. 32 {
  39. 33 1 if(i==0)
  40. 34 1 {
  41. 35 2 OLED_WR_Byte(0xA6,OLED_CMD);//正常显示
  42. 36 2 }
  43. 37 1 if(i==1)
  44. 38 1 {
  45. 39 2 OLED_WR_Byte(0xA7,OLED_CMD);//反色显示
  46. 40 2 }
  47. 41 1 }
  48. 42
  49. 43 //屏幕旋转180度
  50. 44 void OLED_DisplayTurn(u8 i)
  51. 45 {
  52. 46 1 if(i==0)
  53. 47 1 {
  54. 48 2 OLED_WR_Byte(0xC8,OLED_CMD);//正常显示
  55. 49 2 OLED_WR_Byte(0xA1,OLED_CMD);
  56. 50 2 }
  57. 51 1 if(i==1)
  58. 52 1 {
  59. 53 2 OLED_WR_Byte(0xC0,OLED_CMD);//反转显示
  60. 54 2 OLED_WR_Byte(0xA0,OLED_CMD);
  61. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 2
  62. 55 2 }
  63. 56 1 }
  64. 57
  65. 58 //延时
  66. 59 void IIC_delay(void)
  67. 60 {
  68. 61 1 _nop_();
  69. 62 1 }
  70. 63
  71. 64 //起始信号
  72. 65 void I2C_Start(void)
  73. 66 {
  74. 67 1 OLED_SDA_Set();
  75. 68 1 OLED_SCL_Set();
  76. 69 1 IIC_delay();
  77. 70 1 OLED_SDA_Clr();
  78. 71 1 IIC_delay();
  79. 72 1 OLED_SCL_Clr();
  80. 73 1
  81. 74 1 }
  82. 75
  83. 76 //结束信号
  84. 77 void I2C_Stop(void)
  85. 78 {
  86. 79 1 OLED_SDA_Clr();
  87. 80 1 OLED_SCL_Set();
  88. 81 1 IIC_delay();
  89. 82 1 OLED_SDA_Set();
  90. 83 1 }
  91. 84
  92. 85 //等待信号响应
  93. 86 void I2C_WaitAck(void) //测数据信号的电平
  94. 87 {
  95. 88 1 OLED_SDA_Set();
  96. 89 1 IIC_delay();
  97. 90 1 OLED_SCL_Set();
  98. 91 1 IIC_delay();
  99. 92 1 OLED_SCL_Clr();
  100. 93 1 IIC_delay();
  101. 94 1 }
  102. 95
  103. 96 //写入一个字节
  104. 97 void Send_Byte(u8 dat)
  105. 98 {
  106. 99 1 u8 i;
  107. 100 1 for(i=0;i<8;i++)
  108. 101 1 {
  109. 102 2 OLED_SCL_Clr();//将时钟信号设置为低电平
  110. 103 2 if(dat&0x80)//将dat的8位从最高位依次写入
  111. 104 2 {
  112. 105 3 OLED_SDA_Set();
  113. 106 3 }
  114. 107 2 else
  115. 108 2 {
  116. 109 3 OLED_SDA_Clr();
  117. 110 3 }
  118. 111 2 IIC_delay();
  119. 112 2 OLED_SCL_Set();
  120. 113 2 IIC_delay();
  121. 114 2 OLED_SCL_Clr();
  122. 115 2 dat<<=1;
  123. 116 2 }
  124. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 3
  125. 117 1 }
  126. 118
  127. 119 //发送一个字节
  128. 120 //向SSD1306写入一个字节。
  129. 121 //mode:数据/命令标志 0,表示命令;1,表示数据;
  130. 122 void OLED_WR_Byte(u8 dat,u8 mode)
  131. 123 {
  132. 124 1 I2C_Start();
  133. 125 1 Send_Byte(0x78);
  134. 126 1 I2C_WaitAck();
  135. 127 1 if(mode){Send_Byte(0x40);}
  136. 128 1 else{Send_Byte(0x00);}
  137. 129 1 I2C_WaitAck();
  138. 130 1 Send_Byte(dat);
  139. 131 1 I2C_WaitAck();
  140. 132 1 I2C_Stop();
  141. 133 1 }
  142. 134
  143. 135 //坐标设置
  144. 136 void OLED_Set_Pos(u8 x, u8 y)
  145. 137 {
  146. 138 1 OLED_WR_Byte(0xb0+y,OLED_CMD);
  147. 139 1 OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  148. 140 1 OLED_WR_Byte((x&0x0f),OLED_CMD);
  149. 141 1 }
  150. 142 //开启OLED显示
  151. 143 void OLED_Display_On(void)
  152. 144 {
  153. 145 1 OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令
  154. 146 1 OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON
  155. 147 1 OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON
  156. 148 1 }
  157. 149 //关闭OLED显示
  158. 150 void OLED_Display_Off(void)
  159. 151 {
  160. 152 1 OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令
  161. 153 1 OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF
  162. 154 1 OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF
  163. 155 1 }
  164. 156 //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!
  165. 157 void OLED_Clear(void)
  166. 158 {
  167. 159 1 u8 i,n;
  168. 160 1 for(i=0;i<8;i++)
  169. 161 1 {
  170. 162 2 OLED_WR_Byte (0xb0+i,OLED_CMD); //设置页地址(0~7)
  171. 163 2 OLED_WR_Byte (0x00,OLED_CMD); //设置显示位置—列低地址
  172. 164 2 OLED_WR_Byte (0x10,OLED_CMD); //设置显示位置—列高地址
  173. 165 2 for(n=0;n<128;n++)OLED_WR_Byte(0,OLED_DATA);
  174. 166 2 } //更新显示
  175. 167 1 }
  176. 168
  177. 169 //在指定位置显示一个字符,包括部分字符
  178. 170 //x:0~127
  179. 171 //y:0~63
  180. 172 //sizey:选择字体 6x8 8x16
  181. 173 void OLED_ShowChar(u8 x,u8 y,u8 chr,u8 sizey)
  182. 174 {
  183. 175 1 u8 c=0,sizex=sizey/2;
  184. 176 1 u16 i=0,size1;
  185. 177 1 if(sizey==8)size1=6;
  186. 178 1 else size1=(sizey/8+((sizey%8)?1:0))*(sizey/2);
  187. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 4
  188. 179 1 c=chr-' ';//得到偏移后的值
  189. 180 1 OLED_Set_Pos(x,y);
  190. 181 1 for(i=0;i<size1;i++)
  191. 182 1 {
  192. 183 2 if(i%sizex==0&&sizey!=8) OLED_Set_Pos(x,y++);
  193. 184 2 if(sizey==8) OLED_WR_Byte(asc2_0806[c][i],OLED_DATA);//6X8字号
  194. 185 2 else if(sizey==16) OLED_WR_Byte(asc2_1608[c][i],OLED_DATA);//8x16字号
  195. 186 2 // else if(sizey==xx) OLED_WR_Byte(asc2_xxxx[c][i],OLED_DATA);//用户添加字号
  196. 187 2 else return;
  197. 188 2 }
  198. 189 1 }
  199. 190 //m^n函数
  200. 191 u32 oled_pow(u8 m,u8 n)
  201. 192 {
  202. 193 1 u32 result=1;
  203. 194 1 while(n--)result*=m;
  204. 195 1 return result;
  205. 196 1 }
  206. 197 //显示数字
  207. 198 //x,y :起点坐标
  208. 199 //num:要显示的数字
  209. 200 //len :数字的位数
  210. 201 //sizey:字体大小
  211. 202 void OLED_ShowNum(u8 x,u8 y,u32 num,u8 len,u8 sizey)
  212. 203 {
  213. 204 1 u8 t,temp,m=0;
  214. 205 1 u8 enshow=0;
  215. 206 1 if(sizey==8)m=2;
  216. 207 1 for(t=0;t<len;t++)
  217. 208 1 {
  218. 209 2 temp=(num/oled_pow(10,len-t-1))%10;
  219. 210 2 if(enshow==0&&t<(len-1))
  220. 211 2 {
  221. 212 3 if(temp==0)
  222. 213 3 {
  223. 214 4 OLED_ShowChar(x+(sizey/2+m)*t,y,' ',sizey);
  224. 215 4 continue;
  225. 216 4 }else enshow=1;
  226. 217 3 }
  227. 218 2 OLED_ShowChar(x+(sizey/2+m)*t,y,temp+'0',sizey);
  228. 219 2 }
  229. 220 1 }
  230. 221
  231. 222 //显示一个字符号串
  232. 223 void OLED_ShowString(u8 x,u8 y,u8 *chr,u8 sizey)
  233. 224 {
  234. 225 1 u8 j=0;
  235. 226 1 while (chr[j]!='\0')
  236. 227 1 {
  237. 228 2 OLED_ShowChar(x,y,chr[j++],sizey);
  238. 229 2 if(sizey==8)x+=6;
  239. 230 2 else x+=sizey/2;
  240. 231 2 }
  241. 232 1 }
  242. 233 //显示汉字
  243. 234 //void OLED_ShowChinese(u8 x,u8 y,u8 no,u8 sizey)
  244. 235 //{
  245. 236 // u16 i,size1=(sizey/8+((sizey%8)?1:0))*sizey;
  246. 237 // for(i=0;i<size1;i++)
  247. 238 // {
  248. 239 // if(i%sizey==0) OLED_Set_Pos(x,y++);
  249. 240 // if(sizey==16) OLED_WR_Byte(Hzk[no][i],OLED_DATA);//16x16字号
  250. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 5
  251. 241 //// else if(sizey==xx) OLED_WR_Byte(xxx[c][i],OLED_DATA);//用户添加字号
  252. 242 // else return;
  253. 243 // }
  254. 244 //}
  255. 245
  256. 246
  257. 247 //显示图片
  258. 248 //x,y显示坐标
  259. 249 //sizex,sizey,图片长宽
  260. 250 //BMP:要显示的图片
  261. 251 void OLED_DrawBMP(int x,int y,unsigned char sizex, unsigned char sizey,unsigned char BMP[])
  262. 252 {
  263. 253 1 int j=0;
  264. 254 1 int i,m;
  265. 255 1 sizey=sizey/8+((sizey%8)?1:0);
  266. 256 1 for(i=0;i<sizey;i++)
  267. 257 1 {
  268. 258 2 OLED_Set_Pos(x,i+y);
  269. 259 2 for(m=0;m<sizex;m++)
  270. 260 2 {
  271. 261 3 OLED_WR_Byte(BMP[j++],OLED_DATA);
  272. 262 3 }
  273. 263 2 }
  274. 264 1 }
  275. 265
  276. 266
  277. 267
  278. 268 //初始化
  279. 269 void OLED_Init(void)
  280. 270 {
  281. 271 1 OLED_RES_Clr();
  282. 272 1 delay_ms(200);
  283. 273 1 OLED_RES_Set();
  284. 274 1 delay_ms(200);
  285. 275 1 OLED_WR_Byte(0xAE,OLED_CMD);//--turn off oled panel
  286. 276 1 OLED_WR_Byte(0x00,OLED_CMD);//---set low column address
  287. 277 1 OLED_WR_Byte(0x10,OLED_CMD);//---set high column address
  288. 278 1 OLED_WR_Byte(0x40,OLED_CMD);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
  289. 279 1 OLED_WR_Byte(0x81,OLED_CMD);//--set contrast control register
  290. 280 1 OLED_WR_Byte(0xff,OLED_CMD); // Set SEG Output Current Brightness
  291. 281 1 OLED_WR_Byte(0xA1,OLED_CMD);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常
  292. 282 1 OLED_WR_Byte(0xC8,OLED_CMD);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
  293. 283 1 OLED_WR_Byte(0xA6,OLED_CMD);//--set normal display
  294. 284 1 OLED_WR_Byte(0xA8,OLED_CMD);//--set multiplex ratio(1 to 64)
  295. 285 1 OLED_WR_Byte(0x3f,OLED_CMD);//--1/64 duty
  296. 286 1 OLED_WR_Byte(0xD3,OLED_CMD);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
  297. 287 1 OLED_WR_Byte(0x00,OLED_CMD);//-not offset
  298. 288 1 OLED_WR_Byte(0xd5,OLED_CMD);//--set display clock divide ratio/oscillator frequency
  299. 289 1 OLED_WR_Byte(0x80,OLED_CMD);//--set divide ratio, Set Clock as 100 Frames/Sec
  300. 290 1 OLED_WR_Byte(0xD9,OLED_CMD);//--set pre-charge period
  301. 291 1 OLED_WR_Byte(0xF1,OLED_CMD);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  302. 292 1 OLED_WR_Byte(0xDA,OLED_CMD);//--set com pins hardware configuration
  303. 293 1 OLED_WR_Byte(0x12,OLED_CMD);
  304. 294 1 OLED_WR_Byte(0xDB,OLED_CMD);//--set vcomh
  305. 295 1 OLED_WR_Byte(0x40,OLED_CMD);//Set VCOM Deselect Level
  306. 296 1 OLED_WR_Byte(0x20,OLED_CMD);//-Set Page Addressing Mode (0x00/0x01/0x02)
  307. 297 1 OLED_WR_Byte(0x02,OLED_CMD);//
  308. 298 1 OLED_WR_Byte(0x8D,OLED_CMD);//--set Charge Pump enable/disable
  309. 299 1 OLED_WR_Byte(0x14,OLED_CMD);//--set(0x10) disable
  310. 300 1 OLED_WR_Byte(0xA4,OLED_CMD);// Disable Entire Display On (0xa4/0xa5)
  311. 301 1 OLED_WR_Byte(0xA6,OLED_CMD);// Disable Inverse Display On (0xa6/a7)
  312. 302 1 OLED_Clear();
  313. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 6
  314. 303 1 OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/
  315. 304 1 OLED_Clear();
  316. 305 1 OLED_ColorTurn(0);
  317. 306 1 OLED_DisplayTurn(0);
  318. 307 1 OLED_Display_On();
  319. 308 1 }
  320. 309
  321. 310 void OLED_DrawPixel(unsigned char x, unsigned char y,unsigned char color)
  322. 311 {
  323. 312 1 unsigned char mask;
  324. 313 1 unsigned char *pBuf;
  325. 314 1 if(y%2 == 0)
  326. 315 1 {
  327. 316 2 y++;
  328. 317 2 }
  329. 318 1 if (__x > width)
  330. 319 1 {
  331. 320 2 __x = 0;
  332. 321 2 __y += 1;
  333. 322 2 }
  334. 323 1 if (__y > height * 8)
  335. 324 1 {
  336. 325 2 __y = 0;
  337. 326 2 }
  338. 327 1 pBuf = &_buf[(y >> 3) * width + x];
  339. 328 1 mask = 1 << (y & 7);
  340. 329 1 if (!color)
  341. 330 1 {
  342. 331 2 *pBuf++ &= ~mask;
  343. 332 2 }
  344. 333 1 else
  345. 334 1 {
  346. 335 2 *pBuf++ |= mask;
  347. 336 2 }
  348. 337 1 }
  349. 338
  350. 339 void _swap_char(unsigned char* a,unsigned char* b)
  351. 340 {
  352. 341 1 unsigned char tmp = *a;
  353. 342 1 *a = *b;
  354. 343 1 *b = tmp;
  355. 344 1 }
  356. 345
  357. 346 /*========================================================
  358. 347 *????: ?0.96Oled???
  359. 348 *????: x1 -> ??x1?? y1 -> ??y1??
  360. 349 * x2 -> ??x1?? y2 -> ??y1??
  361. 350 *????: ?
  362. 351 *========================================================*/
  363. 352 void OLED_DrawLine(unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2, unsigned char colo
  364. -r)
  365. 353 {
  366. 354 1 unsigned char i = 0;
  367. 355 1 char DeltaY = 0,DeltaX = 0;
  368. 356 1 float k = 0,b = 0;
  369. 357 1 if(x1>x2)
  370. 358 1 {
  371. 359 2 i = x2;x2 = x1;x1 = i;
  372. 360 2 i = y2;y2 = y1;y1 = i;
  373. 361 2 i = 0;
  374. 362 2 }
  375. 363 1 DeltaY = y2 - y1;
  376. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 7
  377. 364 1 DeltaX = x2 - x1;
  378. 365 1 if(DeltaX == 0)
  379. 366 1 {
  380. 367 2 if(y1<=y2)
  381. 368 2 {
  382. 369 3 for(y1;y1<=y2;y1++)
  383. 370 3 {
  384. 371 4 OLED_DrawPixel(x1,y1,color);
  385. 372 4 }
  386. 373 3 }else if(y1>y2)
  387. 374 2 {
  388. 375 3 for(y2;y2<=y1;y2++)
  389. 376 3 {
  390. 377 4 OLED_DrawPixel(x1,y2,color);
  391. 378 4 }
  392. 379 3 }
  393. 380 2 }
  394. 381 1 else if(DeltaY == 0)
  395. 382 1 {
  396. 383 2 for(x1;x1<=x2;x1++)
  397. 384 2 {
  398. 385 3 OLED_DrawPixel(x1,y1,color);
  399. 386 3 }
  400. 387 2 }
  401. 388 1 else
  402. 389 1 {
  403. 390 2 k = ((float)DeltaY)/((float)DeltaX);
  404. 391 2 b = y2 - k * x2;
  405. 392 2 if((k>-1&k<1))
  406. 393 2 {
  407. 394 3 for(x1;x1<=x2;x1++)
  408. 395 3 {
  409. 396 4 OLED_DrawPixel(x1,(int)(k * x1 + b),color);
  410. 397 4 }
  411. 398 3 }else if((k>=1)|(k<=-1))
  412. 399 2 {
  413. 400 3 if(y1<=y2)
  414. 401 3 {
  415. 402 4 for(y1;y1<=y2;y1++)
  416. 403 4 {
  417. 404 5 OLED_DrawPixel((int)((y1 - b) / k),y1,color);
  418. 405 5 }
  419. 406 4 }else if(y1>y2)
  420. 407 3 {
  421. 408 4 for(y2;y2<=y1;y2++)
  422. 409 4 {
  423. 410 5 OLED_DrawPixel((int)((y2 - b) / k),y2,color);
  424. 411 5 }
  425. 412 4 }
  426. 413 3 }
  427. 414 2 }
  428. 415 1 }
  429. 416
  430. 417 void OLED_display(void)
  431. 418 {
  432. 419 1 OLED_DrawBMP(0,0,128,64,_buf);
  433. 420 1 //OLED_DrawBMP(0,6,width[1],heigth[1]*8,_buf1);
  434. 421 1 }
  435. 422
  436. 423 void OLED_display_clear()
  437. 424 {
  438. 425 1 memset(_buf, 0x00, width * height);
  439. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 8
  440. 426 1 }
  441. 427
  442. 428 void OLED_Draw_Byte(unsigned char *pBuf, unsigned char mask, unsigned char offset, bit reserve_hl)
  443. 429 {
  444. 430 1 if (_OLED_Overlap)
  445. 431 1 {
  446. 432 2 if (_OLED_Reverse)
  447. 433 2 *pBuf |= ~mask;
  448. 434 2 else
  449. 435 2 *pBuf |= mask;
  450. 436 2 }
  451. 437 1 else
  452. 438 1 {
  453. 439 2 if (_OLED_Reverse)
  454. 440 2 {
  455. 441 3 /* 保留高位
  456. 442 3 Reserve upper */
  457. 443 3 if (reserve_hl)
  458. 444 3 {
  459. 445 4 *pBuf &= (~mask) | (0xFF << (8 - offset));
  460. 446 4 *pBuf |= (~mask) & (0xFF >> offset);
  461. 447 4 }
  462. 448 3 /* 保留低位
  463. 449 3 Reserve lower */
  464. 450 3 else
  465. 451 3 {
  466. 452 4 *pBuf &= (~mask) | (0xFF >> (8 - offset));
  467. 453 4 *pBuf |= (~mask) & (0xFF << offset);
  468. 454 4 }
  469. 455 3 }
  470. 456 2 else
  471. 457 2 {
  472. 458 3 /* 保留高位
  473. 459 3 Reserve upper */
  474. 460 3 if (reserve_hl)
  475. 461 3 {
  476. 462 4 *pBuf &= mask | (0xFF << (8 - offset));
  477. 463 4 *pBuf |= mask & (0xFF >> offset);
  478. 464 4 }
  479. 465 3 /* 保留低位
  480. 466 3 Reserve lower */
  481. 467 3 else
  482. 468 3 {
  483. 469 4 *pBuf &= mask | (0xFF >> (8 - offset));
  484. 470 4 *pBuf |= mask & (0xFF << offset);
  485. 471 4 }
  486. 472 3 }
  487. 473 2 }
  488. 474 1 }
  489. 475
  490. 476
  491. 477 void OLED_DrawChar(unsigned char x, unsigned char y, unsigned char chr)
  492. 478 {
  493. 479 1 unsigned char c;
  494. 480 1 unsigned char i;
  495. 481 1 unsigned char mask;
  496. 482 1 unsigned char *pBuf;
  497. 483 1 unsigned char offset;
  498. 484 1 offset = y & 7;
  499. 485 1 c = chr - ' ';
  500. 486 1 pBuf = &_buf[(y >> 3) * width + x];
  501. 487 1
  502. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 9
  503. 488 1 for (i = 0; i < 8; i++)
  504. 489 1 {
  505. 490 2 mask = asc2_1608[c][i] << offset;
  506. 491 2 OLED_Draw_Byte(pBuf++, mask, offset, 0);
  507. 492 2 }
  508. 493 1 if (offset && y < 56 - 8)
  509. 494 1 {
  510. 495 2 pBuf = &_buf[((y >> 3) + 1) * 100 + x];
  511. 496 2 for (i = 0; i < 6; i++)
  512. 497 2 {
  513. 498 3 mask = asc2_0806[c][i] >> (8 - offset);
  514. 499 3 OLED_Draw_Byte(pBuf++, mask, 8 - offset, 1);
  515. 500 3 }
  516. 501 2 }
  517. 502 1 }
  518. 503 void OLED_Set_Posi(unsigned char x, unsigned char y)
  519. 504 {
  520. 505 1 __x = x;
  521. 506 1 __y = y;
  522. 507 1 }
  523. 508
  524. 509 void OLED_DrawNum(unsigned char digit, unsigned char len)
  525. 510 {
  526. 511 1 unsigned char t, i, temp;
  527. 512 1 unsigned char enshow = 0;
  528. 513 1 i = 0;
  529. 514 1 for (t = 0; t < len; t++)
  530. 515 1 {
  531. 516 2 temp = (digit / oled_pow(10, len - t - 1)) % 10;
  532. 517 2
  533. 518 2 if (enshow == 0 && t < (len - 1))
  534. 519 2 {
  535. 520 3 if (temp == 0)
  536. 521 3 {
  537. 522 4 i++;
  538. 523 4 continue;
  539. 524 4 }
  540. 525 3 else
  541. 526 3 enshow = 1;
  542. 527 3 }
  543. 528 2
  544. 529 2 if (__x > 100 - 6)
  545. 530 2 {
  546. 531 3 __x = 0;
  547. 532 3 __y += 8;
  548. 533 3 }
  549. 534 2 if (__y > 56 - 8)
  550. 535 2 {
  551. 536 3 __y = 0;
  552. 537 3 }
  553. 538 2
  554. 539 2 OLED_DrawChar(__x + (6) * (t - i), __y, temp + '0');
  555. 540 2 }
  556. 541 1 __x += len;
  557. 542 1 }
  558. 543
  559. 544 void OLED_DrawBMP_2(u8 x0, u8 page0, u8 xsize, u8 ysize, u8 *BMP)
  560. 545 {
  561. 546 1 u16 i, j;
  562. 547 1 for(j = page0; j < page0+ysize/8; j++)
  563. 548 1 {
  564. 549 2 for(i = x0; i < x0+xsize; i++)
  565. C51 COMPILER V9.54 OLED 09/26/2022 20:11:46 PAGE 10
  566. 550 2 {
  567. 551 3 _buf[i+(j)*width]=BMP[(i-x0)+(j-page0)*xsize];
  568. 552 3 }
  569. 553 2 }
  570. 554 1 }
  571. MODULE INFORMATION: STATIC OVERLAYABLE
  572. CODE SIZE = 3490 ----
  573. CONSTANT SIZE = 2074 ----
  574. XDATA SIZE = 1026 99
  575. PDATA SIZE = ---- ----
  576. DATA SIZE = ---- ----
  577. IDATA SIZE = ---- ----
  578. BIT SIZE = 2 1
  579. END OF MODULE INFORMATION.
  580. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)