#include<reg52.h>
#include <math.h>
sbit KEY0 = P3^4;
void lcd_init(void);
void clr_lcd(void);
void send_com(unsigned char cmd);
void send_data(unsigned char dat);
void chek_busy(void);
void set_xy(unsigned char xpos,unsigned char ypos);
void print(unsigned char x,unsigned char y,char* str);
void printstr(unsigned char xpos,unsigned char ypos,unsigned char
str[],unsigned char k);
unsigned char code buf[4] ={0xbb,0xb6,0xd3,0xad};//欢迎
#define DATA P1
#define CONTROL P2
#define E 2 //并行的使能信号 sbit E = P0^7
#define RW 1 //并行的读写信号 sbit RW = P0^6
#define RS 0 //并行的指令数据选择信号 sbit RS = P0^5
#define PSB 3 //并/串行接口选择 sbit PSB = P0^4
#define RST 5 //复位 低电平有效 sbit RST = P0^3
#define SETB(x,y) (x|=(1<<y))
#define CLRB(x,y) (x&=(~(1<<y)))
#define CHKB(x,y) (x&(1<<y))
/********************测忙碌**********************/
//测忙碌子程序
//RS=0,RW=1,E=H,D0-D7=状态字
/************************************************/
void chek_busy(void)
{ unsigned char temp1;//状态信息(判断是否忙)
CLRB(CONTROL,RS); // RS = 0;
SETB(CONTROL,RW); // RW = 1;
SETB(CONTROL,E); // E = 1;
do{temp1 = DATA;DATA=0xFF;} while(temp1&0x80);
SETB(CONTROL,E); // E = 1;
DATA=0xFF;
}
/********************写命令**********************/
//写命令子程序
//
/************************************************/
void send_com(unsigned char cmd)/*写命令*/
{
chek_busy();
CLRB(CONTROL,RS); //RS = 0;
CLRB(CONTROL,RW); //RW = 0;
DATA = cmd;
SETB(CONTROL,E); //E = 1;
CLRB(CONTROL,E); //E = 0;
}
/********************写数据**********************/
//写数据子程序
//
/************************************************/
void send_data(unsigned char dat)
{
chek_busy();
SETB(CONTROL,RS); //RS = 1;
CLRB(CONTROL,RW); //RW = 0;