找回密码
 立即注册

QQ登录

只需一步,快速开始

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

普中lcd12864参考程序与pdf资料下载,带背景点阵屏

[复制链接]
跳转到指定楼层
楼主
这个屏幕资料不是很多,这是自己写的,给各位新手参考,


单片机源程序如下:
  1. #include "st7565p.h"
  2. //#include "charcode.h"

  3. // 类似8080接口
  4. extern struct CharCodeTypedef{
  5.         unsigned char CharWord;
  6.         unsigned char Ecode[16];
  7. };
  8. extern struct CNCodeTypedef
  9. {
  10.         unsigned char HZ[2];
  11.         unsigned char HZcode[32];
  12. };

  13. extern struct CharCodeTypedef code letter[74];
  14. extern struct CNCodeTypedef code hanzi[3];

  15. void Init_st7565p(void)
  16. {
  17.   unsigned int i;
  18.         LCD_PZ12864_CS = 0;
  19.         LCD_PZ12864_RSET = 0;
  20.         for (i=0; i<2000; i++);

  21.         LCD_PZ12864_RSET = 1;
  22.        
  23.         WriteCmd_st7565(0xe2); // (14) Internal reset
  24.         for (i=0; i<100; i++);           //延时一下
  25.        
  26.         WriteCmd_st7565(0xa0); // (8) ADC select : normal , 0xa0: normal, 0xa1: reverse
  27.        
  28.         WriteCmd_st7565(0xc8); // (15) Common output mode select : normal,  0xc8:reverse direction, 0xc7: normal direction
  29.        
  30.         WriteCmd_st7565(0xa6); // (9) Display normal, 0xa6: normal, 0xa7: reverse
  31.        
  32.         WriteCmd_st7565(0xa4); // (10) 0xa5: all points on, 0xa4: all points off
  33.        
  34.         WriteCmd_st7565(0xa2); // (11) bias set : 1/7 ,  0xa2:1/9, 0xa3:1/7  区别不大。。
  35.        
  36.         WriteCmd_st7565(0xf8); // (20)
  37.   WriteCmd_st7565(0x01);
  38.        
  39.         WriteCmd_st7565(0x81); // (18)
  40.         WriteCmd_st7565(0x23);
  41.        
  42.         WriteCmd_st7565(0x25); // (17) Select internal resistor ratio(Rb/Ra) mode
  43.        
  44.         WriteCmd_st7565(0x2f); // (16) Select internal power supply operating mode
  45.                 for (i=0; i<100; i++);
  46.                
  47.         WriteCmd_st7565(0x40); // (2)        Set the display RAM display start line address  0x40 + (0-63)
  48.        
  49.         WriteCmd_st7565(0xaf); // (1) display on/off ,  0xaf: on, 0xae: off
  50.         for (i=0; i<100; i++);
  51. }

  52. void ClearScreen(void)
  53. {
  54.         unsigned char i,j;
  55.         for(i = 0; i < 8; i++)
  56.         {
  57.                 WriteCmd_st7565(0xb0 + i); //y
  58.                
  59.                 WriteCmd_st7565(0x10);
  60.                 WriteCmd_st7565(0x00);
  61.                 for(j = 0; j < 128; j++)
  62.                 {
  63.                         WriteData_st7565(0x00);
  64.                 }
  65.         }
  66. }


  67. void WriteCmd_st7565(unsigned char cmd)
  68. {
  69.         LCD_PZ12864_CS = 0;
  70.         LCD_PZ12864_WR = 0;       
  71.         LCD_PZ12864_RD = 1;  //disable read
  72.         LCD_PZ12864_RS = 0;        // command
  73.         _nop_();
  74.         _nop_();
  75.         DATA_PORT = cmd;
  76.         _nop_();
  77.         _nop_();
  78.         LCD_PZ12864_WR = 1;
  79. }

  80. void WriteData_st7565(unsigned char dat)
  81. {
  82.         LCD_PZ12864_CS = 0;
  83.         LCD_PZ12864_WR = 0;       
  84.         LCD_PZ12864_RD = 1;  //disable read
  85.         LCD_PZ12864_RS = 1;        // data
  86.         _nop_();
  87.         _nop_();
  88.         DATA_PORT = dat;
  89.         _nop_();
  90.         _nop_();
  91.         LCD_PZ12864_WR = 1;
  92. }

  93. void XY_WriteCmd(unsigned char x, unsigned char y)
  94. {
  95.         unsigned char xl,xh;
  96.         xh = (x >> 4) & 0x0f;
  97.         xl = x & 0x0f;
  98.                 // 八页0-7,一页四位
  99.         WriteCmd_st7565(0xb0 + y); //y
  100.         // 横坐标127个 0-127,比如第5个 5 - 1 =0x04 ,则高四位为0,第四位为4,即0x10+0,0x00+4
  101.         WriteCmd_st7565(0x10 + xh);                        //x
  102.         WriteCmd_st7565(0x00 + xl);                        //x
  103. }


  104. void XY_Write816Data(unsigned char x,unsigned char y, unsigned char *CH)
  105. {
  106.         unsigned char i;
  107.         XY_WriteCmd(x,y);
  108.         for(i = 0; i < 16; i ++)
  109.         {
  110.                 if(i == 8)
  111.                         XY_WriteCmd(x,y+1);
  112.                
  113.                 WriteData_st7565(*(CH+i));
  114.         }
  115. }

  116. void XY_Write1616Data(unsigned char x,unsigned char y, unsigned char *CH)
  117. {
  118.         unsigned char i;
  119.         XY_WriteCmd(x,y);
  120.         for(i = 0; i < 32; i ++)
  121.         {
  122.                 if(i == 16)
  123.                         XY_WriteCmd(x,y+1);
  124.                
  125.                 WriteData_st7565(*(CH+i));
  126.         }
  127. }

  128. void XY_WriteString(unsigned char x, unsigned char y, unsigned char *str)
  129. {
  130.         unsigned char i;
  131.         while(*str != '\0')
  132.         {
  133.                 for(i = 0; i < 74; i ++)        //字库字符数量
  134.                 {
  135.                         if(*str == letter[i].CharWord)
  136.                         {
  137.                                 XY_Write816Data(x, y, letter[i].Ecode);
  138.                                 x += 8;
  139.                         }
  140.                 }
  141.                 str += 1;
  142.         }
  143. }

  144. void XY_WriteCN(unsigned char x, unsigned char y, unsigned char *str)
  145. {
  146.         unsigned char i;
  147.         while(*str != '\0')
  148.         {
  149.                 for(i = 0; i < 3; i ++)//字库汉字数量
  150.                 {
  151.                         if((*str == hanzi[i].HZ[0]) && (*(str + 1) == hanzi[i].HZ[1]))
  152.                         {
  153.                                         XY_Write1616Data(x, y, hanzi[i].HZcode);
  154.                                         x += 16;
  155.                         }
  156.                 }
  157.                 str += 2;
  158.         }
  159. }
复制代码

所有资料51hei提供下载:
普中12864带背景点阵屏.rar (2.75 MB, 下载次数: 41)


评分

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

查看全部评分

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

使用道具 举报

沙发
ID:237218 发表于 2019-1-10 20:47 | 只看该作者
老手忽略就好
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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