|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#ifndef _LCD_H_
#define _LCD_H_
#ifndef uchar
#define uchar unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
#include<reg51.h>
#define LCD_Datapin P0
sbit LCD_RS = P2^6;
sbit LCD_RW = P2^5;
sbit LCD_EN = P2^7;
void DelayMs(uint x);
uchar LCD_Busy();
void LCD_Write(uchar date,bit j);
void LCDInit();
void LCD_Display_byte(uchar x,uchar y,uchar date );
void LCD_Display_String(uchar x,uchar y,uchar table[]);
#include<LCD.h>
#include<intrins.h>
#include<string.h>
void DelayMs(uint x) //毫秒的延时函数
{
uint t;
while(x--)
{
for(t=0;t<120;t++);
}
}
/*******
判断LCD是否忙碌状态要求
1.使用读时序
2.读出D7的状态是0还是1,0表示不忙 ,1表示忙碌中
********/
uchar LCD_Busy() //判断LCD是否忙碌状态
{
uchar LCD_Status;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
DelayMs(1);
LCD_Status = (P0&0x80); //
LCD_EN = 0 ;
return LCD_Status;
}
//写指令数据程序 j为0时写命令 j为1写数据
void LCD_Write(uchar date,bit j)
{
while(LCD_Busy());
LCD_RW = 0;
LCD_RS = j;
LCD_Datapin = date;
LCD_EN = 1;
LCD_EN = 0;
}
//LCD初始化
void LCDInit()
{
DelayMs(5);
LCD_Write(0x38,0);
DelayMs(5);
LCD_Write(0x38,0);
LCD_Write(0x08,0);
LCD_Write(0x01,0);
LCD_Write(0x06,0);
LCD_Write(0x0c,0);
}
// 显示单个字符 x为0写在第一行 x为1写在第二行 y数据显示的地址 Z写入的数据
void LCD_Display_byte(uchar x,uchar y,uchar date )
{
if(x==0)
{
LCD_Write(0x80+y,0);//写显示地址
}
else
{
LCD_Write(0xc0+y,0); //写显示地址
}
LCD_Write(date,1);//写数据
}
//写字符串
void LCD_Display_String(uchar x,uchar y,uchar table[])
{
uchar t;//记录table字符串的长度
if(x==0)
{
LCD_Write(0x80+y,0);//写显示地址
}
else
{
LCD_Write(0xc0+y,0); //写显示地址
}
t= strlen(table);
if(t<=16)
{
for(t=0;t<17;t++)
{
LCD_Write(table[t],1);
}
}
}
#include<reg51.h>
#include<LCD.h>
uchar table[]={"qq:1111111111"};
void main()
{
LCDInit();
LCD_Display_byte(0,1,'B');
LCD_Display_String(1,2,table);
while(1);
}
#endif请大佬们帮我看看代码需要怎么修改 |
|