找回密码
 立即注册

QQ登录

只需一步,快速开始

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

0.91寸oled屏幕显示例子用于stc15w和stc32g等系列自己研究了三天移植成功分享给大家

[复制链接]
跳转到指定楼层
楼主
ID:1038987 发表于 2023-8-1 21:59 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. //stc32g系列单片机iic通信显示0.91寸显示屏模块
  2. #include "comm\STC32G.h"

  3. //stc32g系列单片机iic通信显示0.91寸显示屏模块1.定义部分占用P15 SCL P14 SDA  设置推挽模式

  4. //1.stc32g系列单片机iic通信显示0.91寸显示屏模块主体往下
  5. #define  u8u8 unsigned char
  6. #define  u16u16 unsigned int
  7. #define  u32u32 unsigned long


  8. #define OLED_CMD  0        //写命令
  9. #define OLED_DATA 1        //写数据

  10. sbit OLED_SCL=P1^5;//SCL
  11. sbit OLED_SDA=P1^4;//SDA
  12. //sbit OLED_RES =P1^2;//RES

  13. //-----------------OLED端口定义----------------

  14. #define OLED_SCL_Clr() OLED_SCL=0
  15. #define OLED_SCL_Set() OLED_SCL=1

  16. #define OLED_SDA_Clr() OLED_SDA=0
  17. #define OLED_SDA_Set() OLED_SDA=1

  18. //#define OLED_RES_Clr() OLED_RES=0
  19. //#define OLED_RES_Set() OLED_RES=1


  20. //OLED控制用函数
  21. void delay_ms(unsigned int ms);
  22. void OLED_ColorTurn(u8u8 oled_i);
  23. void OLED_DisplayTurn(u8u8 oled_i);
  24. void OLED_WR_Byte(u8u8 oled_w_dat,u8u8 cmd);
  25. void OLED_Set_Pos(u8u8 x, u8u8 y);
  26. void OLED_Display_On(void);
  27. void OLED_Display_Off(void);
  28. void OLED_Clear(void);
  29. void OLED_ShowChar(u8u8 x,u8u8 y,u8u8 chr,u8u8 sizey);
  30. u32u32 oled_pow(u8u8 oled_m,u8u8 n);
  31. void OLED_ShowNum(u8u8 x,u8u8 y,u32u32 num,u8u8 len,u8u8 sizey);
  32. void OLED_ShowString(u8u8 x,u8u8 y,u8u8 *chr,u8u8 sizey);
  33. void OLED_ShowChinese(u8u8 x,u8u8 y,u8u8 no,u8u8 sizey);
  34. void OLED_DrawBMP(u8u8 x,u8u8 y,u8u8 sizex, u8u8 sizey,u8u8 BMP[]);
  35. void OLED_Init(void);
  36. unsigned char code BMP1[] =
  37. {
  38.         0x00,0x06,0x0A,0xFE,0x0A,0xC6,0x00,0xE0,0x00,0xF0,0x00,0xF8,0x00,0x00,0x00,0x00,
  39.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  40.         0xFC,0xFC,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  41.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0xF8,0xF0,0xB0,0xB0,0xB0,0xB0,
  42.         0xB0,0xB0,0xB0,0xB0,0xB0,0xB0,0xB0,0xF8,0xF8,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
  43.         0x00,0x00,0x00,0x00,0xF8,0xF8,0x30,0x30,0xB0,0xB0,0xB0,0xB0,0xB0,0xB0,0xB0,0xB0,
  44.         0xB0,0xB0,0xB0,0xB0,0xB0,0x30,0x30,0x30,0xF8,0xF8,0x00,0x00,0x00,0x00,0x78,0x48,
  45.         0xFE,0x82,0xBA,0xBA,0x82,0xBA,0xBA,0x82,0xBA,0xBA,0x82,0xBA,0xBA,0x82,0xFE,0x00,
  46.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  47.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFE,0x06,0x06,0x06,0x06,0x06,0x06,
  48.         0xFF,0xFF,0xFF,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0xFF,0xFF,0xFF,0x00,0x00,0x00,
  49.         0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x6F,0xEF,0xEF,0x67,0x67,0x67,0x67,
  50.         0x7F,0x7F,0x7F,0x67,0x67,0x67,0xE7,0xEF,0xEF,0x6F,0x60,0x60,0x60,0x60,0x00,0x00,
  51.         0x00,0x00,0x00,0x00,0xFF,0xFF,0x30,0x30,0x31,0x31,0x31,0xF1,0xF1,0x31,0x31,0x31,
  52.         0xF1,0xF1,0x31,0x31,0x31,0x30,0x30,0x30,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,
  53.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  54.         0x00,0x24,0xA4,0x2E,0x24,0xE4,0x24,0x2E,0xA4,0x24,0x00,0x00,0x00,0xF8,0x4A,0x4C,
  55.         0x48,0xF8,0x48,0x4C,0x4A,0xF8,0x00,0x1F,0x1F,0x0F,0x06,0x06,0x06,0x06,0x06,0x06,
  56.         0xFF,0xFF,0xFF,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x1F,0x1F,0x1F,0x00,0x00,0x00,
  57.         0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xBF,0xFF,0xF3,0xF3,0x33,0x33,
  58.         0xF3,0xF3,0xF3,0x33,0x33,0xF3,0xFF,0xBF,0xBF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  59.         0x00,0x00,0x00,0x00,0xFF,0xFF,0x00,0x80,0xC0,0xF0,0x7E,0x3F,0x0F,0x00,0x00,0x00,
  60.         0xFF,0xFF,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xFF,0xFF,0x00,0x00,0xC0,0x20,0x10,0x10,
  61.         0x10,0x10,0x20,0xC0,0x00,0x00,0xC0,0x20,0x10,0x10,0x10,0x10,0x20,0xC0,0x00,0x00,
  62.         0x00,0x12,0x0A,0x07,0x02,0x7F,0x02,0x07,0x0A,0x12,0x00,0x00,0x00,0x0B,0x0A,0x0A,
  63.         0x0A,0x7F,0x0A,0x0A,0x0A,0x0B,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  64.         0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65.         0x00,0x00,0x00,0x00,0x18,0x1C,0x0C,0x0E,0x07,0x07,0x03,0x01,0x0D,0x0C,0x1C,0x3C,
  66.         0x3F,0x1F,0x0F,0x00,0x00,0x00,0x01,0x03,0x03,0x07,0x0F,0x1E,0x1E,0x00,0x00,0x00,
  67.         0x00,0x00,0x00,0x00,0x1F,0x1F,0x0F,0x0F,0x0D,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,
  68.         0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1F,0x1F,0x00,0x00,0x1F,0x20,0x40,0x40,
  69.         0x40,0x50,0x20,0x5F,0x80,0x00,0x1F,0x20,0x40,0x40,0x40,0x50,0x20,0x5F,0x80,0x00,
  70. };





  71. /************************************6*8的点阵************************************/
  72. unsigned char code asc2_0806[][6] ={
  73. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},// sp
  74. {0x00, 0x00, 0x00, 0x2f, 0x00, 0x00},// !
  75. {0x00, 0x00, 0x07, 0x00, 0x07, 0x00},// "
  76. {0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14},// #
  77. {0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12},// $
  78. {0x00, 0x62, 0x64, 0x08, 0x13, 0x23},// %
  79. {0x00, 0x36, 0x49, 0x55, 0x22, 0x50},// &
  80. {0x00, 0x00, 0x05, 0x03, 0x00, 0x00},// '
  81. {0x00, 0x00, 0x1c, 0x22, 0x41, 0x00},// (
  82. {0x00, 0x00, 0x41, 0x22, 0x1c, 0x00},// )
  83. {0x00, 0x14, 0x08, 0x3E, 0x08, 0x14},// *
  84. {0x00, 0x08, 0x08, 0x3E, 0x08, 0x08},// +
  85. {0x00, 0x00, 0x00, 0xA0, 0x60, 0x00},// ,
  86. {0x00, 0x08, 0x08, 0x08, 0x08, 0x08},// -
  87. {0x00, 0x00, 0x60, 0x60, 0x00, 0x00},// .
  88. {0x00, 0x20, 0x10, 0x08, 0x04, 0x02},// /
  89. {0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E},// 0
  90. {0x00, 0x00, 0x42, 0x7F, 0x40, 0x00},// 1
  91. {0x00, 0x42, 0x61, 0x51, 0x49, 0x46},// 2
  92. {0x00, 0x21, 0x41, 0x45, 0x4B, 0x31},// 3
  93. {0x00, 0x18, 0x14, 0x12, 0x7F, 0x10},// 4
  94. {0x00, 0x27, 0x45, 0x45, 0x45, 0x39},// 5
  95. {0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30},// 6
  96. {0x00, 0x01, 0x71, 0x09, 0x05, 0x03},// 7
  97. {0x00, 0x36, 0x49, 0x49, 0x49, 0x36},// 8
  98. {0x00, 0x06, 0x49, 0x49, 0x29, 0x1E},// 9
  99. {0x00, 0x00, 0x36, 0x36, 0x00, 0x00},// :
  100. {0x00, 0x00, 0x56, 0x36, 0x00, 0x00},// ;
  101. {0x00, 0x08, 0x14, 0x22, 0x41, 0x00},// <
  102. {0x00, 0x14, 0x14, 0x14, 0x14, 0x14},// =
  103. {0x00, 0x00, 0x41, 0x22, 0x14, 0x08},// >
  104. {0x00, 0x02, 0x01, 0x51, 0x09, 0x06},// ?
  105. {0x00, 0x32, 0x49, 0x59, 0x51, 0x3E},// @
  106. {0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C},// A
  107. {0x00, 0x7F, 0x49, 0x49, 0x49, 0x36},// B
  108. {0x00, 0x3E, 0x41, 0x41, 0x41, 0x22},// C
  109. {0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C},// D
  110. {0x00, 0x7F, 0x49, 0x49, 0x49, 0x41},// E
  111. {0x00, 0x7F, 0x09, 0x09, 0x09, 0x01},// F
  112. {0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A},// G
  113. {0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F},// H
  114. {0x00, 0x00, 0x41, 0x7F, 0x41, 0x00},// I
  115. {0x00, 0x20, 0x40, 0x41, 0x3F, 0x01},// J
  116. {0x00, 0x7F, 0x08, 0x14, 0x22, 0x41},// K
  117. {0x00, 0x7F, 0x40, 0x40, 0x40, 0x40},// L
  118. {0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F},// M
  119. {0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F},// N
  120. {0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E},// O
  121. {0x00, 0x7F, 0x09, 0x09, 0x09, 0x06},// P
  122. {0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E},// Q
  123. {0x00, 0x7F, 0x09, 0x19, 0x29, 0x46},// R
  124. {0x00, 0x46, 0x49, 0x49, 0x49, 0x31},// S
  125. {0x00, 0x01, 0x01, 0x7F, 0x01, 0x01},// T
  126. {0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F},// U
  127. {0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F},// V
  128. {0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F},// W
  129. {0x00, 0x63, 0x14, 0x08, 0x14, 0x63},// X
  130. {0x00, 0x07, 0x08, 0x70, 0x08, 0x07},// Y
  131. {0x00, 0x61, 0x51, 0x49, 0x45, 0x43},// Z
  132. {0x00, 0x00, 0x7F, 0x41, 0x41, 0x00},// [
  133. {0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55},// 55
  134. {0x00, 0x00, 0x41, 0x41, 0x7F, 0x00},// ]
  135. {0x00, 0x04, 0x02, 0x01, 0x02, 0x04},// ^
  136. {0x00, 0x40, 0x40, 0x40, 0x40, 0x40},// _
  137. {0x00, 0x00, 0x01, 0x02, 0x04, 0x00},// '
  138. {0x00, 0x20, 0x54, 0x54, 0x54, 0x78},// a
  139. {0x00, 0x7F, 0x48, 0x44, 0x44, 0x38},// b
  140. {0x00, 0x38, 0x44, 0x44, 0x44, 0x20},// c
  141. {0x00, 0x38, 0x44, 0x44, 0x48, 0x7F},// d
  142. {0x00, 0x38, 0x54, 0x54, 0x54, 0x18},// e
  143. {0x00, 0x08, 0x7E, 0x09, 0x01, 0x02},// f
  144. {0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C},// g
  145. {0x00, 0x7F, 0x08, 0x04, 0x04, 0x78},// h
  146. {0x00, 0x00, 0x44, 0x7D, 0x40, 0x00},// i
  147. {0x00, 0x40, 0x80, 0x84, 0x7D, 0x00},// j
  148. {0x00, 0x7F, 0x10, 0x28, 0x44, 0x00},// k
  149. {0x00, 0x00, 0x41, 0x7F, 0x40, 0x00},// l
  150. {0x00, 0x7C, 0x04, 0x18, 0x04, 0x78},// m
  151. {0x00, 0x7C, 0x08, 0x04, 0x04, 0x78},// n
  152. {0x00, 0x38, 0x44, 0x44, 0x44, 0x38},// o
  153. {0x00, 0xFC, 0x24, 0x24, 0x24, 0x18},// p
  154. {0x00, 0x18, 0x24, 0x24, 0x18, 0xFC},// q
  155. {0x00, 0x7C, 0x08, 0x04, 0x04, 0x08},// r
  156. {0x00, 0x48, 0x54, 0x54, 0x54, 0x20},// s
  157. {0x00, 0x04, 0x3F, 0x44, 0x40, 0x20},// t
  158. {0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C},// u
  159. {0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C},// v
  160. {0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C},// w
  161. {0x00, 0x44, 0x28, 0x10, 0x28, 0x44},// x
  162. {0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C},// y
  163. {0x00, 0x44, 0x64, 0x54, 0x4C, 0x44},// z
  164. {0x14, 0x14, 0x14, 0x14, 0x14, 0x14},// horiz lines

  165. };


  166. //16*16 ASCII字符集点阵
  167. unsigned char code asc2_1608[][16]={         
  168. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
  169. {0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00},/*"!",1*/
  170. {0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/
  171. {0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00},/*"#",3*/
  172. {0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00},/*"[        DISCUZ_CODE_0        ]quot;,4*/
  173. {0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00},/*"%",5*/
  174. {0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10},/*"&",6*/
  175. {0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
  176. {0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00},/*"(",8*/
  177. {0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00},/*")",9*/
  178. {0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00},/*"*",10*/
  179. {0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00},/*"+",11*/
  180. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00},/*",",12*/
  181. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01},/*"-",13*/
  182. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00},/*".",14*/
  183. {0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},/*"/",15*/
  184. {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00},/*"0",16*/
  185. {0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"1",17*/
  186. {0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00},/*"2",18*/
  187. {0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00},/*"3",19*/
  188. {0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00},/*"4",20*/
  189. {0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00},/*"5",21*/
  190. {0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"6",22*/
  191. {0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00},/*"7",23*/
  192. {0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00},/*"8",24*/
  193. {0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00},/*"9",25*/
  194. {0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00},/*":",26*/
  195. {0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00},/*";",27*/
  196. {0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00},/*"<",28*/
  197. {0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00},/*"=",29*/
  198. {0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00},/*">",30*/
  199. {0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00},/*"?",31*/
  200. {0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00},/*"@",32*/
  201. {0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20},/*"A",33*/
  202. {0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00},/*"B",34*/
  203. {0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00},/*"C",35*/
  204. {0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00},/*"D",36*/
  205. {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00},/*"E",37*/
  206. {0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00},/*"F",38*/
  207. {0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00},/*"G",39*/
  208. {0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20},/*"H",40*/
  209. {0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"I",41*/
  210. {0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00},/*"J",42*/
  211. {0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00},/*"K",43*/
  212. {0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00},/*"L",44*/
  213. {0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00},/*"M",45*/
  214. {0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00},/*"N",46*/
  215. {0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00},/*"O",47*/
  216. {0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00},/*"P",48*/
  217. {0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00},/*"Q",49*/
  218. {0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20},/*"R",50*/
  219. {0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00},/*"S",51*/
  220. {0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00},/*"T",52*/
  221. {0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},/*"U",53*/
  222. {0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00},/*"V",54*/
  223. {0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00},/*"W",55*/
  224. {0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20},/*"X",56*/
  225. {0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00},/*"Y",57*/
  226. {0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00},/*"Z",58*/
  227. {0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00},/*"[",59*/
  228. {0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00},/*"\",60*/
  229. {0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00},/*"]",61*/
  230. {0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/
  231. {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80},/*"_",63*/
  232. {0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"`",64*/
  233. {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20},/*"a",65*/
  234. {0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00},/*"b",66*/
  235. {0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00},/*"c",67*/
  236. {0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20},/*"d",68*/
  237. {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00},/*"e",69*/
  238. {0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"f",70*/
  239. {0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00},/*"g",71*/
  240. {0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20},/*"h",72*/
  241. {0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"i",73*/
  242. {0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00},/*"j",74*/
  243. {0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00},/*"k",75*/
  244. {0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00},/*"l",76*/
  245. {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F},/*"m",77*/
  246. {0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20},/*"n",78*/
  247. {0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},/*"o",79*/
  248. {0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00},/*"p",80*/
  249. {0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80},/*"q",81*/
  250. {0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00},/*"r",82*/
  251. {0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00},/*"s",83*/
  252. {0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00},/*"t",84*/
  253. {0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20},/*"u",85*/
  254. {0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00},/*"v",86*/
  255. {0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00},/*"w",87*/
  256. {0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00},/*"x",88*/
  257. {0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00},/*"y",89*/
  258. {0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00},/*"z",90*/
  259. {0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40},/*"{",91*/
  260. {0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00},/*"|",92*/
  261. {0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00},/*"}",93*/
  262. {0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/
  263. };  
  264. unsigned char code Hzk[][32]={
  265. {0x00,0x00,0xF0,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00,0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0xFF,0x04,0x04,0x04,0x04,0x0F,0x00,0x00,0x00},/*"中",0*/
  266. {0x40,0x40,0x40,0x5F,0x55,0x55,0x55,0x75,0x55,0x55,0x55,0x5F,0x40,0x40,0x40,0x00,0x00,0x40,0x20,0x0F,0x09,0x49,0x89,0x79,0x09,0x09,0x09,0x0F,0x20,0x40,0x00,0x00},/*"景",1*/
  267. {0x00,0xFE,0x02,0x42,0x4A,0xCA,0x4A,0x4A,0xCA,0x4A,0x4A,0x42,0x02,0xFE,0x00,0x00,0x00,0xFF,0x40,0x50,0x4C,0x43,0x40,0x40,0x4F,0x50,0x50,0x5C,0x40,0xFF,0x00,0x00},/*"园",2*/
  268. {0x00,0x00,0xF8,0x88,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x08,0x7F,0x88,0x88,0x88,0x88,0x9F,0x80,0xF0,0x00},/*"电",3*/
  269. {0x80,0x82,0x82,0x82,0x82,0x82,0x82,0xE2,0xA2,0x92,0x8A,0x86,0x82,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"子",4*/
  270. {0x10,0x10,0x10,0xFF,0x10,0x90,0x08,0x88,0x88,0x88,0xFF,0x88,0x88,0x88,0x08,0x00,0x04,0x44,0x82,0x7F,0x01,0x80,0x80,0x40,0x43,0x2C,0x10,0x28,0x46,0x81,0x80,0x00},/*"技",5*/
  271. {0x00,0x10,0x10,0x10,0x10,0xD0,0x30,0xFF,0x30,0xD0,0x12,0x1C,0x10,0x10,0x00,0x00,0x10,0x08,0x04,0x02,0x01,0x00,0x00,0xFF,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x00},/*"术",6*/

  272. };
  273. //OLED的显存
  274. //存放格式如下.
  275. //[0]0 1 2 3 ... 127        
  276. //[1]0 1 2 3 ... 127        
  277. //[2]0 1 2 3 ... 127        
  278. //[3]0 1 2 3 ... 127        
  279. //[4]0 1 2 3 ... 127        
  280. //[5]0 1 2 3 ... 127        
  281. //[6]0 1 2 3 ... 127        
  282. //[7]0 1 2 3 ... 127                           
  283. void delay_ms(unsigned int ms)
  284. {                        
  285.         unsigned int oled_a;
  286.         while(ms)
  287.         {
  288.                 oled_a=1800;
  289.                 while(oled_a--);
  290.                 ms--;
  291.         }
  292.         return;
  293. }

  294. //反显函数
  295. void OLED_ColorTurn(u8u8 oled_i)
  296. {
  297.         if(oled_i==0)
  298.                 {
  299.                         OLED_WR_Byte(0xA6,OLED_CMD);//正常显示
  300.                 }
  301.         if(oled_i==1)
  302.                 {
  303.                         OLED_WR_Byte(0xA7,OLED_CMD);//反色显示
  304.                 }
  305. }

  306. //屏幕旋转180度
  307. void OLED_DisplayTurn(u8u8 oled_i)
  308. {
  309.         if(oled_i==0)
  310.                 {
  311.                         OLED_WR_Byte(0xC8,OLED_CMD);//正常显示
  312.                         OLED_WR_Byte(0xA1,OLED_CMD);
  313.                 }
  314.         if(oled_i==1)
  315.                 {
  316.                         OLED_WR_Byte(0xC0,OLED_CMD);//反转显示
  317.                         OLED_WR_Byte(0xA0,OLED_CMD);
  318.                 }
  319. }


  320. //延时
  321. void IIC_delay(void)
  322. {
  323.         u8u8 t=1;
  324.         while(t--);
  325. }

  326. //起始信号
  327. void I2C_Start(void)
  328. {
  329.         OLED_SDA_Set();
  330.         OLED_SCL_Set();
  331.         IIC_delay();
  332.         OLED_SDA_Clr();
  333.         IIC_delay();
  334.         OLED_SCL_Clr();
  335.          
  336. }

  337. //结束信号
  338. void I2C_Stop(void)
  339. {
  340.         OLED_SDA_Clr();
  341.         OLED_SCL_Set();
  342.         IIC_delay();
  343.         OLED_SDA_Set();
  344. }

  345. //等待信号响应
  346. void I2C_WaitAck(void) //测数据信号的电平
  347. {
  348.         OLED_SDA_Set();
  349.         IIC_delay();
  350.         OLED_SCL_Set();
  351.         IIC_delay();
  352.         OLED_SCL_Clr();
  353.         IIC_delay();
  354. }

  355. //写入一个字节
  356. void Send_Byte(u8u8 oled_w_dat)
  357. {
  358.         u8u8 oled_i;
  359.         for(oled_i=0;oled_i<8;oled_i++)
  360.         {
  361.                 OLED_SCL_Clr();//将时钟信号设置为低电平
  362.                 if(oled_w_dat&0x80)//将dat的8位从最高位依次写入
  363.                 {
  364.                         OLED_SDA_Set();
  365.     }
  366.                 else
  367.                 {
  368.                         OLED_SDA_Clr();
  369.     }
  370.                 IIC_delay();
  371.                 OLED_SCL_Set();
  372.                 IIC_delay();
  373.                 OLED_SCL_Clr();
  374.                 oled_w_dat<<=1;
  375.   }
  376. }

  377. //发送一个字节
  378. //向SSD1306写入一个字节。
  379. //mode:数据/命令标志 0,表示命令;1,表示数据;
  380. void OLED_WR_Byte(u8u8 oled_w_dat,u8u8 mode)
  381. {
  382.         I2C_Start();
  383.         Send_Byte(0x78);
  384.         I2C_WaitAck();
  385.         if(mode){Send_Byte(0x40);}
  386.   else{Send_Byte(0x00);}
  387.         I2C_WaitAck();
  388.         Send_Byte(oled_w_dat);
  389.         I2C_WaitAck();
  390.         I2C_Stop();
  391. }

  392. //坐标设置

  393. void OLED_Set_Pos(u8u8 x, u8u8 y)
  394. {
  395.         OLED_WR_Byte(0xb0+y,OLED_CMD);
  396.         OLED_WR_Byte(((x&0xf0)>>4)|0x10,OLED_CMD);
  397.         OLED_WR_Byte((x&0x0f),OLED_CMD);
  398. }            
  399. //开启OLED显示   
  400. void OLED_Display_On(void)
  401. {
  402.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  403.         OLED_WR_Byte(0X14,OLED_CMD);  //DCDC ON
  404.         OLED_WR_Byte(0XAF,OLED_CMD);  //DISPLAY ON
  405. }
  406. //关闭OLED显示     
  407. void OLED_Display_Off(void)
  408. {
  409.         OLED_WR_Byte(0X8D,OLED_CMD);  //SET DCDC命令
  410.         OLED_WR_Byte(0X10,OLED_CMD);  //DCDC OFF
  411.         OLED_WR_Byte(0XAE,OLED_CMD);  //DISPLAY OFF
  412. }                                            
  413. //清屏函数,清完屏,整个屏幕是黑色的!和没点亮一样!!!         
  414. void OLED_Clear(void)  
  415. {  
  416.         u8u8 oled_i,oled_n;                    
  417.         for(oled_i=0;oled_i<4;oled_i++)  
  418.         {  
  419.                 OLED_WR_Byte (0xb0+oled_i,OLED_CMD);    //设置页地址(0~7)
  420.                 OLED_WR_Byte (0x00,OLED_CMD);      //设置显示位置—列低地址
  421.                 OLED_WR_Byte (0x10,OLED_CMD);      //设置显示位置—列高地址   
  422.                 for(oled_n=0;oled_n<128;oled_n++)OLED_WR_Byte(0,OLED_DATA);
  423.         } //更新显示
  424. }

  425. //在指定位置显示一个字符,包括部分字符
  426. //x:0~127
  427. //y:0~63                                 
  428. //sizey:选择字体 6x8  8x16
  429. void OLED_ShowChar(u8u8 x,u8u8 y,u8u8 chr,u8u8 sizey)
  430. {              
  431.         u8u8 c=0,sizex=sizey/2;
  432.         u16u16 oled_i=0,size1;
  433.         if(sizey==8)size1=6;
  434.         else size1=(sizey/8+((sizey%8)?1:0))*(sizey/2);
  435.         c=chr-' ';//得到偏移后的值
  436.         OLED_Set_Pos(x,y);
  437.         for(oled_i=0;oled_i<size1;oled_i++)
  438.         {
  439.                 if(oled_i%sizex==0&&sizey!=8) OLED_Set_Pos(x,y++);
  440.                 if(sizey==8) OLED_WR_Byte(asc2_0806[c][oled_i],OLED_DATA);//6X8字号
  441.                 else if(sizey==16) OLED_WR_Byte(asc2_1608[c][oled_i],OLED_DATA);//8x16字号
  442. //                else if(sizey==xx) OLED_WR_Byte(asc2_xxxx[c][i],OLED_DATA);//用户添加字号
  443.                 else return;
  444.         }
  445. }
  446. //m^n函数
  447. u32u32 oled_pow(u8u8 oled_m,u8u8 oled_n)
  448. {
  449.         u32u32 result=1;         
  450.         while(oled_n--)result*=oled_m;   
  451.         return result;
  452. }                                 
  453. //显示数字
  454. //x,y :起点坐标
  455. //num:要显示的数字
  456. //len :数字的位数
  457. //sizey:字体大小                          OLED_ShowNum(80,2,55,3,24);
  458. void OLED_ShowNum(u8u8 x,u8u8 y,u32u32 num,u8u8 len,u8u8 sizey)
  459. {                 
  460.         u8u8 t,temp,oled_m=0;
  461.         u8u8 enshow=0;
  462.         if(sizey==8)oled_m=2;
  463.         for(t=0;t<len;t++)
  464.         {
  465.                 temp=(num/oled_pow(10,len-t-1))%10;
  466.                 if(enshow==0&&t<(len-1))
  467.                 {
  468.                         if(temp==0)
  469.                         {
  470.                                 OLED_ShowChar(x+(sizey/2+oled_m)*t,y,' ',sizey);
  471.                                 continue;
  472.                         }else enshow=1;
  473.                 }
  474.                  OLED_ShowChar(x+(sizey/2+oled_m)*t,y,temp+'0',sizey);
  475.         }
  476. }
  477. //显示一个字符号串
  478. void OLED_ShowString(u8u8 x,u8u8 y,u8u8 *chr,u8u8 sizey)
  479. {
  480.         u8u8 oled_j=0;
  481.         while (chr[oled_j]!='\0')
  482.         {               
  483.                 OLED_ShowChar(x,y,chr[oled_j++],sizey);
  484.                 if(sizey==8)x+=6;
  485.                 else x+=sizey/2;
  486.         }
  487. }
  488. //显示汉字
  489. void OLED_ShowChinese(u8u8 x,u8u8 y,u8u8 no,u8u8 sizey)
  490. {
  491.         u16u16 oled_i,size1=(sizey/8+((sizey%8)?1:0))*sizey;
  492.         for(oled_i=0;oled_i<size1;oled_i++)
  493.         {
  494.                 if(oled_i%sizey==0) OLED_Set_Pos(x,y++);
  495.                 if(sizey==16) OLED_WR_Byte(Hzk[no][oled_i],OLED_DATA);//16x16字号
  496. //                else if(sizey==xx) OLED_WR_Byte(xxx[c][i],OLED_DATA);//用户添加字号
  497.                 else return;
  498.         }                                
  499. }


  500. //显示图片
  501. //x,y显示坐标
  502. //sizex,sizey,图片长宽
  503. //BMP:要显示的图片
  504. void OLED_DrawBMP(u8u8 x,u8u8 y,u8u8 sizex, u8u8 sizey,u8u8 BMP[])
  505. {         
  506.   u16u16 oled_j=0;
  507.         u8u8 oled_i,oled_m;
  508.         sizey=sizey/8+((sizey%8)?1:0);
  509.         for(oled_i=0;oled_i<sizey;oled_i++)
  510.         {
  511.                 OLED_Set_Pos(x,oled_i+y);
  512.     for(oled_m=0;oled_m<sizex;oled_m++)
  513.                 {      
  514.                         OLED_WR_Byte(BMP[oled_j++],OLED_DATA);                    
  515.                 }
  516.         }
  517. }



  518. //初始化                                    
  519. void OLED_Init(void)
  520. {
  521. //        OLED_RES_Clr();
  522.   delay_ms(200);
  523. //        OLED_RES_Set();
  524.         
  525.         OLED_WR_Byte(0xAE,OLED_CMD); /*display off*/
  526.         OLED_WR_Byte(0x00,OLED_CMD); /*set lower column address*/
  527.         OLED_WR_Byte(0x10,OLED_CMD); /*set higher column address*/
  528.         OLED_WR_Byte(0x00,OLED_CMD); /*set display start line*/
  529.         OLED_WR_Byte(0xB0,OLED_CMD); /*set page address*/
  530.         OLED_WR_Byte(0x81,OLED_CMD); /*contract control*/
  531.         OLED_WR_Byte(0xff,OLED_CMD); /*128*/
  532.         OLED_WR_Byte(0xA1,OLED_CMD); /*set segment remap*/
  533.         OLED_WR_Byte(0xA6,OLED_CMD); /*normal / reverse*/
  534.         OLED_WR_Byte(0xA8,OLED_CMD); /*multiplex ratio*/
  535.         OLED_WR_Byte(0x1F,OLED_CMD); /*duty = 1/32*/
  536.         OLED_WR_Byte(0xC8,OLED_CMD); /*Com scan direction*/
  537.         OLED_WR_Byte(0xD3,OLED_CMD); /*set display offset*/
  538.         OLED_WR_Byte(0x00,OLED_CMD);
  539.         OLED_WR_Byte(0xD5,OLED_CMD); /*set osc division*/
  540.         OLED_WR_Byte(0x80,OLED_CMD);
  541.         OLED_WR_Byte(0xD9,OLED_CMD); /*set pre-charge period*/
  542.         OLED_WR_Byte(0x1f,OLED_CMD);
  543.         OLED_WR_Byte(0xDA,OLED_CMD); /*set COM pins*/
  544.         OLED_WR_Byte(0x00,OLED_CMD);
  545.         OLED_WR_Byte(0xdb,OLED_CMD); /*set vcomh*/
  546.         OLED_WR_Byte(0x40,OLED_CMD);
  547.         OLED_WR_Byte(0x8d,OLED_CMD); /*set charge pump enable*/
  548.         OLED_WR_Byte(0x14,OLED_CMD);
  549.         OLED_Clear();
  550.         OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/
  551. }
  552. //1.stc32g系列单片机iic通信显示0.91寸显示屏模块主体往上


  553. //2.stc32g系列单片机iic通信显示0.91寸显示屏模块 main部分
  554. /*
  555. u8u8 t=' ';
  556.         
  557.           WTST = 0;  //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快
  558.     EAXFR = 1; //扩展寄存器(XFR)访问使能
  559.     CKCON = 0; //提高访问XRAM速度
  560.                 P1M1 = 0x00;   P1M0 = 0xff;   //设置为准双向口202209改为推挽
  561.         
  562.         OLED_Init();//初始化OLED
  563.         OLED_ColorTurn(0);//0正常显示,1 反色显示
  564.   OLED_DisplayTurn(0);//0正常显示 1 屏幕翻转显示        
  565. */
  566. //2.stc32g系列单片机iic通信显示0.91寸显示屏模块 main部分


  567. //3.stc32g系列单片机iic通信显示0.91寸显示屏模块 while例子部分
  568. /*
  569. OLED_DrawBMP(0,0,128,32,BMP1);
  570.                 delay_ms(500);
  571.                 OLED_Clear();
  572.                 OLED_ShowChinese(0,0,0,16);//中
  573.                 OLED_ShowChinese(18,0,1,16);//景
  574.                 OLED_ShowChinese(36,0,2,16);//园
  575.                 OLED_ShowChinese(54,0,3,16);//电
  576.                 OLED_ShowChinese(72,0,4,16);//子
  577.                 OLED_ShowChinese(90,0,5,16);//科
  578.                 OLED_ShowChinese(108,0,6,16);//技
  579.                 OLED_ShowString(8,2,"ZHONGJINGYUAN",16);
  580.                 delay_ms(500);
  581.                 OLED_Clear();
  582.                 OLED_ShowString(20,0,"2014/05/01",16);
  583.                 OLED_ShowString(0,2,"ASCII:",16);  
  584.                 OLED_ShowString(63,2,"CODE:",16);
  585.                 OLED_ShowChar(48,2,t,16);//显示ASCII字符           
  586.                 t++;
  587.                 if(t>'~')t=' ';
  588.                 OLED_ShowNum(103,2,t,3,16);
  589.                 delay_ms(500);
  590.                 OLED_Clear();
  591. */
  592. //3.stc32g系列单片机iic通信显示0.91寸显示屏模块 while例子部分



















  593. int main(void)
  594. {        u8u8 t=' ';
  595.         
  596.           WTST = 0;  //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快
  597.     EAXFR = 1; //扩展寄存器(XFR)访问使能
  598.     CKCON = 0; //提高访问XRAM速度
  599.                 P1M1 = 0x00;   P1M0 = 0xff;   //设置为准双向口202209改为推挽
  600.         
  601.         OLED_Init();//初始化OLED
  602.         OLED_ColorTurn(0);//0正常显示,1 反色显示
  603.   OLED_DisplayTurn(0);//0正常显示 1 屏幕翻转显示        
  604.         

  605.         OLED_Clear();

  606.         while(1)
  607.         {               
  608.                
  609.                
  610.          

  611.                 //显示数字
  612. //x,y :起点坐标
  613. //num:要显示的数字
  614. //len :数字的位数
  615. //sizey:字体大小                          
  616.                 OLED_ShowNum(8,2,1503,4,16);
  617. OLED_ShowNum(40,2,1773,4,16);
  618.                 OLED_ShowNum(72,2,670,3,16);
  619.         }         
  620.         
  621. }
复制代码

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏3 分享淘帖 顶 踩
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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