#include "reg51.h"
#include "LCD1602.h"
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
void delay_us(int time)
{
do
{
time--;
}
while (time>1);
}
void delay_ms(unsigned int time)
{
while(time!=0)
{
delay_us(100);
time--;
}
}
/**********************************************************
LCD1602函数
并行方式
**********************************************************/
void write_com(unsigned char c)
{
RS=0;
RW=0;
EN=0;
P0=c;
delay_ms(5);
EN=1;
delay_us(20);
EN=0;
}
void write_data(unsigned char d)
{
RS=1;
RW=0;
P0=d;
delay_ms(5);
EN=1;
delay_us(20);
EN=0;
}
void lcd_initialize()
{
EN=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
//write_com(0x08);
}
void write_1602(unsigned char row,unsigned char line)
{
write_com(0x80+row*0x40+line);
}
void LCD_write_char(unsigned char x,unsigned char y,unsigned char data1)
{
if (y==0)
write_com(0x80+x);
else
write_com(0xC0+x);
write_data(data1);
}
void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
write_com(0x80+x);
else
write_com(0xC0+x);
while (*s)
{
write_data(*s);
s++;
}
}
以上 我的初始化代码···
#include "LCD1602.h"
sbit RS=P2^0;
sbit RW=P2^1;
sbit EN=P2^2;
void delay_us(int time)
{
do
{
time--;
}
while (time>1);
}
void delay_ms(unsigned int time)
{
while(time!=0)
{
delay_us(100);
time--;
}
}
/**********************************************************
LCD1602函数
并行方式
**********************************************************/
void write_com(unsigned char c)
{
RS=0;
RW=0;
EN=0;
P0=c;
delay_ms(5);
EN=1;
delay_us(20);
EN=0;
}
void write_data(unsigned char d)
{
RS=1;
RW=0;
P0=d;
delay_ms(5);
EN=1;
delay_us(20);
EN=0;
}
void lcd_initialize()
{
EN=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
//write_com(0x08);
}
void write_1602(unsigned char row,unsigned char line)
{
write_com(0x80+row*0x40+line);
}
void LCD_write_char(unsigned char x,unsigned char y,unsigned char data1)
{
if (y==0)
write_com(0x80+x);
else
write_com(0xC0+x);
write_data(data1);
}
void LCD_write_str(unsigned char x,unsigned char y,unsigned char *s)
{
if (y == 0)
write_com(0x80+x);
else
write_com(0xC0+x);
while (*s)
{
write_data(*s);
s++;
}
}
以上 我的初始化代码···