|
程序:
#include <reg52.h>
#define DATA_PORT P0
sbit LCD12864_EN = P1^2;
sbit LCD12864_RSET = P1^3;
sbit LCD12864_RS = P1^0;
sbit LCD12864_RW = P1^1;
sbit LCD12864_PSB = P1^6;
void delay(unsigned int xms) //延时//
{
unsigned char i,j;
for(j = 0; j < xms; j++)
{
for(i = 0;i < 110;i++);
}
}
bit LcdBusyCheck(){
bit result;
LCD12864_RS = 0;
LCD12864_RW = 1;
LCD12864_EN = 1;
result = (bit)(DATA_PORT&0x80);
LCD12864_EN = 0;
return result;
}
void WriteCmdToLCD(unsigned char cmd)
{
// while(LcdBusyCheck());
delay(10);
LCD12864_RS = 0;
LCD12864_RW = 0;
LCD12864_EN = 1;
DATA_PORT = cmd;
delay(5);
LCD12864_EN = 0;
delay(5);
LCD12864_EN = 1;
}
void WriteDatToLcd(unsigned char dat)
{
//while(LcdBusyCheck());
delay(10);
LCD12864_RS = 1;
LCD12864_RW = 0;
LCD12864_EN = 1;
DATA_PORT = dat;
delay(5);
LCD12864_EN = 0;
delay(5);
LCD12864_EN = 1;
}
void WriteStrToLcd(unsigned char *str)
{
while(*str != '\0')
{
WriteDatToLcd(*str++);
delay(5);
}
}
void LcdPos(unsigned char x,unsigned char y)
{
unsigned char pos;
if(x == 1)
{
x = 0x80;
}else if(x == 2)
{
x = 0x90;
}else if(x == 3)
{
x = 0x88;
}else if(x == 4)
{
x = 0x98;
}
pos = x + y - 1;
WriteCmdToLCD(pos);
}
void LcdInit()
{
LCD12864_PSB = 1;
LCD12864_RSET = 0;
delay(10);
LCD12864_RSET = 1;
WriteCmdToLCD(0x30);
delay(5);
WriteCmdToLCD(0x30);
delay(5);
WriteCmdToLCD(0x18);
delay(5);
WriteCmdToLCD(0x10);
delay(5);
WriteCmdToLCD(0x01);
delay(5);
WriteCmdToLCD(0x06);
delay(5);
WriteCmdToLCD(0x0c);
delay(5);
}
int main()
{
P0 = 0xff;
P1 = 0xff;
LcdInit();
while(1)
{
LcdPos(1,1);
WriteStrToLcd(" 榆林学院 ");
delay(5);
LcdPos(2,1);
WriteStrToLcd("能源工程学院");
delay(5);
LcdPos(3,1);
WriteStrToLcd("51控制LCD12864");
delay(5);
LcdPos(4,1);
WriteStrToLcd("加油吧朋友们!!!");
delay(500);
}
}
|
评分
-
查看全部评分
|