các đại ka chỉ bảo em vể cách lập trình cho LCD với em mới vào nghề nên ko biết.nhiều.
giải thích cho em thư viện #include này với.
giải thích cho em thư viện #include
- Code:
#include <AT89X52.H>
#include "lcd8.h"
#define FUNCTION 0x38
#define CONTROL 0x0c
#define CLRSCR 0x01
#define RETHOME 0x03
#define ENTRYMODE 0x06
#define PortData P2
#define RS P1_1
#define RW P1_2
#define EN P1_3
//********************************************************
void Delay(unsigned int n)
{
unsigned int j;
for(j=0;j<n;j++);
}
//********************************************************
void SetupLcd(void)
{
Delay(150);
WriteCmd(0x30);
Delay(150);
WriteCmd(0x30);
Delay(150);
WriteCmd(0x30);
Delay(150);
EN = 1;
Delay(0);
EN = 0;
WaitBusy();
WriteCmd(FUNCTION);
WriteCmd(CONTROL);
WriteCmd(CLRSCR);
WriteCmd(ENTRYMODE);
}
//********************************************************
void WriteCmd(unsigned char byte)
{
WaitBusy();
RS = 0;
RW = 0;
Delay(0);
PortData = byte;
EN = 1;
Delay(0);
EN = 0;
}
//********************************************************
void WriteChar(unsigned char ch)
{
WaitBusy();
RS = 1;
RW = 0;
Delay(0);
PortData = ch;
EN = 1;
Delay(0);
EN = 0;
}
//********************************************************
void WriteNum(unsigned char num)
{
unsigned char digit;
digit = num/100;
WriteChar(digit + '0'); //write tram
digit = num/10;
digit = digit % 10;
WriteChar(digit + '0'); //write chuc
digit = num % 100;
digit = digit % 10;
WriteChar(digit + '0'); //write dvi
}
//********************************************************
void GoHome()
{
WriteCmd(RETHOME);
Delay(100);
}
//********************************************************
void GoToXY(unsigned char row,unsigned char col)
{
unsigned char ac;
ac = 0x80;
ac = ac | ((row & 1) << 6);
ac = ac | (col & 15);
WriteCmd(ac);
}
//********************************************************
void ClearScreen(void)
{
WriteCmd(CLRSCR);
Delay(100);
}
//********************************************************
void WaitBusy(void)
{
char i,nLcdBusy;
PortData = (PortData | 0x80);
RS = 0;
RW = 1;
for(i=0;i<50;i++)
{
while(1)
{
EN = 1;
Delay(0);
nLcdBusy = (PortData & 0x80);
EN = 0;
Delay(0);
if(nLcdBusy == 0)
break;
}
}
}