新聞中心

IIC OLED驅(qū)動

作者: 時間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
  1. /*
  2. 文 件 名 : oled.c
  3. 版 本 號 : v1.0
  4. 最近修改 :
  5. 功能描述 : LED128x64OLED顯示屏底層驅(qū)動
  6. 修改歷史 :
  7. ******************************************************************************/
  8. /*----------------------------------------------------------------------------*
  9. * 包含頭文件 *
  10. *----------------------------------------------------------------------------*/
  11. #include
  12. #include"oled.h"
  13. /*----------------------------------------------------------------------------*
  14. * 宏定義 *
  15. *----------------------------------------------------------------------------*/
  16. /*----------------------------------------------------------------------------*
  17. * 全局變量 *
  18. *----------------------------------------------------------------------------*/
  19. sbit LED_SCL=P1^0;
  20. sbit LED_SDA=P1^1;
  21. sbit LED_RST=P1^2;
  22. sbit LED_DC=P1^3;
  23. constUCHAR8 code F6x8[][6]=
  24. {
  25. {0x00,0x00,0x00,0x00,0x00,0x00},//sp0
  26. {0x00,0x00,0x00,0x2f,0x00,0x00},// !1
  27. {0x00,0x00,0x07,0x00,0x07,0x00},// "2
  28. {0x00,0x14,0x7f,0x14,0x7f,0x14},// #3
  29. {0x00,0x24,0x2a,0x7f,0x2a,0x12},// $4
  30. {0x00,0x62,0x64,0x08,0x13,0x23},// %5
  31. {0x00,0x36,0x49,0x55,0x22,0x50},// &6
  32. {0x00,0x00,0x05,0x03,0x00,0x00},// 7
  33. {0x00,0x00,0x1c,0x22,0x41,0x00},// (8
  34. {0x00,0x00,0x41,0x22,0x1c,0x00},// )9
  35. {0x00,0x14,0x08,0x3E,0x08,0x14},// *10
  36. {0x00,0x08,0x08,0x3E,0x08,0x08},// +11
  37. {0x00,0x00,0x00,0xA0,0x60,0x00},// ,12
  38. {0x00,0x08,0x08,0x08,0x08,0x08},// -13
  39. {0x00,0x00,0x60,0x60,0x00,0x00},// .14
  40. {0x00,0x20,0x10,0x08,0x04,0x02},// /15
  41. {0x00,0x3E,0x51,0x49,0x45,0x3E},// 016
  42. {0x00,0x00,0x42,0x7F,0x40,0x00},// 117
  43. {0x00,0x42,0x61,0x51,0x49,0x46},// 218
  44. {0x00,0x21,0x41,0x45,0x4B,0x31},// 319
  45. {0x00,0x18,0x14,0x12,0x7F,0x10},// 420
  46. {0x00,0x27,0x45,0x45,0x45,0x39},// 521
  47. {0x00,0x3C,0x4A,0x49,0x49,0x30},// 622
  48. {0x00,0x01,0x71,0x09,0x05,0x03},// 723
  49. {0x00,0x36,0x49,0x49,0x49,0x36},// 824
  50. {0x00,0x06,0x49,0x49,0x29,0x1E},// 925
  51. {0x00,0x00,0x36,0x36,0x00,0x00},// :26
  52. {0x00,0x00,0x56,0x36,0x00,0x00},// ;27
  53. {0x00,0x08,0x14,0x22,0x41,0x00},// <28
  54. {0x00,0x14,0x14,0x14,0x14,0x14},// =29
  55. {0x00,0x00,0x41,0x22,0x14,0x08},// >30
  56. {0x00,0x02,0x01,0x51,0x09,0x06},// ?31
  57. {0x00,0x32,0x49,0x59,0x51,0x3E},// @32
  58. {0x00,0x7C,0x12,0x11,0x12,0x7C},// A33
  59. {0x00,0x7F,0x49,0x49,0x49,0x36},// B34
  60. {0x00,0x3E,0x41,0x41,0x41,0x22},// C35
  61. {0x00,0x7F,0x41,0x41,0x22,0x1C},// D36
  62. {0x00,0x7F,0x49,0x49,0x49,0x41},// E37
  63. {0x00,0x7F,0x09,0x09,0x09,0x01},// F38
  64. {0x00,0x3E,0x41,0x49,0x49,0x7A},// G39
  65. {0x00,0x7F,0x08,0x08,0x08,0x7F},// H40
  66. {0x00,0x00,0x41,0x7F,0x41,0x00},// I41
  67. {0x00,0x20,0x40,0x41,0x3F,0x01},// J42
  68. {0x00,0x7F,0x08,0x14,0x22,0x41},// K43
  69. {0x00,0x7F,0x40,0x40,0x40,0x40},// L44
  70. {0x00,0x7F,0x02,0x0C,0x02,0x7F},// M45
  71. {0x00,0x7F,0x04,0x08,0x10,0x7F},// N46
  72. {0x00,0x3E,0x41,0x41,0x41,0x3E},// O47
  73. {0x00,0x7F,0x09,0x09,0x09,0x06},// P48
  74. {0x00,0x3E,0x41,0x51,0x21,0x5E},// Q49
  75. {0x00,0x7F,0x09,0x19,0x29,0x46},// R50
  76. {0x00,0x46,0x49,0x49,0x49,0x31},// S51
  77. {0x00,0x01,0x01,0x7F,0x01,0x01},// T52
  78. {0x00,0x3F,0x40,0x40,0x40,0x3F},// U53
  79. {0x00,0x1F,0x20,0x40,0x20,0x1F},// V54
  80. {0x00,0x3F,0x40,0x38,0x40,0x3F},// W55
  81. {0x00,0x63,0x14,0x08,0x14,0x63},// X56
  82. {0x00,0x07,0x08,0x70,0x08,0x07},// Y57
  83. {0x00,0x61,0x51,0x49,0x45,0x43},// Z58
  84. {0x00,0x00,0x7F,0x41,0x41,0x00},// [59
  85. {0x00,0x02,0x04,0x08,0x10,0x20},// 60
  86. {0x00,0x00,0x41,0x41,0x7F,0x00},// ]61
  87. {0x00,0x04,0x02,0x01,0x02,0x04},// ^62
  88. {0x00,0x40,0x40,0x40,0x40,0x40},// _63
  89. {0x00,0x00,0x01,0x02,0x04,0x00},// 64
  90. {0x00,0x20,0x54,0x54,0x54,0x78},// a65
  91. {0x00,0x7F,0x48,0x44,0x44,0x38},// b66
  92. {0x00,0x38,0x44,0x44,0x44,0x20},// c67
  93. {0x00,0x38,0x44,0x44,0x48,0x7F},// d68
  94. {0x00,0x38,0x54,0x54,0x54,0x18},// e69
  95. {0x00,0x08,0x7E,0x09,0x01,0x02},// f70
  96. {0x00,0x18,0xA4,0xA4,0xA4,0x7C},// g71
  97. {0x00,0x7F,0x08,0x04,0x04,0x78},// h72
  98. {0x00,0x00,0x44,0x7D,0x40,0x00},// i73
  99. {0x00,0x40,0x80,0x84,0x7D,0x00},// j74
  100. {0x00,0x7F,0x10,0x28,0x44,0x00},// k75
  101. {0x00,0x00,0x41,0x7F,0x40,0x00},// l76
  102. {0x00,0x7C,0x04,0x18,0x04,0x78},// m77
  103. {0x00,0x7C,0x08,0x04,0x04,0x78},// n78
  104. {0x00,0x38,0x44,0x44,0x44,0x38},// o79
  105. {0x00,0xFC,0x24,0x24,0x24,0x18},// p80
  106. {0x00,0x18,0x24,0x24,0x18,0xFC},// q81
  107. {0x00,0x7C,0x08,0x04,0x04,0x08},// r82
  108. {0x00,0x48,0x54,0x54,0x54,0x20},// s83
  109. {0x00,0x04,0x3F,0x44,0x40,0x20},// t84
  110. {0x00,0x3C,0x40,0x40,0x20,0x7C},// u85
  111. {0x00,0x1C,0x20,0x40,0x20,0x1C},// v86
  112. {0x00,0x3C,0x40,0x30,0x40,0x3C},// w87
  113. {0x00,0x44,0x28,0x10,0x28,0x44},// x88
  114. {0x00,0x1C,0xA0,0xA0,0xA0,0x7C},// y89
  115. {0x00,0x44,0x64,0x54,0x4C,0x44},// z90
  116. {0x14,0x14,0x14,0x14,0x14,0x14}// horiz lines91
  117. };
  118. //中文字符串原字
  119. constUCHAR8 code F14x16_Idx[]=
  120. {
  121. "科技屏幕測試"
  122. };
  123. //中文字符串編碼
  124. constUCHAR8 code F14x16[]=
  125. {
  126. 0x00,0x00,0x48,0xFC,0x44,0x42,0x00,0x88,0x30,0x00,0xFE,0x02,0x00,0x00,
  127. 0x00,0x0C,0x02,0x7F,0x01,0x01,0x08,0x08,0x05,0x04,0xFF,0x04,0x02,0x00,/*"科",4*/
  128. 0x00,0x00,0x20,0xFE,0x20,0x90,0x20,0x20,0x20,0xFE,0x20,0xA0,0x10,0x00,
  129. 0x00,0x02,0x41,0x7F,0x81,0x80,0x41,0x47,0x29,0x18,0x27,0x41,0x40,0x00,/*"技",5*/
  130. 0x00,0x00,0xFE,0x14,0x14,0x34,0x54,0x14,0x94,0x74,0x14,0x9C,0x00,0x00,
  131. 0x00,0x30,0x0F,0x88,0x48,0x39,0x0F,0x09,0x08,0x7F,0x09,0x04,0x04,0x00,/*"屏",6*/
  132. 0x00,0x04,0x04,0xF4,0x54,0xCE,0x54,0x54,0x4E,0x4C,0xF4,0x04,0x04,0x00,
  133. 0x00,0x08,0x0A,0x3E,0x0A,0x09,0x7E,0x0A,0x0A,0x7A,0x0E,0x0A,0x09,0x00,/*"幕",7*/
  134. 0x00,0x20,0x04,0x80,0xFC,0x04,0xF4,0x04,0xFC,0x00,0xF0,0xFC,0x00,0x00,
  135. 0x00,0x00,0x7F,0x40,0x27,0x18,0x07,0x10,0x67,0x00,0x4F,0xFF,0x00,0x00,/*"測",8*/
  136. 0x00,0x80,0x88,0x98,0x20,0x20,0x20,0x20,0xA0,0xFE,0x24,0x2C,0x10,0x00,
  137. 0x00,0x00,0x1F,0x60,0x10,0x28,0x21,0x1F,0x10,0x13,0x1C,0x20,0x70,0x00,/*"試",9*/
  138. };
  139. //======================================================
  140. // 128X64OLED液晶底層驅(qū)動[8X16]字體庫
  141. // 設(shè)計者: Guokaiyi
  142. // 描 述: [8X16]西文字符的字模數(shù)據(jù) (縱向取模,字節(jié)倒序)
  143. // !"#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~
  144. //======================================================
  145. constUCHAR8 code F8X16[]=
  146. {
  147. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  148. 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//!1
  149. 0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"2
  150. 0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//#3
  151. 0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$4
  152. 0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//%5
  153. 0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//&6
  154. 0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//7
  155. 0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//(8
  156. 0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//)9
  157. 0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//*10
  158. 0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+11
  159. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//,12
  160. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//-13
  161. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//.14
  162. 0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,///15
  163. 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//016
  164. 0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//117
  165. 0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//218
  166. 0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//319
  167. 0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//420
  168. 0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//521
  169. 0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//622
  170. 0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//723
  171. 0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//824
  172. 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//925
  173. 0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//:26
  174. 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//;27
  175. 0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//<28
  176. 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//=29
  177. 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//>30
  178. 0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//?31
  179. 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@32
  180. 0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A33
  181. 0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B34
  182. 0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C35
  183. 0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D36
  184. 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E37
  185. 0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F38
  186. 0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G39
  187. 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H40
  188. 0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I41
  189. 0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J42
  190. 0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K43
  191. 0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L44
  192. 0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M45
  193. 0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N46
  194. 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O47
  195. 0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P48
  196. 0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q49
  197. 0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R50
  198. 0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S51
  199. 0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T52
  200. 0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U53
  201. 0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V54
  202. 0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W55
  203. 0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X56
  204. 0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y57
  205. 0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z58
  206. 0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[59
  207. 0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//60
  208. 0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//]61
  209. 0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^62
  210. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_63
  211. 0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//`64
  212. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a65
  213. 0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b66
  214. 0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c67
  215. 0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d68
  216. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e69
  217. 0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f70
  218. 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g71
  219. 0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h72
  220. 0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i73
  221. 0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j74
  222. 0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k75
  223. 0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l76
  224. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m77
  225. 0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n78
  226. 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o79
  227. 0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p80
  228. 0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q81
  229. 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r82
  230. 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s83
  231. 0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t84
  232. 0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u85
  233. 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v86
  234. 0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w87
  235. 0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x88
  236. 0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y89
  237. 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z90
  238. 0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{91
  239. 0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//|92
  240. 0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//}93
  241. 0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~94
  242. };
  243. /*----------------------------------------------------------------------------*
  244. * 內(nèi)部函數(shù)原型 *
  245. *----------------------------------------------------------------------------*/
  246. VOIDLED_WrDat(UCHAR8 ucData);
  247. VOIDLED_WrCmd(UCHAR8 ucCmd);
  248. VOIDLED_SetPos(UCHAR8 ucIdxX,UCHAR8 ucIdxY);
  249. VOIDSetStartColumn(UCHAR8 ucData);
  250. VOIDSetAddressingMode(UCHAR8 ucData);
  251. VOIDSetColumnAddress(UCHAR8 a,UCHAR8 b);
  252. VOIDSetPageAddress(UCHAR8 a,UCHAR8 b);
  253. VOIDSetStartLine(UCHAR8 d);
  254. VOIDSetContrastControl(UCHAR8 d);
  255. VOIDSetChargePump(UCHAR8 d);
  256. VOIDSetSegmentRemap(UCHAR8 d);
  257. VOIDSetEntireDisplay(UCHAR8 d);
  258. VOIDSetInverseDisplay(UCHAR8 d);
  259. VOIDSetMultiplexRatio(UCHAR8 d);
  260. VOIDSetDisplayOnOff(UCHAR8 d);
  261. VOIDSetStartPage(UCHAR8 d);
  262. VOIDSetCommonRemap(UCHAR8 d);
  263. VOIDSetDisplayOffset(UCHAR8 d);
  264. VOIDSetDisplayClock(UCHAR8 d);
  265. VOIDSetPrechargePeriod(UCHAR8 d);
  266. VOIDSetCommonConfig(UCHAR8 d);
  267. VOIDSetVCOMH(UCHAR8 d);
  268. VOIDSetNop(VOID);
  269. /*----------------------------------------------------------------------------*
  270. * 外部函數(shù)原型 *
  271. *----------------------------------------------------------------------------*/
  272. /**********************************************
  273. //IIC Start
  274. **********************************************/
  275. voidIIC_Start()
  276. {
  277. LED_SCL=1;
  278. //Delay_us(1);
  279. LED_SDA=1;
  280. //Delay_us(1);
  281. LED_SDA=0;
  282. // Delay_us(1);
  283. LED_SCL=0;
  284. // Delay_us(1);
  285. }
  286. /**********************************************
  287. //IIC Stop
  288. **********************************************/
  289. voidIIC_Stop()
  290. {
  291. LED_SCL=0;
  292. //Delay_us(1);
  293. LED_SDA=0;
  294. //Delay_us(1);
  295. LED_SCL=1;
  296. //Delay_us(1);
  297. LED_SDA=1;
  298. //Delay_us(1);
  299. }
  300. /**********************************************
  301. // IIC Write byte
  302. **********************************************/
  303. voidWrite_IIC_Byte(unsignedcharIIC_Byte)
  304. {
  305. unsignedchari;
  306. for(i=0;i<8;i++)
  307. {
  308. if(IIC_Byte&0x80)//1?0?
  309. LED_SDA=1;
  310. else
  311. LED_SDA=0;
  312. //Delay_us(1);
  313. LED_SCL=1;
  314. //Delay_us(1);
  315. LED_SCL=0;
  316. //Delay_us(1);
  317. IIC_Byte<<=1;//loop
  318. }
  319. LED_SDA=1;
  320. //Delay_us(1);
  321. LED_SCL=1;
  322. //Delay_us(1);
  323. LED_SCL=0;
  324. //Delay_us(1);
  325. }
  326. /*****************************************************************************
  327. 函 數(shù) 名 : LED_WrDat
  328. 功能描述 : 向OLED寫數(shù)據(jù)
  329. 輸入?yún)?shù) : UCHAR8 ucData
  330. 輸出參數(shù) : NONE
  331. 返 回 值 : NONE
  332. *****************************************************************************/
  333. VOIDLED_WrDat(UCHAR8 ucData)
  334. {
  335. IIC_Start();
  336. Write_IIC_Byte(0x78);
  337. Write_IIC_Byte(0x40);//write data
  338. Write_IIC_Byte(ucData);
  339. IIC_Stop();
  340. }
  341. /*****************************************************************************
  342. 函 數(shù) 名 : LED_WrCmd
  343. 功能描述 : 向OLED寫命令
  344. 輸入?yún)?shù) : UCHAR8 ucCmd
  345. 輸出參數(shù) : NONE
  346. 返 回 值 : NONE
  347. *****************************************************************************/
  348. VOIDLED_WrCmd(UCHAR8 ucCmd)
  349. {
  350. IIC_Start();
  351. Write_IIC_Byte(0x78);//Slave address,SA0=0
  352. Write_IIC_Byte(0x00);//write command
  353. Write_IIC_Byte(ucCmd);
  354. IIC_Stop();
  355. }
  356. /*****************************************************************************
  357. 函 數(shù) 名 : LED_SetPos
  358. 功能描述 : 設(shè)置坐標(biāo)
  359. 輸入?yún)?shù) : UCHAR8 ucIdxX
  360. UCHAR8 ucIdxY
  361. 輸出參數(shù) : NONE
  362. 返 回 值 : NONE
  363. *****************************************************************************/
  364. VOIDLED_SetPos(UCHAR8 ucIdxX,UCHAR8 ucIdxY)
  365. {
  366. LED_WrCmd(0xb0+ucIdxY);
  367. LED_WrCmd(((ucIdxX&0xf0)>>4)|0x10);
  368. LED_WrCmd((ucIdxX&0x0f)|0x00);
  369. }
  370. /*****************************************************************************
  371. 函 數(shù) 名 : LED_Fill
  372. 功能描述 : 對全屏寫入同一個字符函數(shù)
  373. 如 LED_Fill(0x01); 對于某一位0為不亮 1為亮
  374. ------------------------------------------------------
  375. 共128列
  376. 1 1 1
  377. 共 0 0 0
  378. 8 0 0 0
  379. 組 0 ……0 ………… 0
  380. 字 0 0 0
  381. 符 0 0 0
  382. 即 0 0 0
  383. 8 0 0 0
  384. 頁 1 1 1
  385. 64 0 0 0
  386. 行 . . .
  387. . . ………… .
  388. . . .
  389. . . .
  390. 0 0 0
  391. ------------------------------------------------------
  392. 輸入?yún)?shù) : UCHAR8 ucData
  393. 輸出參數(shù) : NONE
  394. 返 回 值 : NONE
  395. *****************************************************************************/
  396. VOIDLED_Fill(UCHAR8 ucData)
  397. {
  398. UCHAR8 ucPage,ucColumn;
  399. for(ucPage=0;ucPage<8;ucPage++)
  400. {
  401. LED_WrCmd(0xb0+ucPage);//0xb0+0~7表示頁0~7
  402. LED_WrCmd(0x00);//0x00+0~16表示將128列分成16組其地址在某組中的第幾列
  403. LED_WrCmd(0x10);//0x10+0~16表示將128列分成16組其地址所在第幾組
  404. for(ucColumn=0;ucColumn<128;ucColumn++)
  405. {
  406. LED_WrDat(ucData);
  407. }
  408. }
  409. }
  410. VOIDSetStartColumn(UCHAR8 ucData)
  411. {
  412. LED_WrCmd(0x00+ucData%16);// Set Lower Column Start Address for Page Addressing Mode
  413. // Default => 0x00
  414. LED_WrCmd(0x10+ucData/16);// Set Higher Column Start Address for Page Addressing Mode
  415. // Default => 0x10
  416. }
  417. VOIDSetAddressingMode(UCHAR8 ucData)
  418. {
  419. LED_WrCmd(0x20);// Set Memory Addressing Mode
  420. LED_WrCmd(ucData);// Default => 0x02
  421. // 0x00 => Horizontal Addressing Mode
  422. // 0x01 => Vertical Addressing Mode
  423. // 0x02 => Page Addressing Mode
  424. }
  425. VOIDSetColumnAddress(UCHAR8 a,UCHAR8 b)
  426. {
  427. LED_WrCmd(0x21);// Set Column Address
  428. LED_WrCmd(a);// Default => 0x00 (Column Start Address)
  429. LED_WrCmd(b);// Default => 0x7F (Column End Address)
  430. }
  431. VOIDSetPageAddress(UCHAR8 a,UCHAR8 b)
  432. {
  433. LED_WrCmd(0x22);// Set Page Address
  434. LED_WrCmd(a);// Default => 0x00 (Page Start Address)
  435. LED_WrCmd(b);// Default => 0x07 (Page End Address)
  436. }
  437. VOIDSetStartLine(UCHAR8 ucData)
  438. {
  439. LED_WrCmd(0x40|ucData);// Set Display Start Line
  440. // Default => 0x40 (0x00)
  441. }
  442. VOIDSetContrastControl(UCHAR8 ucData)
  443. {
  444. LED_WrCmd(0x81);// Set Contrast Control
  445. LED_WrCmd(ucData);// Default => 0x7F
  446. }
  447. VOIDSetChargePump(UCHAR8 ucData)
  448. {
  449. LED_WrCmd(0x8D);// Set Charge Pump
  450. LED_WrCmd(0x10|ucData);// Default => 0x10
  451. // 0x10 (0x00) => Disable Charge Pump
  452. // 0x14 (0x04) => Enable Charge Pump
  453. }
  454. VOIDSetSegmentRemap(UCHAR8 ucData)
  455. {
  456. LED_WrCmd(0xA0|ucData);// Set Segment Re-Map
  457. // Default => 0xA0
  458. // 0xA0 (0x00) => Column Address 0 Mapped to SEG0
  459. // 0xA1 (0x01) => Column Address 0 Mapped to SEG127
  460. }
  461. VOIDSetEntireDisplay(UCHAR8 ucData)
  462. {
  463. LED_WrCmd(0xA4|ucData);// Set Entire Display On / Off
  464. // Default => 0xA4
  465. // 0xA4 (0x00) => Normal Display
  466. // 0xA5 (0x01) => Entire Display On
  467. }
  468. VOIDSetInverseDisplay(UCHAR8 ucData)
  469. {
  470. LED_WrCmd(0xA6|ucData);// Set Inverse Display On/Off
  471. // Default => 0xA6
  472. // 0xA6 (0x00) => Normal Display
  473. // 0xA7 (0x01) => Inverse Display On
  474. }
  475. VOIDSetMultiplexRatio(UCHAR8 ucData)
  476. {
  477. LED_WrCmd(0xA8);// Set Multiplex Ratio
  478. LED_WrCmd(ucData);// Default => 0x3F (1/64 Duty)
  479. }
  480. VOIDSetDisplayOnOff(UCHAR8 ucData)
  481. {
  482. LED_WrCmd(0xAE|ucData);// Set Display On/Off
  483. // Default => 0xAE
  484. // 0xAE (0x00) => Display Off
  485. // 0xAF (0x01) => Display On
  486. }
  487. VOIDSetStartPage(UCHAR8 ucData)
  488. {
  489. LED_WrCmd(0xB0|ucData);// Set Page Start Address for Page Addressing Mode
  490. // Default => 0xB0 (0x00)
  491. }
  492. VOIDSetCommonRemap(UCHAR8 ucData)
  493. {
  494. LED_WrCmd(0xC0|ucData);// Set COM Output Scan Direction
  495. // Default => 0xC0
  496. // 0xC0 (0x00) => Scan from COM0 to 63
  497. // 0xC8 (0x08) => Scan from COM63 to 0
  498. }
  499. VOIDSetDisplayOffset(UCHAR8 ucData)
  500. {
  501. LED_WrCmd(0xD3);// Set Display Offset
  502. LED_WrCmd(ucData);// Default => 0x00
  503. }
  504. VOIDSetDisplayClock(UCHAR8 ucData)
  505. {
  506. LED_WrCmd(0xD5);// Set Display Clock Divide Ratio / Oscillator Frequency
  507. LED_WrCmd(ucData);// Default => 0x80
  508. // D[3:0] => Display Clock Divider
  509. // D[7:4] => Oscillator Frequency
  510. }
  511. VOIDSetPrechargePeriod(UCHAR8 ucData)
  512. {
  513. LED_WrCmd(0xD9);// Set Pre-Charge Period
  514. LED_WrCmd(ucData);// Default => 0x22 (2 Display Clocks [Phase 2] / 2 Display Clocks [Phase 1])
  515. // D[3:0] => Phase 1 Period in 1~15 Display Clocks
  516. // D[7:4] => Phase 2 Period in 1~15 Display Clocks
  517. }
  518. VOIDSetCommonConfig(UCHAR8 ucData)
  519. {
  520. LED_WrCmd(0xDA);// Set COM Pins Hardware Configuration
  521. LED_WrCmd(0x02|ucData);// Default => 0x12 (0x10)
  522. // Alternative COM Pin Configuration
  523. // Disable COM Left/Right Re-Map
  524. }
  525. VOIDSetVCOMH(UCHAR8 ucData)
  526. {
  527. LED_WrCmd(0xDB);// Set VCOMH Deselect Level
  528. LED_WrCmd(ucData);// Default => 0x20 (0.77*VCC)
  529. }
  530. VOIDSetNop(VOID)
  531. {
  532. LED_WrCmd(0xE3);// Command for No Operation
  533. }
  534. /*****************************************************************************
  535. 函 數(shù) 名 : LED_Init
  536. 功能描述 : OLED初始化
  537. 輸入?yún)?shù) : VOID
  538. 輸出參數(shù) : NONE
  539. 返 回 值 : NONE
  540. *****************************************************************************/
  541. VOIDLED_Init(VOID)
  542. {
  543. UCHAR8 i;
  544. LED_SCL=1;
  545. LED_RST=0;
  546. for(i=0;i<100;i++)
  547. {
  548. _nop_();//從上電到下面開始初始化要有足夠的時間,即等待RC復(fù)位完畢
  549. }
  550. LED_RST=1;
  551. SetDisplayOnOff(0x00);// Display Off (0x00/0x01)
  552. SetDisplayClock(0x80);// Set Clock as 100 Frames/Sec
  553. SetMultiplexRatio(0x3F);// 1/64 Duty (0x0F~0x3F)
  554. SetDisplayOffset(0x00);// Shift Mapping RAM Counter (0x00~0x3F)
  555. SetStartLine(0x00);// Set Mapping RAM Display Start Line (0x00~0x3F)
  556. SetChargePump(0x04);// Enable Embedded DC/DC Converter (0x00/0x04)
  557. SetAddressingMode(0x02);// Set Page Addressing Mode (0x00/0x01/0x02)
  558. SetSegmentRemap(0x01);// Set SEG/Column Mapping 0x00左右反置 0x01正常
  559. SetCommonRemap(0x08);// Set COM/Row Scan Direction 0x00上下反置 0x08正常
  560. SetCommonConfig(0x10);// Set Sequential Configuration (0x00/0x10)
  561. SetContrastControl(0xCF);// Set SEG Output Current
  562. SetPrechargePeriod(0xF1);// Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  563. SetVCOMH(0x40);// Set VCOM Deselect Level
  564. SetEntireDisplay(0x00);// Disable Entire Display On (0x00/0x01)
  565. SetInverseDisplay(0x00);// Disable Inverse Display On (0x00/0x01)
  566. SetDisplayOnOff(0x01);// Display On (0x00/0x01)
  567. LED_Fill(0x00);// 初始清屏
  568. LED_SetPos(0,0);
  569. return;
  570. }
  571. /*****************************************************************************
  572. 函 數(shù) 名 : LED_P6x8Char
  573. 功能描述 : 顯示一個6x8標(biāo)準(zhǔn)ASCII字符
  574. 輸入?yún)?shù) : UCHAR8 ucIdxX 顯示的橫坐標(biāo)0~122
  575. UCHAR8 ucIdxY 頁范圍0~7
  576. UCHAR8 ucData 顯示的字符
  577. 輸出參數(shù) : NONE
  578. 返 回 值 : NONE
  579. *****************************************************************************/
  580. VOIDLED_P6x8Char(UCHAR8 ucIdxX,UCHAR8 ucIdxY,UCHAR8 ucData)
  581. {
  582. UCHAR8 i,ucDataTmp;
  583. ucDataTmp=ucData-32;
  584. if(ucIdxX>122)
  585. {
  586. ucIdxX=0;
  587. ucIdxY++;
  588. }
  589. LED_SetPos(ucIdxX,ucIdxY);
  590. for(i=0;i<6;i++)
  591. {
  592. LED_WrDat(F6x8[ucDataTmp][i]);
  593. }
  594. }
  595. /*****************************************************************************
  596. 函 數(shù) 名 : LED_P6x8Str
  597. 功能描述 : 寫入一組6x8標(biāo)準(zhǔn)ASCII字符串
  598. 輸入?yún)?shù) : UCHAR8 ucIdxX 顯示的橫坐標(biāo)0~122
  599. UCHAR8 ucIdxY 頁范圍0~7
  600. UCHAR8 ucDataStr[] 顯示的字符串
  601. 輸出參數(shù) : NONE
  602. 返 回 值 : NONE
  603. *****************************************************************************/
  604. VOIDLED_P6x8Str(UCHAR8 ucIdxX,UCHAR8 ucIdxY,UCHAR8 ucDataStr[])
  605. {
  606. UCHAR8 i,j,ucDataTmp;
  607. for(j=0;ucDataStr[j]!=