[51单片机] 51单片机驱动OLED

[复制链接]
3601|0
 楼主| 比神乐 发表于 2024-10-13 14:19 | 显示全部楼层 |阅读模式
代码:
OLED.C
  1. #include "reg51.h"
  2. #include "OLED.h"
  3. sbit LCD_SCL=P1^0;
  4. sbit LCD_SDA=P1^1;
  5. sbit LCD_RST=P1^2;
  6. sbit LCD_DC=P1^3;
  7. //#define LCD_SCL  LATCbits.LATC0
  8. //#define LCD_SDA  LATCbits.LATC1
  9. //#define LCD_RST  LATCbits.LATC2
  10. //#define LCD_DC   LATCbits.LATC3

  11. #define XLevelL                0x00
  12. #define XLevelH                0x10
  13. #define XLevel                ((XLevelH&0x0F)*16+XLevelL)
  14. #define Max_Column        128
  15. #define Max_Row                64
  16. #define        Brightness        0xCF


  17. #define X_WIDTH 128
  18. #define Y_WIDTH 64


  19. unsigned char code Dot[]={   //图片--100x36
  20. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,
  21. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
  22. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
  23. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
  24. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
  25. 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,
  26. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xF0,0xF8,0xFC,0xFE,0xFF,
  27. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  28. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x3F,0x9F,0x9F,0xDF,0xCF,0xEF,0xEF,
  29. 0xE7,0xE7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF3,0xF3,0xFB,0xFB,0xFB,0xFB,0xF9,0xF9,0xFD,
  30. 0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,
  31. 0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFD,0xFC,0xFC,0xFC,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,
  32. 0xFC,0xFC,0xF8,0xF0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
  33. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  34. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0x3F,0x0F,0x07,0x03,0xF8,0xFA,0xFB,0xBB,0xBB,
  35. 0x9B,0xBB,0xBB,0x3B,0x03,0x03,0x03,0x83,0xE3,0x73,0xFB,0xF3,0x83,0x03,0x03,0xC3,
  36. 0xE3,0xF3,0xF3,0xFB,0xBB,0x73,0x73,0x33,0x03,0xFB,0xFB,0xFB,0xBB,0x9B,0xBB,0xBB,
  37. 0xBB,0x03,0x03,0x03,0x83,0xE3,0x73,0x7B,0xFB,0x83,0x03,0x03,0xFB,0xFB,0x3B,0x3B,
  38. 0x7B,0xF3,0xF7,0xEF,0x1F,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  39. 0x00,0x00,0x00,0x03,0x07,0x0F,0x1F,0x3F,0x3F,0x3F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,
  40. 0x7F,0x7F,0x3F,0x3F,0x1F,0x1F,0x0F,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,
  41. 0x7F,0x7F,0x73,0x73,0x73,0x73,0x73,0x21,0x30,0x7E,0x3F,0x1F,0x0F,0x0C,0x0F,0x3F,
  42. 0x7F,0x78,0x38,0x01,0x7B,0x73,0x73,0x73,0x7B,0x3F,0x3F,0x1F,0x00,0x7F,0x7F,0x73,
  43. 0x73,0x73,0x73,0x73,0x73,0x30,0x7C,0x3F,0x1F,0x0F,0x0C,0x0F,0x3F,0x7F,0x78,0x00,
  44. 0x7F,0x7F,0x0F,0x0F,0x1F,0x3F,0x3F,0x7B,0x30,0x01,0x7F,0xFF,0xFF,0x00,0x00,0x00,
  45. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  48. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  49. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  50. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  51. 0x00,0x00,0x00,0x00};



  52. //======================================

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


  148. code unsigned char F8X16[]=
  149. {
  150.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,// 0
  151.   0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00,//!1
  152.   0x00,0x10,0x0C,0x06,0x10,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//"2
  153.   0x40,0xC0,0x78,0x40,0xC0,0x78,0x40,0x00,0x04,0x3F,0x04,0x04,0x3F,0x04,0x04,0x00,//#3
  154.   0x00,0x70,0x88,0xFC,0x08,0x30,0x00,0x00,0x00,0x18,0x20,0xFF,0x21,0x1E,0x00,0x00,//$4
  155.   0xF0,0x08,0xF0,0x00,0xE0,0x18,0x00,0x00,0x00,0x21,0x1C,0x03,0x1E,0x21,0x1E,0x00,//%5
  156.   0x00,0xF0,0x08,0x88,0x70,0x00,0x00,0x00,0x1E,0x21,0x23,0x24,0x19,0x27,0x21,0x10,//&6
  157.   0x10,0x16,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//'7
  158.   0x00,0x00,0x00,0xE0,0x18,0x04,0x02,0x00,0x00,0x00,0x00,0x07,0x18,0x20,0x40,0x00,//(8
  159.   0x00,0x02,0x04,0x18,0xE0,0x00,0x00,0x00,0x00,0x40,0x20,0x18,0x07,0x00,0x00,0x00,//)9
  160.   0x40,0x40,0x80,0xF0,0x80,0x40,0x40,0x00,0x02,0x02,0x01,0x0F,0x01,0x02,0x02,0x00,//*10
  161.   0x00,0x00,0x00,0xF0,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x1F,0x01,0x01,0x01,0x00,//+11
  162.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xB0,0x70,0x00,0x00,0x00,0x00,0x00,//,12
  163.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,//-13
  164.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,//.14
  165.   0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00,///15
  166.   0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,//016
  167.   0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//117
  168.   0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,//218
  169.   0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,//319
  170.   0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,//420
  171.   0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,//521
  172.   0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,//622
  173.   0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,//723
  174.   0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,//824
  175.   0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,//925
  176.   0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,//:26
  177.   0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x60,0x00,0x00,0x00,0x00,//;27
  178.   0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x00,//<28
  179.   0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,//=29
  180.   0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00,//>30
  181.   0x00,0x70,0x48,0x08,0x08,0x08,0xF0,0x00,0x00,0x00,0x00,0x30,0x36,0x01,0x00,0x00,//?31
  182.   0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00,0x07,0x18,0x27,0x24,0x23,0x14,0x0B,0x00,//@32
  183.   0x00,0x00,0xC0,0x38,0xE0,0x00,0x00,0x00,0x20,0x3C,0x23,0x02,0x02,0x27,0x38,0x20,//A33
  184.   0x08,0xF8,0x88,0x88,0x88,0x70,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x11,0x0E,0x00,//B34
  185.   0xC0,0x30,0x08,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00,//C35
  186.   0x08,0xF8,0x08,0x08,0x08,0x10,0xE0,0x00,0x20,0x3F,0x20,0x20,0x20,0x10,0x0F,0x00,//D36
  187.   0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x20,0x23,0x20,0x18,0x00,//E37
  188.   0x08,0xF8,0x88,0x88,0xE8,0x08,0x10,0x00,0x20,0x3F,0x20,0x00,0x03,0x00,0x00,0x00,//F38
  189.   0xC0,0x30,0x08,0x08,0x08,0x38,0x00,0x00,0x07,0x18,0x20,0x20,0x22,0x1E,0x02,0x00,//G39
  190.   0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x20,0x3F,0x21,0x01,0x01,0x21,0x3F,0x20,//H40
  191.   0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//I41
  192.   0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,0x00,//J42
  193.   0x08,0xF8,0x88,0xC0,0x28,0x18,0x08,0x00,0x20,0x3F,0x20,0x01,0x26,0x38,0x20,0x00,//K43
  194.   0x08,0xF8,0x08,0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,0x20,0x30,0x00,//L44
  195.   0x08,0xF8,0xF8,0x00,0xF8,0xF8,0x08,0x00,0x20,0x3F,0x00,0x3F,0x00,0x3F,0x20,0x00,//M45
  196.   0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00,//N46
  197.   0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00,//O47
  198.   0x08,0xF8,0x08,0x08,0x08,0x08,0xF0,0x00,0x20,0x3F,0x21,0x01,0x01,0x01,0x00,0x00,//P48
  199.   0xE0,0x10,0x08,0x08,0x08,0x10,0xE0,0x00,0x0F,0x18,0x24,0x24,0x38,0x50,0x4F,0x00,//Q49
  200.   0x08,0xF8,0x88,0x88,0x88,0x88,0x70,0x00,0x20,0x3F,0x20,0x00,0x03,0x0C,0x30,0x20,//R50
  201.   0x00,0x70,0x88,0x08,0x08,0x08,0x38,0x00,0x00,0x38,0x20,0x21,0x21,0x22,0x1C,0x00,//S51
  202.   0x18,0x08,0x08,0xF8,0x08,0x08,0x18,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//T52
  203.   0x08,0xF8,0x08,0x00,0x00,0x08,0xF8,0x08,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//U53
  204.   0x08,0x78,0x88,0x00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00,//V54
  205.   0xF8,0x08,0x00,0xF8,0x00,0x08,0xF8,0x00,0x03,0x3C,0x07,0x00,0x07,0x3C,0x03,0x00,//W55
  206.   0x08,0x18,0x68,0x80,0x80,0x68,0x18,0x08,0x20,0x30,0x2C,0x03,0x03,0x2C,0x30,0x20,//X56
  207.   0x08,0x38,0xC8,0x00,0xC8,0x38,0x08,0x00,0x00,0x00,0x20,0x3F,0x20,0x00,0x00,0x00,//Y57
  208.   0x10,0x08,0x08,0x08,0xC8,0x38,0x08,0x00,0x20,0x38,0x26,0x21,0x20,0x20,0x18,0x00,//Z58
  209.   0x00,0x00,0x00,0xFE,0x02,0x02,0x02,0x00,0x00,0x00,0x00,0x7F,0x40,0x40,0x40,0x00,//[59
  210.   0x00,0x0C,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x38,0xC0,0x00,//\60
  211.   0x00,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0x00,0x40,0x40,0x40,0x7F,0x00,0x00,0x00,//]61
  212.   0x00,0x00,0x04,0x02,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//^62
  213.   0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,//_63
  214.   0x00,0x02,0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//`64
  215.   0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x19,0x24,0x22,0x22,0x22,0x3F,0x20,//a65
  216.   0x08,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x3F,0x11,0x20,0x20,0x11,0x0E,0x00,//b66
  217.   0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00,0x0E,0x11,0x20,0x20,0x20,0x11,0x00,//c67
  218.   0x00,0x00,0x00,0x80,0x80,0x88,0xF8,0x00,0x00,0x0E,0x11,0x20,0x20,0x10,0x3F,0x20,//d68
  219.   0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,0x22,0x13,0x00,//e69
  220.   0x00,0x80,0x80,0xF0,0x88,0x88,0x88,0x18,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//f70
  221.   0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x6B,0x94,0x94,0x94,0x93,0x60,0x00,//g71
  222.   0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//h72
  223.   0x00,0x80,0x98,0x98,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//i73
  224.   0x00,0x00,0x00,0x80,0x98,0x98,0x00,0x00,0x00,0xC0,0x80,0x80,0x80,0x7F,0x00,0x00,//j74
  225.   0x08,0xF8,0x00,0x00,0x80,0x80,0x80,0x00,0x20,0x3F,0x24,0x02,0x2D,0x30,0x20,0x00,//k75
  226.   0x00,0x08,0x08,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,//l76
  227.   0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F,//m77
  228.   0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20,//n78
  229.   0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00,//o79
  230.   0x80,0x80,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xFF,0xA1,0x20,0x20,0x11,0x0E,0x00,//p80
  231.   0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,0x0E,0x11,0x20,0x20,0xA0,0xFF,0x80,//q81
  232.   0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x20,0x20,0x3F,0x21,0x20,0x00,0x01,0x00,//r82
  233.   0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x33,0x24,0x24,0x24,0x24,0x19,0x00,//s83
  234.   0x00,0x80,0x80,0xE0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x1F,0x20,0x20,0x00,0x00,//t84
  235.   0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x20,//u85
  236.   0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x00,0x01,0x0E,0x30,0x08,0x06,0x01,0x00,//v86
  237.   0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,0x0F,0x30,0x0C,0x03,0x0C,0x30,0x0F,0x00,//w87
  238.   0x00,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x31,0x2E,0x0E,0x31,0x20,0x00,//x88
  239.   0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,0x80,0x81,0x8E,0x70,0x18,0x06,0x01,0x00,//y89
  240.   0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00,0x21,0x30,0x2C,0x22,0x21,0x30,0x00,//z90
  241.   0x00,0x00,0x00,0x00,0x80,0x7C,0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x3F,0x40,0x40,//{91
  242.   0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,//|92
  243.   0x00,0x02,0x02,0x7C,0x80,0x00,0x00,0x00,0x00,0x40,0x40,0x3F,0x00,0x00,0x00,0x00,//}93
  244.   0x00,0x06,0x01,0x01,0x02,0x02,0x04,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//~94

  245. };


  246. void LCD_WrDat(unsigned char dat)
  247. {
  248.         unsigned char i=8;
  249.         //LCD_CS=0;;
  250.         LCD_DC=1;;
  251.   LCD_SCL=0;;
  252.   //;;   
  253.   while(i--)
  254.   {
  255.     if(dat&0x80){LCD_SDA=1;}
  256.     else{LCD_SDA=0;}
  257.     LCD_SCL=1;
  258.     ;;;
  259.                 //;;            
  260.     LCD_SCL=0;;   
  261.     dat<<=1;   
  262.   }
  263.         //LCD_CS=1;
  264. }
  265. void LCD_WrCmd(unsigned char cmd)
  266. {
  267.         unsigned char i=8;
  268.        
  269.         //LCD_CS=0;;
  270.         LCD_DC=0;;
  271.   LCD_SCL=0;;
  272.   //;;   
  273.   while(i--)
  274.   {
  275.     if(cmd&0x80){LCD_SDA=1;}
  276.     else{LCD_SDA=0;;}
  277.     LCD_SCL=1;;
  278.     ;;;
  279.                 //;;            
  280.     LCD_SCL=0;;   
  281.     cmd<<=1;;   
  282.   }        
  283.         //LCD_CS=1;
  284. }
  285. void LCD_Set_Pos(unsigned char x, unsigned char y)
  286. {
  287.   LCD_WrCmd(0xb0+y);
  288.   LCD_WrCmd(((x&0xf0)>>4)|0x10);
  289.   LCD_WrCmd((x&0x0f)|0x00);
  290. }
  291. void LCD_Fill(unsigned char bmp_dat)
  292. {
  293.         unsigned char y,x;
  294.        
  295.         for(y=0;y<8;y++)
  296.         {
  297.                 LCD_WrCmd(0xb0+y);
  298.                 LCD_WrCmd(0x01);
  299.                 LCD_WrCmd(0x10);
  300.                 for(x=0;x<X_WIDTH;x++)
  301.                         LCD_WrDat(bmp_dat);
  302.         }
  303. }
  304. void LCD_CLS(void)
  305. {
  306.         unsigned char y,x;       
  307.         for(y=0;y<8;y++)
  308.         {
  309.                 LCD_WrCmd(0xb0+y);
  310.                 LCD_WrCmd(0x01);
  311.                 LCD_WrCmd(0x10);
  312.                 for(x=0;x<X_WIDTH;x++)
  313.                         LCD_WrDat(0);
  314.         }
  315. }
  316. void LCD_DLY_ms(unsigned int ms)
  317. {   
  318.         unsigned int i;
  319.         while(ms--)
  320.         {
  321.                 for(i=0;i<2000;i++);//编译器自带延时指定个周期,在主频8Mhz下,一个指令周期为0.5us       
  322.                 //GCC_CLRWDT();
  323.         }
  324. }
  325. void LCD_Init(void)        
  326. {  
  327.        
  328.        
  329.         LCD_SCL=1;
  330.         //LCD_CS=1;        //预制SLK和SS为高电平         
  331.         LCD_RST=0;
  332.         LCD_DLY_ms(50);
  333.         LCD_RST=1;
  334.        
  335.         //从上电到下面开始初始化要有足够的时间,即等待RC复位完毕   
  336.   
  337.   LCD_WrCmd(0xae);//--turn off oled panel
  338.   LCD_WrCmd(0x00);//---set low column address
  339.   LCD_WrCmd(0x10);//---set high column address
  340.   LCD_WrCmd(0x40);//--set start line address  Set Mapping RAM Display Start Line (0x00~0x3F)
  341.   LCD_WrCmd(0x81);//--set contrast control register
  342.   LCD_WrCmd(0xcf); // Set SEG Output Current Brightness
  343.   LCD_WrCmd(0xa1);//--Set SEG/Column Mapping     0xa0左右反置 0xa1正常
  344.   LCD_WrCmd(0xc8);//Set COM/Row Scan Direction   0xc0上下反置 0xc8正常
  345.   LCD_WrCmd(0xa6);//--set normal display
  346.   LCD_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
  347.   LCD_WrCmd(0x3f);//--1/64 duty
  348.   LCD_WrCmd(0xd3);//-set display offset        Shift Mapping RAM Counter (0x00~0x3F)
  349.   LCD_WrCmd(0x00);//-not offset
  350.   LCD_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
  351.   LCD_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
  352.   LCD_WrCmd(0xd9);//--set pre-charge period
  353.   LCD_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
  354.   LCD_WrCmd(0xda);//--set com pins hardware configuration
  355.   LCD_WrCmd(0x12);
  356.   LCD_WrCmd(0xdb);//--set vcomh
  357.   LCD_WrCmd(0x40);//Set VCOM Deselect Level
  358.   LCD_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
  359.   LCD_WrCmd(0x02);//
  360.   LCD_WrCmd(0x8d);//--set Charge Pump enable/disable
  361.   LCD_WrCmd(0x14);//--set(0x10) disable
  362.   LCD_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
  363.   LCD_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
  364.   LCD_WrCmd(0xaf);//--turn on oled panel
  365.   LCD_Fill(0x00);  //初始清屏
  366.   LCD_Set_Pos(0,0);        
  367. }

  368. //==============================================================
  369. //函数名: void LCD_PutPixel(byte x,byte y)
  370. //功能描述:绘制一个点(x,y)
  371. //参数:真实坐标值(x,y),x的范围0~127,y的范围0~64
  372. //返回:无
  373. //==============================================================
  374. void LCD_PutPixel(unsigned char  x,unsigned char  y)
  375. {
  376.         unsigned char  data1;  //data1当前点的数据
  377.          
  378.   LCD_Set_Pos(x,y);
  379.         data1 = 0x01<<(y%8);        
  380.         LCD_WrCmd(0xb0+(y>>3));
  381.         LCD_WrCmd(((x&0xf0)>>4)|0x10);
  382.         LCD_WrCmd((x&0x0f)|0x00);
  383.         LCD_WrDat(data1);                 
  384. }
  385. //==============================================================
  386. //函数名: void LCD_Rectangle(byte x1,byte y1,
  387. //                   byte x2,byte y2,byte color,byte gif)
  388. //功能描述:绘制一个实心矩形
  389. //参数:左上角坐标(x1,y1),右下角坐标(x2,y2)
  390. //      其中x1、x2的范围0~127,y1,y2的范围0~63,即真实坐标值
  391. //返回:无
  392. //==============================================================
  393. void LCD_Rectangle(unsigned char  x1,unsigned char  y1,unsigned char  x2,unsigned char  y2,unsigned char  gif)
  394. {
  395.         unsigned char  n;
  396.                
  397.         LCD_Set_Pos(x1,y1>>3);
  398.         for(n=x1;n<=x2;n++)
  399.         {
  400.                 LCD_WrDat(0x01<<(y1%8));                        
  401.                 if(gif == 1)         LCD_DLY_ms(50);
  402.         }  
  403.         LCD_Set_Pos(x1,y2>>3);
  404.   for(n=x1;n<=x2;n++)
  405.         {
  406.                 LCD_WrDat(0x01<<(y2%8));                        
  407.                 if(gif == 1)         LCD_DLY_ms(5);
  408.         }
  409.        
  410. }  

  411. //==============================================================
  412. //函数名:LCD_P6x8Str(unsigned char x,unsigned char y,unsigned char *p)
  413. //功能描述:写入一组标准ASCII字符串
  414. //参数:显示的位置(x,y),y为页范围0~7,要显示的字符串
  415. //返回:无
  416. //==============================================================  
  417. void LCD_P6x8Str(unsigned char x,unsigned char y,unsigned char ch[])
  418. {
  419.   unsigned char c=0,i=0,j=0;      
  420.   while (ch[j]!='\0')
  421.   {   
  422.     c =ch[j]-32;
  423.     if(x>126){x=0;y++;}
  424.     LCD_Set_Pos(x,y);   
  425.           for(i=0;i<6;i++)     
  426.             LCD_WrDat(F6x8[c][i]);  
  427.           x+=6;
  428.           j++;
  429.   }
  430. }

  431. void LCD_P8x16Str(unsigned char x,unsigned char y,unsigned char ch[])
  432. {
  433.   unsigned char c=0,i=0,j=0;
  434.         
  435.   while (ch[j]!='\0')
  436.   {   
  437.     c =ch[j]-32;
  438.     if(x>120){x=0;y++;}
  439.     LCD_Set_Pos(x,y);   
  440.           for(i=0;i<8;i++)     
  441.             LCD_WrDat(F8X16[c*16+i]);
  442.           LCD_Set_Pos(x,y+1);   
  443.           for(i=0;i<8;i++)     
  444.             LCD_WrDat(F8X16[c*16+i+8]);  
  445.           x+=8;
  446.           j++;
  447.   }
  448. }


  449. //==============================================================
  450. //函数名: void Draw_BMP(byte x,byte y)
  451. //功能描述:显示BMP图片128×64
  452. //参数:起始点坐标(x,y),x的范围0~127,y为页的范围0~7
  453. //返回:无
  454. //==============================================================
  455. void Draw_BMP(unsigned char  x0,unsigned char  y0,unsigned char  x1,unsigned char  y1,unsigned char bmp[])
  456. {        
  457.   unsigned int  ii=0;
  458.   unsigned char  x,y;
  459.   
  460.           if(y1%8==0) y=y1/8;      
  461.           else y=y1/8+1;
  462.         for(y=y0;y<=y1;y++)
  463.         {
  464.                 LCD_Set_Pos(x0,y);                               
  465.             for(x=x0;x<x1;x++)
  466.             {      
  467.                     LCD_WrDat(bmp[ii++]);                   
  468.             }
  469.         }
  470. }
main.c
  1. #include<reg51.h>
  2. #include"OLED.H"

  3. extern unsigned char code Dot[];

  4. void main(void)
  5. {
  6.         LCD_Init();
  7.      LCD_CLS();
  8.         LCD_P8x16Str(45,5,(u8*)"EASEAR");
  9.         LCD_P6x8Str(0,7,(u8*)"www.holteksupport.com");
  10.         Draw_BMP(0,0,100,3,(u8*)Dot);
  11.         while(1)
  12.         {
  13.         }
  14. }
效果图:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

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

本版积分规则

470

主题

3537

帖子

7

粉丝
快速回复 在线客服 返回列表 返回顶部