主函数文件:
#include <reg52.h>
#include <intrins.h>
#include <stdio.h>
#include "./delay/delay.h"
sbit ds = P1^0;
bit ack = 0;
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;
#define LCDPORT P0
#define LCD_WRITE_DATA 1
#define LCD_WRITE_COM 0
void lcd1602_write(unsigned char byte,unsigned char flag)
{
if(flag)
{
RS = 1;
}
else
{
RS = 0;
}
RW = 0;
E = 1;
LCDPORT = byte;
delay_us(5);
E = 0;
}
void lcd1602_dis_str(unsigned char x, unsigned char y, unsigned char *str)
{
if((x > 15) || (y > 1))
{
return ;
}
if(0 == y)
{
lcd1602_write(0x80 + x,LCD_WRITE_COM);
}
else
{
lcd1602_write(0x80 + 0x40 + x,LCD_WRITE_COM);
}
while(*str != '\0')
{
lcd1602_write(*str,LCD_WRITE_DATA);
str++;
}
}
void lcd_init()
{
delay_ms(15);
lcd1602_write(