找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2507|回复: 0
收起左侧

ST7565驱动芯片SPI串口通讯 单片机程序代码

[复制链接]
ID:705815 发表于 2020-10-21 11:47 | 显示全部楼层 |阅读模式
  1. //型号T12864C048B
  2. #include <reg51.h>
  3. #include <intrins.h>
  4. #include <absacc.h>
  5. #define uchar unsigned char
  6. #define  uint unsigned int

  7. sfr  CLK_DIV        =0x97;
  8. sfr  P1M1           =0x91;
  9. sfr  P1M0           =0x92;
  10. sfr  P3M1           =0xB1;
  11. sfr  P3M0           =0xB2;


  12.                                                                                           
  13. sbit        R_S=        P3^5;//指令/数据选择信号
  14. sbit        RES=        P3^4;//复位信号
  15. sbit        SCK=         P1^6;
  16. sbit        SDA=        P1^7;
  17. sbit    CS1=    P3^7;//片选
  18. bit     Flage1=0;


  19. void LcdInit();        
  20. void Clear();        
  21. void Delayms(uint ms);        
  22. void Comwrite(uchar cmd);        
  23. void Datwrite(uchar dat);        

  24. void Setadd(uchar xl,uchar yl);
  25. void disp_str(unsigned char *p,unsigned char uCol,uPage);        
  26. unsigned char CurOffset;
  27. /*
  28. #define LEFT 0
  29. #define RIGHT 1
  30. #define CMD 0
  31. #define DATA 1
  32. */
  33. #define ASC_CHR_WIDTH        8
  34. #define ASC_CHR_HEIGHT        12

  35. typedef struct typFNT_ASC16        
  36. {
  37.     char Index[1];
  38.     char Msk[16];
  39. };

  40. code struct typFNT_ASC16  ASC_16[] =
  41. {        
  42. "1",0x00,0x00,0x08,0x08,0xFC,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0x07,0x04,0x04,0x00,
  43. "2",0x00,0x00,0x08,0x04,0x84,0x44,0x38,0x00,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x00,
  44. "3",0x00,0x00,0x08,0x04,0x44,0x44,0xB8,0x00,0x00,0x00,0x02,0x04,0x04,0x04,0x03,0x00,
  45. "4",0x00,0x00,0x80,0x60,0x18,0xFC,0x00,0x00,0x00,0x00,0x01,0x01,0x05,0x07,0x05,0x00,
  46. "5",0x00,0x00,0x7C,0x44,0x44,0x44,0x84,0x00,0x00,0x00,0x02,0x04,0x04,0x04,0x03,0x00,
  47. "6",0x00,0x00,0xF0,0x48,0x44,0x44,0x80,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x03,0x00,
  48. "7",0x00,0x00,0x0C,0x04,0x84,0x64,0x1C,0x00,0x00,0x00,0x00,0x06,0x01,0x00,0x00,0x00,
  49. "8",0x00,0x00,0xB8,0x44,0x44,0x44,0xB8,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x03,0x00,
  50. "9",0x00,0x00,0x38,0x44,0x44,0x44,0xF8,0x00,0x00,0x00,0x00,0x04,0x04,0x02,0x01,0x00,
  51. "0",0x00,0x00,0xF8,0x04,0x04,0x04,0xF8,0x00,0x00,0x00,0x03,0x04,0x04,0x04,0x03,0x00,
  52. };


  53. #define ASC_HZ_WIDTH        16
  54. //#define ASC_HZ_HEIGHT        12

  55. typedef struct typFNT_GB16        
  56. {
  57.         char Index[2];
  58.         char Msk[32];
  59. };
  60. /*code struct typFNT_GB16  GB_16[] = {

  61. "欢", 0x04,0x34,0xC4,0x04,0xC4,0x3C,0x20,0x10,0x0F,0xE8,0x08,0x08,0x28,0x18,0x00,0x00,
  62.       0x10,0x08,0x06,0x01,0x82,0x8C,0x40,0x30,0x0C,0x03,0x0C,0x10,0x60,0xC0,0x40,0x00,

  63. "迎", 0x40,0x42,0x44,0xC8,0x00,0xFC,0x04,0x02,0x82,0xFC,0x04,0x04,0x04,0xFE,0x04,0x00,
  64.       0x00,0x40,0x20,0x1F,0x20,0x47,0x42,0x41,0x40,0x7F,0x40,0x42,0x44,0x63,0x20,0x00,

  65. "使", 0x40,0x20,0xF8,0x07,0x04,0xF4,0x14,0x14,0x14,0xFF,0x14,0x14,0x14,0xF6,0x04,0x00,
  66.       0x00,0x00,0xFF,0x00,0x80,0x43,0x45,0x29,0x19,0x17,0x21,0x21,0x41,0xC3,0x40,0x00,

  67. "用", 0x00,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x22,0x22,0x22,0x22,0xFF,0x02,0x00,0x00,
  68.       0x80,0x60,0x1F,0x02,0x02,0x02,0x02,0x7F,0x02,0x02,0x42,0x82,0x7F,0x00,0x00,0x00,

  69. "黑", 0x00,0x00,0xFE,0x8A,0x92,0xB2,0x82,0xFE,0x82,0xA2,0x9A,0x92,0xFF,0x02,0x00,0x00,
  70.       0x08,0x8A,0x6A,0x0A,0x2A,0xCA,0x0A,0x0F,0x2A,0xCA,0x0A,0x2A,0x4A,0xCA,0x08,0x00,

  71. "白", 0x00,0x00,0xF8,0x08,0x0C,0x0A,0x09,0x08,0x08,0x08,0x08,0x08,0xFC,0x08,0x00,0x00,
  72.       0x00,0x00,0x7F,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x21,0x7F,0x00,0x00,0x00,

  73. "点", 0x00,0x00,0xC0,0x40,0x40,0x40,0x7F,0x48,0x48,0x48,0x48,0xE8,0x4C,0x08,0x00,0x00,
  74.       0x80,0x40,0x37,0x04,0x14,0x64,0x04,0x14,0x24,0x64,0x04,0x17,0x20,0xC0,0x00,0x00,

  75. "阵", 0x00,0xFE,0x22,0x5A,0x86,0x04,0x84,0xE4,0x9F,0x84,0xF4,0x84,0xC4,0x86,0x04,0x00,
  76.       0x00,0xFF,0x04,0x08,0x07,0x08,0x08,0x08,0x08,0x08,0xFF,0x08,0x08,0x0C,0x08,0x00,

  77. "液", 0x10,0x22,0x64,0x0C,0x80,0x04,0xC4,0x34,0x05,0xC6,0xBC,0x24,0x24,0xE6,0x04,0x00,
  78.       0x04,0x04,0xFE,0x01,0x02,0x01,0xFF,0x42,0x21,0x16,0x08,0x15,0x23,0x60,0x20,0x00,

  79. "晶", 0x00,0x00,0x00,0x00,0xFF,0x49,0x49,0x49,0x49,0x49,0xFF,0x00,0x00,0x80,0x00,0x00,
  80.       0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x00,0xFF,0x49,0x49,0x49,0x49,0xFF,0x01,0x00,

  81. "屏", 0x00,0x00,0xFE,0x12,0x92,0x92,0xB2,0xD2,0x92,0xD2,0xB2,0x92,0xDF,0x82,0x00,0x00,
  82.       0x40,0x20,0x1F,0x04,0x84,0x44,0x3F,0x04,0x04,0x04,0xFF,0x04,0x04,0x06,0x04,0x00,

  83. "显", 0x00,0x00,0x00,0xFE,0x92,0x92,0x92,0x92,0x92,0x92,0x92,0xFF,0x02,0x00,0x00,0x00,
  84.       0x40,0x42,0x44,0x4D,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x49,0x44,0x66,0x40,0x00,

  85. "示", 0x40,0x40,0x42,0x42,0x42,0x42,0x42,0xC2,0x42,0x42,0x42,0x43,0x42,0x60,0x40,0x00,
  86.       0x00,0x10,0x08,0x04,0x06,0x40,0x80,0x7F,0x00,0x00,0x02,0x04,0x0C,0x18,0x00,0x00,

  87. "汉", 0x10,0x22,0x64,0x0C,0x80,0x04,0x74,0x84,0x04,0x04,0x04,0xC4,0x3E,0x04,0x00,0x00,
  88.       0x04,0x04,0x7E,0x01,0x80,0x40,0x20,0x11,0x0A,0x04,0x0B,0x10,0x60,0xC0,0x40,0x00,

  89. "字", 0x00,0x10,0x0C,0x24,0x24,0x24,0x25,0x26,0xA4,0x64,0x24,0x04,0x14,0x0C,0x00,0x00,
  90.       0x02,0x02,0x02,0x02,0x02,0x42,0x82,0x7F,0x02,0x02,0x02,0x02,0x02,0x03,0x02,0x00,

  91. "测", 0x10,0x22,0x6C,0x00,0x80,0xFC,0x04,0xF4,0x04,0xFE,0x04,0xF8,0x00,0xFE,0x00,0x00,
  92.       0x04,0x04,0xFE,0x01,0x40,0x27,0x10,0x0F,0x10,0x67,0x00,0x47,0x80,0x7F,0x00,0x00,

  93. "试", 0x40,0x42,0xCC,0x00,0x10,0x90,0x90,0x90,0x90,0x90,0xFF,0x10,0x12,0x14,0x10,0x00,
  94.       0x00,0x00,0x7F,0x20,0x10,0x20,0x60,0x3F,0x10,0x10,0x01,0x3E,0x40,0x80,0x70,0x00



  95. };

  96. */


  97. uchar code Hanzi[]={
  98. /*--  调入了一幅图像:F:\技术支持\测试程序\黑白图片\马2.bmp  --*/
  99. /*--  宽度x高度=128x64  --*/
  100. 0x04,0xF4,0x54,0x5F,0x54,0xF4,0x44,0x30,0x4C,0x4B,0xC8,0x48,0x0C,0x08,0x00,0x00,
  101. 0x00,0x00,0xFE,0x92,0x92,0x92,0xFE,0x92,0x92,0x92,0xFF,0x02,0x00,0x00,0x20,0x21,
  102. 0xE6,0x00,0x00,0xF8,0x48,0x48,0xFF,0x48,0x48,0x48,0xFC,0x08,0x00,0x00,0x00,0x00,
  103. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  104. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  105. 0x80,0x80,0x50,0xD0,0xA4,0xE4,0xC8,0xD8,0xF8,0xF8,0xF4,0xF8,0xF8,0xF8,0xF0,0xF0,
  106. 0xF0,0xF0,0xF0,0xE0,0x60,0x40,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xE0,0x20,0xE0,0xE0,
  107. 0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  108. 0x04,0x05,0x05,0x3F,0x05,0x05,0x04,0x00,0x1C,0x23,0x20,0x20,0x20,0x3C,0x00,0x00,
  109. 0x10,0x0C,0x01,0x1E,0x20,0x21,0x22,0x24,0x20,0x20,0x3A,0x04,0x08,0x00,0x10,0x08,
  110. 0x07,0x08,0x10,0x27,0x24,0x24,0x27,0x24,0x24,0x24,0x27,0x20,0x00,0x00,0x00,0x00,
  111. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  112. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x44,0x44,
  113. 0xC2,0x6B,0x6F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF7,0xF0,0xF1,0xC1,0x61,
  114. 0x71,0x71,0xF0,0xF4,0xAC,0xEC,0xEC,0x6E,0x7A,0x3F,0x1F,0x0F,0x1F,0x1F,0x1D,0x1D,
  115. 0x1D,0x05,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  116. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  117. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  118. 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x80,
  119. 0x80,0x80,0xC0,0xC0,0xC0,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  120. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,0x80,0xC5,
  121. 0xE5,0xF7,0xF7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0x2F,0x47,
  122. 0xD7,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xBC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  123. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  124. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  125. 0x00,0x00,0x00,0x00,0x08,0x18,0xD0,0xF0,0xF0,0xE0,0xE0,0xE0,0xE5,0xEC,0xEC,0xFA,
  126. 0xDE,0xFE,0xFC,0xFF,0xFD,0xFF,0xFE,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,
  127. 0xFF,0xFF,0xFF,0x3F,0x3F,0x1F,0x1F,0x0F,0x0F,0x07,0x07,0x07,0x07,0x07,0x07,0x07,
  128. 0x0F,0x0E,0x0E,0x1C,0x1C,0x1C,0x1C,0x18,0x18,0x38,0x38,0x1C,0x1D,0x1D,0x1D,0x2F,
  129. 0x3F,0x9F,0x9F,0x8F,0x8F,0x07,0x03,0x03,0x05,0x16,0x0F,0x07,0xA7,0xE2,0xF0,0xFD,
  130. 0x3F,0x5F,0xDF,0xFF,0xFF,0xFF,0x0F,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  131. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  132. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  133. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
  134. 0x01,0x01,0x07,0x07,0x07,0x07,0x07,0x07,0x87,0xC3,0xEB,0xCF,0xC3,0xC3,0xE0,0xF4,
  135. 0x7F,0x3F,0x15,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xFC,0xFC,0xF8,0xC0,0xE8,0xFC,
  136. 0xFC,0xC0,0xC0,0x80,0x20,0xC0,0xD4,0xD4,0xFE,0xFF,0xF7,0xF6,0xF0,0xFC,0xFC,0xFE,
  137. 0xF3,0xFF,0xF7,0xC3,0x81,0x00,0x38,0x3C,0xFC,0xFC,0xFC,0xEC,0xE5,0xED,0xFF,0xD5,
  138. 0xC5,0xF9,0xF9,0xBF,0xBF,0xFF,0xDF,0xF8,0xFC,0x7E,0x26,0x36,0x36,0x1E,0x1E,0x1C,
  139. 0x3C,0x78,0xF0,0xF0,0xE0,0xE0,0xC0,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,
  140. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  141. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  142. 0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x90,0xFF,0xFF,0xFF,0xF9,0xFD,0x8F,0x0F,0x0D,
  143. 0x0C,0x0C,0x1C,0x1C,0x18,0x18,0x18,0x1C,0x1E,0x0F,0x07,0x03,0x03,0x0F,0x0F,0x1F,
  144. 0x1F,0x3F,0x7F,0xFF,0xFE,0xDE,0xDE,0x9F,0x3F,0x3F,0x7E,0xFF,0xDF,0xBF,0x3F,0x3F,
  145. 0x3F,0x3F,0x1F,0x1F,0x1F,0x1F,0x1F,0x3E,0x3C,0x6F,0x7D,0xFD,0xF9,0xF3,0xD7,0xCF,
  146. 0xDF,0xBB,0x57,0xC3,0x83,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  147. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x0F,0x1F,0x03,0x22,0x26,0x2C,0x10,
  148. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  149. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,
  150. 0x06,0x1F,0x33,0x3B,0x3F,0x13,0x1F,0x0F,0x07,0x07,0x03,0x01,0x00,0x00,0x00,0x00,
  151. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  152. 0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x07,0x07,0x06,0x05,0x0D,0x1B,0x3E,0x36,
  153. 0x7C,0x78,0x78,0xF0,0xE0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,
  154. 0x03,0x07,0x0E,0x0E,0x1F,0x1F,0x3F,0x3E,0x7E,0xFC,0xF0,0xE0,0xC0,0x80,0x80,0x00,
  155. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  156. 0x02,0x02,0xFE,0x02,0x02,0x00,0xFE,0x12,0x12,0x32,0xCC,0x00,0x00,0x7E,0x80,0x80,
  157. 0x80,0x7E,0x00,0x00,0x4C,0x92,0x92,0x64,0x00,0x02,0x02,0xFE,0x02,0x02,0x00,0x02,
  158. 0x0C,0xF0,0x0C,0x02,0x00,0x00,0xFE,0x80,0x80,0x80,0x00,0x7C,0x82,0x82,0x82,0x44,
  159. 0x00,0x00,0xFE,0x82,0x82,0x82,0x7C,0x00,0x00,0x80,0x00,0x00,0x7C,0x82,0x82,0x82,
  160. 0x44,0x00,0x00,0x7C,0x82,0x82,0x82,0x7C,0x00,0xFE,0x0C,0x70,0x80,0x70,0x0C,0xFE,
  161. 0x00,0x00,0x00,0x00,0x01,0x03,0x0F,0x0F,0x1F,0x7F,0x7E,0x36,0x46,0x4E,0x6C,0x68,
  162. 0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x07,0x0F,0x6F,
  163. 0xEF,0xDF,0xDE,0xDA,0xD8,0xF8,0xE0,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,


  164. };


  165. void Display(unsigned char sda,unsigned char sda1)
  166. {
  167.    unsigned char  i,j,k=0;
  168.    for(i=0;i<8;i++)   
  169.     {
  170.      Comwrite(0xb0+k);           
  171.           Comwrite(0x10);
  172.          Comwrite(0x00);         
  173.        for(j=0;j<64;j++)
  174.           { Datwrite(sda);
  175.             Datwrite(sda1);
  176.           }
  177.     k++;
  178.     }
  179. }


  180. void Hanzi_Disp(void)
  181. {
  182.    unsigned char  i,j,k=0;
  183.    for(i=0;i<8;i++)   
  184.     {
  185.      Comwrite(0xb0+k);           
  186.           Comwrite(0x10);
  187.          Comwrite(0x00);        //0x04>0x00  
  188.        for(j=0;j<128;j++)
  189.           {Datwrite(Hanzi[i*128+j]);
  190.           }

  191.     k++;
  192.     }
  193. }     



  194. void main()
  195. {        
  196.    P1M1=0x00;
  197.    P1M0=0xff;
  198.    P3M1=0x00;
  199.    P3M0=0xff;
  200.    CLK_DIV=0x02;
  201.    LcdInit();

  202.    while(1)
  203.         {
  204.           Clear();
  205.       Display(0xff,0xff);
  206.           Delayms(5000);

  207.       Display(0x55,0xaa);
  208.           Delayms(5000);

  209.       Display(0x00,0xff);
  210.           Delayms(5000);

  211.       Display(0xaa,0xaa);
  212.           Delayms(5000);

  213.       Display(0x55,0x55);
  214.           Delayms(5000);         

  215.          Hanzi_Disp();
  216.          Delayms(5000);
  217.          Delayms(5000);
  218. /*          Clear();
  219.         disp_str("测试",0,0);Delayms(1000);
  220.         disp_str("测试",96,0);Delayms(1000);
  221.         disp_str("测试",48,3);Delayms(1000);
  222.         disp_str("测试",96,0);Delayms(1000);
  223.         disp_str("测试",0,6);Delayms(1000);
  224.         disp_str("测试",96,6);Delayms(1000);
  225.         Delayms(4000);Delayms(4000);
  226.     Clear();
  227.         Flage1=0;
  228.         disp_str("黑白液晶屏测试点",0,0);
  229.         disp_str("黑白液晶屏测试点",0,2);        
  230.         disp_str("黑白液晶屏测试点",0,4);
  231.         disp_str("189024550071234",0,6);
  232.         Delayms(5000);Delayms(5000);
  233. */
  234.         }
  235.         
  236. }



  237. void Delayms(uint ms)
  238. {        
  239.         uchar j;
  240.         while(ms--)
  241.           for(j=0;j<=20;j++);   
  242.                            
  243. }               
  244.         
  245. void Comwrite(uchar cmd)
  246. {
  247.     uchar data i,j;
  248.             CS1=0;
  249.             R_S=0;  
  250.         SCK=1;
  251.         for(i=0;i<8;i++)
  252.             {
  253.                  j=cmd;
  254.                  SCK=0;
  255.                  SDA=cmd&0x80;
  256.          SCK=1;            
  257.                  cmd=j<<1;
  258.                 }
  259.             CS1=1;
  260.                 R_S=1;
  261. }


  262. void Datwrite(uchar dat)        
  263. {                                                        
  264.     uchar data i,j;
  265.             CS1=0;
  266.             R_S=1;  
  267.         SCK=1;
  268.         for(i=0;i<8;i++)
  269.             {
  270.                  j=dat;
  271.                  SCK=0;
  272.                  SDA=dat&0x80;
  273.          SCK=1;            
  274.                  dat=j<<1;
  275.                 }
  276.             CS1=1;
  277.                 R_S=0;
  278. }

  279. void Clear()
  280. {
  281.    unsigned char  i,j,m=0;
  282.    for(i=0;i<8;i++)   
  283.     {
  284.      Setadd(0,i);                     
  285.      for(j=0;j<128;j++)
  286.           Datwrite(0x00);
  287.      }
  288. }


  289. void Setadd(uchar xl,uchar yl)
  290. {    uchar i;
  291.      i=(xl+0)&0x0f;    //i=(xl+0)&0x0f;(SEG0~SEG127)  // i=(xl+4)&0x0f;(SEG4~SEG131)
  292.      xl=(xl>>4)+0x10;

  293.      Comwrite(0xb0+yl);           
  294.          Comwrite(xl);
  295.           Comwrite(i);        
  296. }

  297. void LcdInit()
  298. {
  299.      RES=1;
  300.      Delayms(50);
  301.      RES=0;
  302.      Delayms(50);
  303.      RES=1;
  304.      Delayms(50);

  305.      Comwrite(0xE2);          //Software Reset
  306.      Delayms(50);
  307.      Comwrite(0xA2);          //Set Bias     0xA3 1/7bias,  0xA2 1/9 bias
  308.      Comwrite(0xA0);          //Segment Direction Select       bit0=0,normal ,=1,reverse
  309.      Comwrite(0xC8);          //Common Direction Select        bit3=0,normal ,=1,revese
  310.      Comwrite(0xA8);
  311.      Comwrite(0xA6);
  312.      Comwrite(0xA4);
  313.      Comwrite(0x23);          //调电压 对比度  Set internal rb/ra        0x24
  314.      Comwrite(0x81);          //Set Contrast     
  315.      Comwrite(0x30);          //调电压 对比度 1a>1f
  316.      Comwrite(0x2F);          //Power Control Set
  317.      Delayms(5000);                        //delay 40mS

  318.      Comwrite(0x40);          //Set Display Start Line   
  319.      Comwrite(0xAF);          //Display ON
  320. }
  321.         




  322. void disp_ch(unsigned char c,uCol,uPage)
  323. {
  324.         unsigned char k,j,ch_w;
  325.         unsigned char width;
  326.         unsigned char len;

  327.         len=sizeof(ASC_16)/sizeof(ASC_16[0]);
  328.         for(k=0;k<len;k++)
  329.         {
  330.                 if(c == ASC_16[k].Index[0] ) break;
  331.         }
  332.         if(k<len)
  333.         {
  334.                
  335.                 if(c=='-'||c==':')
  336.                         width=ASC_CHR_WIDTH-2;
  337.                 else if(c=='|')
  338.                         width=ASC_HZ_WIDTH-ASC_CHR_WIDTH;
  339.                 else
  340.                         width=ASC_CHR_WIDTH;
  341.                
  342.                    Setadd(uCol,uPage);
  343.                         for(j=0;j<width;j++)
  344.                         {
  345.                                 ch_w=ASC_16[k].Msk[j];                                
  346.                                 Datwrite(ch_w);
  347.                         }

  348.                         Setadd(uCol,uPage+1);
  349.                         for(j=0;j<width;j++)
  350.                         {
  351.                                 ch_w=ASC_16[k].Msk[ASC_CHR_WIDTH+j];
  352.                                 Datwrite(ch_w);
  353.                         }               
  354.         }
  355. }
  356. /*

  357. void disp_hz(unsigned char *hz,uCol,uPage)
  358. {
  359.         unsigned char k,j,ch_w;
  360.     //sizeof 用来求一个变量或者一种类型所占用的字节数
  361.         for(k=0;k<sizeof(GB_16)/sizeof(GB_16[0]);k++)
  362.         {
  363.                 if(hz[0] == GB_16[k].Index[0] && hz[1] == GB_16[k].Index[1])
  364.                         break;
  365.         }

  366.         Setadd(uCol,uPage);
  367.         for(j=0;j<ASC_HZ_WIDTH;j++)
  368.         {               
  369.                 ch_w=GB_16[k].Msk[j];
  370.                 Datwrite(ch_w);
  371.         }

  372.         Setadd(uCol,uPage+1);
  373.         for(j=0;j<ASC_HZ_WIDTH;j++)
  374.         {
  375.                 ch_w=GB_16[k].Msk[ASC_HZ_WIDTH+j];
  376.                 Datwrite(ch_w);
  377.         }
  378. }

  379. */

  380. void disp_str(unsigned char *p,unsigned char uCol,uPage)
  381. {
  382.         unsigned char i=0;
  383.         while(p[i]>0)
  384.         {
  385.                 if(p[i] < 128)
  386.                 {        
  387.                         disp_ch(p[i],uCol,uPage);
  388.             uCol+=8;
  389.                 }
  390. /*                else
  391.                 {        
  392.                         disp_hz(&p[i],uCol,uPage);
  393.                         uCol+=16;
  394.                         i++;
  395.                 }
  396. */                if(Flage1==1) Delayms(200);
  397.                 i++;
  398.         }
  399. }
复制代码
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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