|
源码如下:
#include <REGX51.H>
#include <intrins.H>
#define uchar unsigned char
#define uint unsigned int
uchar code tab1[]="^_^ Welcome ^_^";
uchar code tab2[]="I LOVE MGMC-V1.0";
sbit RS=P3^5;
sbit RW=P3^4;
sbit E=P3^3;
sbit BF=P0^7;
void delayxms(uint x)
{
uint i,j;
for(i=0;i<x;i++)
for(j=0;j<113;j++);
}
uchar DetectBusyBit()
{
bit result;
P0=0xff;
RS=0;RW=1;E=1;
delayxms(1);
result=BF;
E=0;
return result;
}
void WrComLCD(uchar comval)
{
while(DetectBusyBit());
RS=0;RW=0;E=1;
P0=comval;
delayxms(1);
E=0;
}
void WrDatLCD(uchar datval)
{
while(DetectBusyBit());
RS=1;RW=0;E=1;
P0=datval;
delayxms(1);
E=0;
}
void LCD_Init()
{
WrComLCD(0x38);
delayxms(1);
WrComLCD(0x38);
WrComLCD(0x01);
WrComLCD(0x06);
delayxms(1);
WrComLCD(0x0c);
}
void main()
{
uchar ucval=0;
LCD_Init();
delayxms(5);
WrComLCD(0x80);
while(tab1[ucval]!='\0')
{
WrDatLCD(tab1[ucval]);
ucval++;
}
ucval=0;
WrComLCD(0xc0);
while(tab2[ucval]!='\0')
{
WrDatLCD(tab2[ucval]);
ucval++;
}
while(1);
}
|
|