unsigned char str1[]="ll";
unsigned char str2[]="shdfjkewoi";
unsigned char str3[]="1654621";
unsigned char str4[]="我";
//=======================================================
//微秒级延时程序
void delay_us(int time)
{
do
{
time--;
}
while (time > 1);
}
//=======================================================
//毫秒级延时程序
void delay_ms(unsigned int time)
{
while(time != 0)
{
delay_us(1000);
time--;
}
}
//=======================================================
//读取lcd是否内部操作(忙碌)状态
char Lcd_Busy()
{
char r;
DDRB = 0x00; //端口B设为输入方式
E_L;RS_L;RW_H; //E=0(致能),RS=0(命令),RW=1(读)
delay_us(2); //液晶延时子程序
E_H;
delay_us(2); //液晶延时子程序
r = PINB & 0x80; //读取lcd_data第八位
E_L;
DDRB="0xff"; //端口B设为输出方式
return r; //读取结果返回
}
//=======================================================
//向Lcd发送命令程序
void Lcd_Command(unsigned char Command)
{
while(Lcd_Busy()); //判断lcd是否内部操作状态
E_L;RS_L;RW_L; //E=0(致能),RS=0(命令),RW=0(写)
delay_us(2); //液晶延时子程序
E_H;
PORTB = Command; //向Lcd发送命令
delay_us(2); //液晶延时子程序
E_L;
}
//=======================================================
//向lcd写入一个字符程序
void Lcd_Write(unsigned char Data)
{
while(Lcd_Busy()); //判断lcd是否内部操作状态
E_L;RS_H;RW_L; //E=0(致能),RS=1(数据),RW=0(写)
delay_us(2); //液晶延时子程序
E_H;
PORTB = Data; //向lcd写入一个字符
delay_us(2); //液晶延时子程序
E_L;
}
/*=======================================================
LCD第1行显示地址1~20(0x80~0x93)
LCD第2行显示地址1~20(0xc0~0xd3)
LCD第3行显示地址1~20(0x94~0xa7)
LCD第4行显示地址1~20(0xd4~0xe7)
=======================================================*/
//初始化LCD_8位接口,4行x20字符的工作方式
void Lcd_Init()
{
DDRB = 0xff; //端口B设为输出方式
DDRD = 0xff; //端口D设为输出方式
Lcd_Command(0x38); //
Lcd_Command(0x38); //
Lcd_Command(0x38); //
Lcd_Command(0x38); //
Lcd_Command(0x08); //令显示器off
Lcd_Command(0x01); //清除显示器
Lcd_Command(0x06); //令LCD每接收到1Byte数据后,AC自动加1
本文关键字:程序 AVR单片机,单片机-工控设备 - AVR单片机
上一篇:LCD1602程序下载(AVR)