主函数文件:
#include <reg52.h>
#include <intrins.h>
#include "./delay/delay.h"
sbit SCL = P1^0;
sbit SDA = P1^1;
bit ack = 0;
sbit RS = P2^4;
sbit RW = P2^5;
sbit E = P2^6;
#define SUCC 1
#define ERR 0
#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 lcd_dis_char(unsigned char x, unsigned char y, unsigned char byte)
{
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);
}
lcd1602_write(byte,LCD_WRITE_DATA);
}
void lcd_init()
{
delay_ms(15);
lcd1602_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd1602_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd1602_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd1602_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd1602_write(0x08,LCD_WRITE_COM);
delay_ms(5);
lcd1602_write(0x01,LCD_WRITE_COM);
delay_ms(5);
lcd1602_write(0x06,LCD_WRITE_COM);
delay_ms(5);
lcd1602_write(0x0c,LCD_WRITE_COM);
delay_ms(5);
}
void iic_start()
{
SDA = 1;
SCL = 1;
delay_us(1);
SDA = 0;
delay_us(1);
SCL = 0;
}
void iic_stop()
{
SDA = 0;
SCL = 1;
delay_us(1);
SDA = 1;
delay_us(1);
SCL = 0;
}
bit iic_send_byte(unsigned char byte)
{
unsigned char i;
for(i = 0; i < 8;