//********WAVE-E6000/T***************
//*MCU: AT89C51 *
//*MCU-crystal: 12M *
//***********************************
#include#include#define uint unsigned int
#define uchar unsigned char
//****************************
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P2_0=P2^0;
sbit P2_1=P2^1;
sbit P2_2=P2^2;
sbit P2_3=P2^3;
sbit P2_4=P2^4;
sbit P2_5=P2^5;
sbit P2_6=P2^6;
sbit P2_7=P2^7;
sbit P3_6=P3^6;
sbit P3_7=P3^7;
sbit P0_7=P0^7;
//****************************
//定义LCD的连接端口
//****************************
#define LCD_RS P2_5
#define LCD_RW P2_6
#define LCD_EN P2_7
#define BUSY P0_7
#define LCDPort0 P0
#define SCL P3_6
#define SDA P3_7
#define K1 P1_0
#define K2 P1_1
#define K3 P1_2
//********************************
static uchar bdata StateREG; //可位寻址的状态寄存器
sbit CY1 = StateREG^1; //状态
//********************************
uchar Command_Code;
uchar Command_Code_No;
uchar Buf_Code;
uchar Buf_Add;
uchar cont;
uchar code Table[]={0x48,0x65,0x6c,0x6c,0x6f,0x20,0x52,0x49,
0x53,0x49,0x4f,0x4e,0x00}; //"Hello RISION"
//******************************
//函数原型声明 *****************
//******************************
void LCDBusy(void);
void LCDWrite_Command(void);
void LCDWrite_Command_No(void);
void INITLCD(void);
void LCDWrite_Data(uchar Buf_Data);
void _nop_(void);
void delay_ms(uchar ms);
void LCDWrite_String(void);
void STA(void);
void STOP(void);
void Write_DATA();
void Read_DATA();
void WRBYT(uchar EEROM_Buf);
//*******************************
//===============================
//延时最大255毫秒
//===============================
void delay_ms(uchar ms)
{
uchar i,j;
for(j=0;j for (i=0;i<124;i++)
_nop_();
}
//===========================
//写一个命令字节,不进行忙检测
//===========================
void LCDWrite_Command_No()
{
LCD_EN=0;
LCD_RS=0;
LCD_RW=0;
LCDPort0=Command_Code_No;
LCD_EN=1 ;
_nop_();
LCD_EN=0;
}
//===========================
//写一个命令字节,进行忙检测
//===========================
void LCDWrite_Command()
{
LCDBusy();
LCD_EN=0;
LCD_RW=0;
LCD_RS=0;
LCD_EN=1;
LCDPort0=Command_Code;
LCD_EN=0;
}
//===========================
//LCD状态检测
//===========================
void LCDBusy()
{
uchar BUSY_A;
do{
LCDPort0=0xFF;
LCD_EN=0;
LCD_RS=0;
LCD_RW=1;
LCD_EN=1;
BUSY_A=LCDPort0;
LCD_EN=0;
}
while ((BUSY_A&0x80)!=0x00);
}
//****************************
void INITLCD()
{
delay_ms(15);
Command_Code=0x38;
LCDWrite_Command_No();
delay_ms(5);
Command_Code=0x38;
LCDWrite_Command_No();
delay_ms(5);
Command_Code=0x38;
LCDWrite_Command_No();
Command_Code=0x38;
LCDWrite_Command(); //设定LCD为16*2显示,5*7点阵,8位数据接口
Command_Code=0x01;
LCDWrite_Command(); //显示清屏。
Command_Code=0x06;
LCDWrite_Command(); //显示光标自动右移,整屏不移动。
Command_Code=0x0C;
LCDWrite_Command(); //开显示,不显示光标
}
//********************************
//===========================
//写一个命令字节,进行忙检测
//===========================
void LCDWrite_Data(uchar Buf_Code)
{
// Buf_Code=Buf_Code|0x40;
LCDBusy();
LCD_EN=0;
LCD_RW=0;
LCD_RS=1;
LCD_EN=1;
LCDPort0=Buf_Code;
LCD_EN=0;
}
//****************************
void LCDWrite_String()
{
Command_Code=0xC2;cont=0;
do{
LCDWrite_Command();
Command_Code++;
LCDWrite_Data(Table[cont]);
cont++;
}
while(Table[cont]!=0x00);
return;
}
//****************************
void STA()
{
SDA=1;
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
SDA=0;
}
//****************************
void STOP()
{
SDA=0;
_nop_();
_nop_();
SCL=1;
_nop_();
_nop_();
SDA=1;
}
//****************************
void main()
{
INITLCD();
Command_Code=0x80;
LCDWrite_Command(); //将数据指针设置到第一行的第一个字符。
LCDWrite_Data(0x37);
LCDWrite_String();
while(1);
{;}
}