标题: 关于单片机+12864显示图像一直乱码的问题 [打印本页]

作者: Yosuga    时间: 2019-12-7 10:41
标题: 关于单片机+12864显示图像一直乱码的问题
想用12864显示图像 但是图像一直乱码 想问问大神是哪里出了问题
  1. #include <reg51.h>
  2. #include <intrins.h>

  3. sbit LCD_RS=P3^5;//定义引脚
  4. sbit LCD_RW=P3^6;
  5. sbit LCD_E=P3^4;
  6. sbit PSB =P3^7;

  7. #define LCD_Data P0
  8. #define Busy    0x80
  9. #define uchar unsigned char
  10. #define uint unsigned int
  11.         
  12. code uchar tmp[] ={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  13. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  14. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  15. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xD4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  16. 0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  17. 0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  18. 0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  19. 0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  20. 0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  21. 0x00,0x00,0x03,0x50,0x00,0x50,0x80,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  22. 0x00,0x00,0x3C,0x04,0x00,0xA0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  23. 0x00,0x00,0x40,0x01,0x0B,0x15,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  24. 0x00,0x00,0x40,0x00,0x88,0x00,0x00,0x06,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  25. 0x00,0x01,0x80,0x00,0x60,0x00,0x00,0x05,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  26. 0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x03,0x90,0x00,0x01,0xB6,0x36,0x00,0x00,0x00,
  27. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x40,0x00,0x01,0xFE,0x36,0x00,0x00,0x00,
  28. 0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x02,0x20,0x00,0x01,0xB6,0x36,0x00,0x00,0x00,
  29. 0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x02,0xA0,0x00,0x03,0x6F,0xFF,0x00,0x00,0x00,
  30. 0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x1D,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,
  31. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0xC0,0x00,0x00,0x00,0x28,0x00,0x00,0x00,
  32. 0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x38,0x00,0x00,0x00,
  33. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0A,0x80,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
  34. 0x00,0x00,0x10,0x80,0x00,0x00,0x1F,0x08,0x47,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,
  35. 0x00,0x00,0x01,0x20,0x00,0x00,0x3D,0x13,0x0C,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,
  36. 0x00,0x00,0x08,0x10,0x00,0x00,0x27,0xA0,0x18,0x06,0x00,0x00,0x00,0x00,0x00,0x00,
  37. 0x00,0x00,0x02,0x10,0x00,0x00,0x3F,0x80,0x38,0xC7,0x00,0x00,0x00,0x00,0x00,0x00,
  38. 0x00,0x00,0x04,0x03,0xE0,0x00,0x33,0x90,0x3F,0xC7,0x00,0x00,0x00,0x00,0x00,0x00,
  39. 0x00,0x00,0x00,0x03,0xB0,0x00,0x33,0x10,0x7F,0x87,0x00,0x00,0x00,0x00,0x00,0x00,
  40. 0x00,0x00,0x08,0x24,0xF0,0x0C,0x0E,0x00,0xFF,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,
  41. 0x00,0x00,0x00,0x07,0xF0,0xC2,0x00,0x00,0xFE,0x1F,0x81,0xB3,0xE6,0xD8,0xF0,0x00,
  42. 0x00,0x00,0x08,0x46,0x71,0x06,0x00,0x08,0x3F,0x1F,0x01,0xF6,0x67,0xF9,0xB0,0x00,
  43. 0x00,0x00,0x00,0x03,0x20,0x98,0x00,0x00,0x3F,0xFF,0x01,0xB6,0xC6,0xD9,0x80,0x00,
  44. 0x00,0x00,0x08,0x40,0xC0,0x24,0x00,0x04,0x3F,0x1F,0x03,0x7F,0xFD,0xBE,0xFC,0x00,
  45. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x1E,0x1E,0x00,0x00,0x00,0x00,0x00,0x00,
  46. 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x01,0x0E,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,
  47. 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x87,0xF0,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,0x04,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  50. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  51. 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52. 0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  53. 0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,
  54. 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x02,0x08,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,
  55. 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
  56. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x88,0x00,0x01,0x8C,0x00,0x00,0x00,0x00,
  57. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x01,0x8E,0x00,0x00,0x00,0x00,
  58. 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x01,0x00,0x00,0x01,0xB6,0x06,0xDB,0x6C,0x00,
  59. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xFF,0x06,0xDB,0x6C,0x00,
  60. 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  62. 0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  63. 0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  64. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65. 0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  66. 0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67. 0x00,0x00,0x00,0x00,0x40,0x00,0x01,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68. 0x00,0x00,0x00,0x00,0x94,0xA4,0x68,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69. 0x00,0x00,0x00,0x00,0x02,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  70. 0x00,0x00,0x00,0x00,0x42,0x00,0x10,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71. 0x00,0x00,0x00,0x00,0x20,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72. 0x00,0x00,0x00,0x00,0x14,0x00,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  75. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  76. };


  77. void delay (uint z)
  78. {
  79.         uint x,y;
  80.         for (x = z; x > 0; x--)
  81.                 for(y = 144; y > 0; y--);
  82. }

  83. //检测忙
  84. uchar ReadStatusLCD(void)
  85. {
  86.         LCD_Data = 0xFF;
  87.         LCD_RS = 0;
  88.         LCD_RW = 1;
  89.         LCD_E = 1;
  90.         while (LCD_Data & Busy); //检测忙信号
  91.         LCD_E = 0;
  92.         return(LCD_Data);
  93. }

  94. //写数据
  95. void WriteDataLCD(uchar WDLCD)
  96. {
  97.         ReadStatusLCD(); //检测忙
  98.         LCD_RS = 1;
  99.         LCD_RW = 0;
  100.         LCD_Data = WDLCD;
  101.         LCD_E = 1;
  102.         LCD_E = 1;
  103.         LCD_E = 1;
  104.         LCD_E = 0;
  105. }

  106. //写指令
  107. void WriteCommandLCD(uchar WCLCD)
  108. {
  109.         ReadStatusLCD();//检测忙
  110.         LCD_RS = 0;
  111.         LCD_RW = 0;
  112.         LCD_Data = WCLCD;
  113.         LCD_E = 1;
  114.         LCD_E = 1;
  115.         LCD_E = 1;
  116.         LCD_E = 0;  
  117. }

  118. //读数据
  119. uchar ReadDataLCD(void)
  120. {
  121.         LCD_RS = 1;
  122.         LCD_RW = 1;
  123.         LCD_E = 0;
  124.         LCD_E = 0;
  125.         LCD_E = 1;
  126.         return(LCD_Data);
  127. }


  128. void LCDInit(void) //LCD初始化
  129. {
  130.         WriteCommandLCD(0x30); //基本指令集
  131.         WriteCommandLCD(0x01); //显示清屏
  132.         WriteCommandLCD(0x06); //显示光标移动设置
  133.         WriteCommandLCD(0x0C); //显示开及光标设置
  134. }


  135. void LCDClear(void) //清屏
  136. {
  137.   WriteCommandLCD(0x01); //显示清屏
  138.   WriteCommandLCD(0x34); // 显示光标移动设置
  139.   WriteCommandLCD(0x30); // 显示开及光标设置
  140. }

  141. //图形显示
  142. void DisplayImage (uchar code *DData)
  143. {
  144.         uchar i,j;
  145.         WriteCommandLCD(0x34);//打开扩充指令
  146.         for(i = 0; i < 32; i++)
  147.         {        
  148.                 WriteCommandLCD(0x80 + i);//垂直地址
  149.                 WriteCommandLCD(0x30);//水平地址
  150.                 for (j = 0; j < 16; j++)
  151.                 {
  152.                         WriteDataLCD(*DData);
  153.                         DData++;
  154.                 }
  155.         }
  156.         for(i = 0; i < 32; i++)
  157.         {        
  158.                 WriteCommandLCD(0x80 + i);//垂直地址
  159.                 WriteCommandLCD(0x30);//水平地址
  160.                 for (j = 0; j < 16; j++)
  161.                 {
  162.                         WriteDataLCD(*DData);
  163.                         DData++;
  164.                 }
  165.         }
  166.         WriteCommandLCD(0x36);//打开绘图模式
  167.         WriteCommandLCD(0x30); //基本指令
  168. }

  169. ////串口初始化
  170. //void UARTinit()
  171. //{
  172. //        EA = 1;//开总中断
  173. //        ES = 1;//串口中断
  174. //        SM0 = 0;
  175. //        SM1 = 1;//串口工作方式
  176. //        REN = 1;//允许串口接收
  177. //        TR1 = 1;//启动定时器1
  178. //        TMOD = 0x20;//定时器1工作模式2
  179. //        TH1 = 0xfd;
  180. //        TL1 = 0xfd;
  181. //}

  182. ////串口中断函数
  183. //void UART() interrupt 4
  184. //{
  185. //        uchar i;
  186. //        i = 0;
  187. //        if(RI)
  188. //        {
  189. //                tmp[i] = SBUF;
  190. //                RI = 0;//软件清零
  191. //                i++;
  192. //                if(i >= 1024)
  193. //                        i = 0;
  194. //        }
  195. //}

  196. void main()
  197. {
  198. //        UARTinit();
  199.         P0 = 0;
  200.         LCDInit();        
  201.         LCDClear();
  202.         while(1)
  203.         {
  204.                 DisplayImage(tmp);
  205.                 while(1);
  206.         }
  207. }
复制代码


作者: 51hei**1140    时间: 2019-12-7 12:10
如果显示乱码,一般和取模方向有关
作者: moluxiyan    时间: 2019-12-7 17:04
显示其他字符是否正常
作者: 这是我    时间: 2020-2-21 13:36
仔细看了下显示图片的子程序,觉得和我手头上所用HD529M1型号的12864很象,便复制整个程序到我的开发板里试了试,显示果然是乱糟糟的:

作者: 这是我    时间: 2020-2-21 13:43
反复试了几次,还是不行,静下心来读程序,终于发现小问题,水平地址0x30有误,应该分别改为0x80和0x88,一切OK:


作者: 这是我    时间: 2020-2-21 13:55
这几天研究12864的心得就是:有12864的问题要问,一定要给出具体型号,不然就只能自己查找资料,别人没用过的话很难帮上忙。换句话说,学习的话一定要用大众型号的12864,或者对着手头例程买。
我的12864是好多年前朋友送的,一直吃灰中,疫期期间出不去,翻出来玩玩,好在坛子里找到了例程。
作者: 难打狗    时间: 2022-11-29 16:20
你好,我的图片一直左右颠倒了,但是明明用的图形取模正常,请问您的图片取模是什么取模方向呢?




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1