/********************************
LCD1602驱动 文件
********************************/
#include "main.h"
// Define P3 pins
#define DATA_BUS P0
sbit RS=P3^2;
sbit RW=P3^3;
sbit EN=P3^4;
// Test the Busy bit
void check_busy(void)
{
do
{
DATA_BUS = 0xff;
RS = 0;
RW = 1;
EN = 0;
delay1ms(1);
EN = 1;
delay1ms(1);
}
while(DATA_BUS & 0x80);
EN = 0;
}
// Write a command
void write_cmd(uchar cmd)
{
check_busy();
delay1ms(1);
RS = 0;
RW = 0;
EN = 0;
delay1ms(1);
DATA_BUS = cmd;
delay1ms(1);
EN = 1;
delay1ms(1);
EN = 0;
}
// Write Data
void write_dat(uchar dat)
{
check_busy();
delay1ms(1);
RS = 1;
RW = 0;
EN = 0;
DATA_BUS = dat;
delay1ms(1);
EN = 1;
delay1ms(1);
EN = 0;
}
// Ini
tialize LCD controller
void LCD_init8(void)
{
write_cmd(0x38);
delay1ms(1);
write_cmd(0x01);
delay1ms(1);
write_cmd(0x06);
delay1ms(1);
write_cmd(0x0e);
delay1ms(1);
}
// Clear LCD controller
void LCD_clr(void)
{
write_cmd(0x01);
delay1ms(1);
write_cmd(0x02);
delay1ms(1);
}
// Display a string
void LCD_disp(uchar addr, uchar *str)
{
write_cmd(addr);
delay1ms(1);
while(*str>=0)
{
write_dat(*str++);
delay1ms(1);
}
}
main.h文件内容为
[/img]#include "reg52.h"
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long int
一周热门 更多>