#include "REG52.H"
// define some needed variant
sbit RS =P1^0;
sbit RW =P1^1;
sbit EN =P1^2;
sbit BUSY =P2^7;
// character dislay
#define CHU_A 0x41
#define CHU_B 0x42
#define CHU_C 0x43
#define CHU_D 0x44
#define CHU_E 0x45
#define CHU_F 0x46
#define CHU_G 0x47
#define CHU_H 0x48
#define CHU_I 0x49
#define CHU_J 0x4A
#define CHU_K 0x4B
#define CHU_L 0x4C
#define CHU_M 0x4D
#define CHU_N 0x4E
#define CHU_O 0x4F
#define CHU_P 0x50
#define CHU_Q 0x51
#define CHU_R 0x52
#define CHU_S 0x53
#define CHU_T 0x54
#define CHU_U 0x55
#define CHU_V 0x56
#define CHU_W 0x57
#define CHU_X 0x58
#define CHU_Y 0x59
#define CHU_Z 0x5A
#define KT 0x20
//
#define DATA P2
//declare my function
void WR_LCD( unsigned char TXT,bit RSbit);
void WAIT_LCD(void);
void INT_LCD(void);
void CLR_LCD (void);
void HOME_LCD (void);
//main program
void main(void)
{
INT_LCD();
CLR_LCD();
HOME_LCD();
DATA=0X55;
WR_LCD(CHU_B,1);
WR_LCD(CHU_A,1);
WR_LCD(CHU_O,1);
while(1);
}
//==================================================
void WAIT_LCD(void)
{
unsigned char tempt=255;
BUSY=1;
EN=1 ;
RW=1 ; //doc tu LCD ve uC
RS=0 ;//command
while (BUSY)
;
EN=0;
RW=0; //LCD nhan data
}
//==================================================
void INT_LCD(void)
{
//function set 8 col 2 row, 5x7 dot format,NIBBLE MODE
//EN=1;
//RS=0;
//DATA=0x38;
WR_LCD(0x28,0);
//EN=0;
//WAIT_LCD();
// Dislay ON/OFF CURSOR Shift
// dislay ON, Cursor Underline on, cursor blink off
WR_LCD(0x0E,0);
//EN=1;
//RS=0;
//DATA=0x0E;
//EN=0;
//WAIT_LCD();
//Set Charracter Mode
// increment (dich fai) , Dislay Shift Off
WR_LCD(0x06,0);
//EN=1;
//RS=0;
//DATA=0x06;
//EN=0;
//WAIT_LCD();
}
//=======================================================
void WR_LCD( unsigned char TXT,bit RSbit)//RSbit=0 cmd,=1 data
{
RS=RSbit;
RW=0;
//write 4 bit high
EN=1 ;
DATA=(TXT|0x0F)&DATA;
EN=0 ;
WAIT_LCD() ;
//DATA=highTXT_lowDATA
//write 4 bit low
EN=1 ;
DATA=((TXT<<4)|0x0F)&DATA;
//DATA=lowTXT_lowDATA
EN=0 ;
WAIT_LCD() ;
}
void CLR_LCD(void)
{
//EN=1;
//RS=0;
//DATA=0x01;
//EN=0;
//WAIT_LCD();
WR_LCD(0x01,0);
}
void HOME_LCD (void)
{//EN=1;
//RS=0;
//DATA=0X02;
//EN=1;
//WAIT_LCD();
WR_LCD(0x02,0);
}