一乐电子

一乐电子百科

 找回密码
 请使用微信账号登录和注册会员

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
12
返回列表 发新帖
楼主: mdy-5153
收起左侧

[其他综合] 1602 LCD 不能四线驱动

[复制链接]
发表于 2014-3-12 21:19 | 显示全部楼层
实际上送0x22合理一些,这要看你的write函数怎么写了
上电
器件复位
ms级延时15
->0x22
ms级延时
->0x22
ms级延时
->0x22
ms级延时
发表于 2014-3-12 21:26 | 显示全部楼层
如果你的LCD_write_command结构是这样的:
高半字节处理
enable及延时
低半字节处理
enable及延时

那么你必须写成
LCD_write_command(0x22);
发表于 2014-3-12 21:41 | 显示全部楼层
初始化过程用8位的命今,之后用4位命令

点评

四位命令,是这样吗?比如地址码=0xce; LCD_write_command(0xc); LCD_write_command(0xe); LCD_write_command 只发四位数据。  发表于 2014-3-12 21:58
发表于 2014-3-12 21:58 | 显示全部楼层
你看下PDF哩,有些是不支持滴
发表于 2014-3-12 23:13 | 显示全部楼层
不玩1602了,,玩 NOKIA的屏,,TB上不贵,可视面积大多了.

