找回密码
 立即注册

QQ登录

只需一步,快速开始

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

LCD1602显示单片机源码

[复制链接]
ID:75262 发表于 2015-3-24 23:08 | 显示全部楼层 |阅读模式
这几天精神状态不佳,今天才出成果,LCD1602 显示,由于使用的是字符型的LCD,所以无法显示汉字,只能是字符,好了,代码来袭~~
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit LCDE=P2^7;
sbit RS=P2^6;
sbit RW=P2^5;
uchar code table1[]="x=1,y=1";   //显示第一行内容
uchar code table2[]="x=2,y=2";           //显示第二行内容

void LCD_write_com(uchar com);          //写指令
void LCD_write_dat(uchar dat);           //写数据
void delay(uint z);
void init();


void LCD_write_com(uchar com)
{
RS=0;                  
P0=com;
delay(5);
LCDE=1;
delay(5);
LCDE=0;

}

void LCD_write_dat(uchar dat)
{
RS=1;
P0=dat;
delay(5);
LCDE=1;
delay(5);
LCDE=0;
}
void init()
{
RW=0;
LCD_write_com(0x38);         //数据总线8位,显示2行,5*7点阵每字符
LCD_write_com(0x0c);         //显示功能开,无光标
LCD_write_com(0x06);          //光标设置
LCD_write_com(0x80+0x10);  //数据指针位置
LCD_write_com(0x01);                   //清屏
}

void delay(uchar z)
{uint a,b;
for(a=z;a>0;a--)
for(b=110;b>0;b--);}

void main()
{uchar a;
init();
LCD_write_com(0x80);
for(a=0;a<7;a++)
{
LCD_write_dat(table1[a]);
delay(30);
}
LCD_write_com(0x80+0x40);
for(a=0;a<7;a++)
{LCD_write_dat(table2[a]);
delay(30);
}
delay(4500);
for(a=0;a<20;a++)
{
LCD_write_com(0x18);
delay(150);
}


}
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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