找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 10313|回复: 5
收起左侧

LCD1602A显示问题 只显示第一个字符

[复制链接]
ID:107409 发表于 2016-4-16 16:32 | 显示全部楼层 |阅读模式
#include <reg52.h>
sbit RS=P2^6;
sbit RW=P2^5;
sbit E=P2^7;
void LCD1602_init();
void LCD1602_disp(unsigned char x,unsigned y,unsigned char buf);
void LCD1602_write_adress(unsigned char x,unsigned y);
/*void LCD1602_write_dat(unsigned char datbuf);*/
void LCD1602_write_dat_busy(unsigned char datbuf);
void LCD1602_write_com(unsigned char combuf);
void LCD1602_write_com_busy(unsigned char combuf);
void LCD1602_busy();
void delay(unsigned int t);



//主函数
void main()
{
    LCD1602_init();                                                                  //初始化
        LCD1602_disp(0,0,'H');
        LCD1602_disp(1,1,'E');
        LCD1602_disp(2,0,'L');
        LCD1602_disp(3,0,'L');
        LCD1602_disp(4,0,'O');
        LCD1602_disp(5,0,'!');
        while(1)
        {

        }
}



//lcd显示函数
void LCD1602_disp(unsigned char x,unsigned y,unsigned char buf)
{
    LCD1602_write_adress(x,y);
        LCD1602_write_dat_busy(buf);

}


//lcd写地址函数
void LCD1602_write_adress(unsigned char x,unsigned y)
{
    if(y==0)
        LCD1602_write_com_busy(0x80+x);
        else
        LCD1602_write_com_busy(0xc0+x);
}


//写数据函数

/*void LCD1602_write_dat(unsigned char datbuf)
{
    RS=1;
        RW=0;
        P0=datbuf;
        E=1;
        E=0;
}*/
//写数据函数带忙检测
void LCD1602_write_dat_busy(unsigned char datbuf)
{
    LCD1602_busy();
    RS=1;
        RW=0;
        P0=datbuf;
        E=1;
        E=0;
}

//写指令函数
void LCD1602_write_com(unsigned char combuf)
{
    RS=0;
        RW=0;
        P0=combuf;
        E=1;
        E=0;
}
//写指令函数带忙检测
void LCD1602_write_com_busy(unsigned char combuf)
{
    LCD1602_busy();
    RS=0;
        RW=0;
        P0=combuf;
        E=1;
        E=0;
}
//读状态函数(忙检测函数)

void LCD1602_busy()
{
    RS=0;
        RW=1;
        P0=0xff; //读前准备
        E=1;
        while(P0^7==0);
        E=0;
}

//延时函数

void delay(unsigned int t)
{
    unsigned int k;
        for(k=0;k<t;k++);  
}
   

//初始化函数
void LCD1602_init(void)
{
    delay(1500);                                 //延时15ms
        LCD1602_write_com(0x38);         //写指令38H 不检测忙信号
        delay(500);                                         //延时5ms
        LCD1602_write_com(0x38);         //写指令38H 不检测忙信号
    delay(500);                                         //延时5ms
        LCD1602_write_com(0x38);         //写指令38H 不检测忙信号 从该处开始,以后都需要忙检测 写地址不需要
        LCD1602_write_com_busy(0x38);//写指令38H 显示模式设置
        LCD1602_write_com_busy(0x08);//显示关闭
        LCD1602_write_com_busy(0x01);//显示清屏
        LCD1602_write_com_busy(0x06);//显示光标移动设置
        LCD1602_write_com_busy(0x0c);//显示开及光标设置
}

为什么只显示打一个字符H   其他的都不显示

评分

参与人数 1黑币 +50 收起 理由
admin + 50 很给力!

查看全部评分

回复

使用道具 举报

ID:111634 发表于 2016-4-23 22:04 | 显示全部楼层
张志良编著高教社出版《80C51单片机实用教程》ISBN 978-7-04-044532-9有详细应用介绍,欢迎咨询,zzlls@126.com

评分

参与人数 1黑币 +20 收起 理由
admin + 20 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

ID:113415 发表于 2016-4-24 07:18 | 显示全部楼层
教你一招,
在主函数中:
    LCD1602_init(); //这一行保留
   //下面这几行只用一行,其余行先注释掉,进行试验。
        LCD1602_disp(1,1,'E');
        LCD1602_disp(2,0,'L');
        LCD1602_disp(3,0,'L');
        LCD1602_disp(4,0,'O');
        LCD1602_disp(5,0,'!');
看看能否显示?特别是位置是否正确,由于只有一行,所以很好判别。 如果毛病依旧,肯定是你的函数写的有问题,或者初始化里面有错误。

评分

参与人数 1黑币 +60 收起 理由
admin + 60 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

ID:114189 发表于 2016-4-26 00:51 来自触屏版 | 显示全部楼层
我也遇到过这样的问题  提醒一下  用两两测量传送数据的八个引脚  应该有某两个连线了

评分

参与人数 1黑币 +20 收起 理由
admin + 20 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

ID:116746 发表于 2016-4-26 15:23 | 显示全部楼层
这个  我是来学习的

评分

参与人数 1黑币 +20 收起 理由
admin + 20 回帖助人的奖励!

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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