51也不想玩了,
我现在就自己在做一个 STM8+NOKIA屏的板子,练习+学习下STM8..
热转印+双面板,真TMD费劲啊.
发表于 2014-3-13 10:58 | 显示全部楼层
我贴个在用的程序,你参考下,看能否工作。
  1. /*--------------------------------------------------------------*/
  2. //LCD1602四线驱动程序
  3. //File:        LCD1602_4.H
  4. //Date:        08-8-7
  5. //Time:        9:21
  6. //Ver:        0.01


  7. /*--------------------------------------------------------------*/
  8. #ifndef __LCD1602_4_H__                //防止被重复定义
  9. #define __LCD1602_4_H__


  10. /*--------------------------------------------------------------*/
  11. //LCD1602接口定义
  12. sfr                LCD_DATA    = 0xa0;                //P2口高四位(P2^4~P2^7)与LCD的高四位(D4~D7)一一对应相接
  13. sbit        LCD_RS                = P2^2;                //数据指令
  14. sbit        LCD_EN                = P2^3;                //使能端
  15. //sbit        LCD_RW                = GND;                //读写控制端接地        ^_^哈哈,又少了一根线咯!


  16. /*--------------------------------------------------------------*/
  17. //函数声明
  18. void LCD_init   (void);                                                                                                        //液晶初始化
  19. void LCD_en     (void);                                                                                                        //输入使能
  20. void LCD_clr        (void);                                                                                                        //液晶清屏
  21. void LCD_cmd    (unsigned char cmd);                                                                        //指令输入
  22. void LCD_dat    (unsigned char dat);                                                                        //数据输入
  23. void LCD_delay  (unsigned char m, unsigned char n);                                                //延迟时间
  24. void LCD_pos    (unsigned char x, unsigned char y);                                                //液晶定位
  25. void LCD_printc (unsigned char x, unsigned char y, unsigned char c);        //字符定位输出
  26. void LCD_prints (unsigned char x, unsigned char y, unsigned char *s);        //字符串定位输出
  27. /*
  28. void LCD_fprints(unsigned char *s,signed char pos);                                                //字符串输出
  29. */

  30. /*--------------------------------------------------------------*/
  31. //延迟时间12us→130 000us
  32. void LCD_delay(unsigned char m, unsigned char n)
  33. {
  34.     unsigned char tempm,tempn=n;
  35.     do{tempm=m;while(--tempm);}while(--tempn);
  36. }


  37. /*--------------------------------------------------------------*/
  38. //液晶初始化
  39. void LCD_init(void)
  40. {
  41.         LCD_cmd(0x28);
  42.         LCD_en();
  43.         LCD_cmd(0x28);                        //四线显示
  44.         LCD_cmd(0x0c);                        //显示打开
  45.         LCD_cmd(0x01);                        //显示清屏
  46.         LCD_delay(2, 249);                //2000-2 us
  47. }


  48. /*--------------------------------------------------------------*/
  49. //输入使能
  50. void LCD_en(void)
  51. {
  52.         LCD_EN = 1;
  53.         LCD_delay(1,1);                        //12us
  54.         LCD_EN = 0;
  55. }


  56. /*--------------------------------------------------------------*/
  57. //指令输入
  58. void LCD_cmd(unsigned char cmd)
  59. {
  60.         LCD_delay(15,1);                //40us
  61.         LCD_RS = 0;                                //指令
  62.         LCD_DATA &= 0x0f;                //清高四位
  63.         LCD_DATA |= cmd&0xf0;        //写高四位
  64.         LCD_en();
  65.         cmd <<= 4;                                //低四位移到高四位
  66.         LCD_DATA &= 0x0f;                //清高四位
  67.         LCD_DATA |= cmd&0xf0;        //写高四位
  68.         LCD_en();
  69. }


  70. /*--------------------------------------------------------------*/
  71. //数据输入
  72. void LCD_dat(unsigned char dat)
  73. {
  74.         LCD_delay(15,1);                //40us
  75.         LCD_RS = 1;                                //数据
  76.         LCD_DATA &= 0x0f;                //清高四位
  77.         LCD_DATA |= dat&0xf0;        //写高四位
  78.         LCD_en();
  79.         dat <<= 4;                                //低四位移到高四位
  80.         LCD_DATA &= 0x0f;                //清高四位
  81.         LCD_DATA |= dat&0xf0;        //写高四位
  82.         LCD_en();
  83. }


  84. /*--------------------------------------------------------------*/
  85. //液晶清屏
  86. void LCD_clr(void)       
  87. {
  88.         LCD_cmd(0x01);
  89.         LCD_delay(2, 249);                //2000-2 us
  90. }


  91. /*--------------------------------------------------------------*/
  92. //液晶定位
  93. void LCD_pos(unsigned char x, unsigned char y)
  94. {
  95.         if(y)        LCD_cmd(x|0xc0);
  96.         else        LCD_cmd(x|0x80);
  97. }



  98. /*--------------------------------------------------------------*/
  99. //字符定位输出
  100. void LCD_printc(unsigned char x, unsigned char y, unsigned char c)
  101. {
  102.         LCD_pos(x, y);
  103.         LCD_dat(c);
  104. }


  105. /*--------------------------------------------------------------*/
  106. //字符串定位输出
  107. void LCD_prints(unsigned char x, unsigned char y, unsigned char *s)
  108. {
  109.         LCD_pos(x, y);
  110.         while(*s)
  111.         {
  112.                 LCD_dat(*s);
  113.                 s++;
  114.         }
  115. }
复制代码
发表于 2014-3-24 01:42 | 显示全部楼层
/*------------------------------------------------
            initial LCM
------------------------------------------------*/
void LCD_Init(void)//20131225 8bit command
{
   LCD_Write_Com(0x38); //38 --- 8bit & 2 line ,28 -- 4bit & 2 line
           DelayMs(5);
         LCD_Write_Com(0x38); //38 --- 8bit & 2 line ,28 -- 4bit & 2 line
           DelayMs(5);
         LCD_Write_Com(0x38);
   DelayMs(5);       
   LCD_Write_Com(0x08);    /*显示关闭*/



void LCD_Write_Com(char com) //4bit
{  
while(LCD_Check_Busy()); //
RS_CLR; //
RW_CLR; //
EN_SET; //
DataPort= com; //
_nop_();
EN_CLR;//
com<<=4;
EN_SET; //
_nop_();
DataPort= com; //
EN_CLR;//
DelayMs(1);
}

給你參考!!

本版积分规则

QQ|一淘宝店|手机版|商店|电子DIY套件|一乐电子 ( 粤ICP备09076165号 ) 公安备案粤公网安备 44522102000183号

GMT+8, 2024-6-17 02:09 , Processed in 0.048424 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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