?? cs22-2.c
字號:
#include <REG51.H>
#include<INTRINS.H>
#define uchar unsigned char
#define uint unsigned int
#define DataPort P0
sbit LCM_RS=P2^0;
sbit LCM_RW=P2^1;
sbit LCM_EN=P2^2;
uchar code exampl[]="ForAnExample www.hlelectron.com ";
void Delay400ms(void);
void Delay5ms(void);
void WaitForEnable(void);
void WriteDataLCM(uchar data W);
void WriteCommandLCM(uchar CMD,uchar Attribc);
void InitLcd(void);
void Display(uchar dd);
void DisplayOneChar(uchar x,uchar y,uchar Wdata);
void ePutstr(uchar x,uchar y,uchar code *ptr);
//*******************************
void main(void)
{
uchar temp;
Delay400ms();
InitLcd();
temp=32;
ePutstr(0,0,exampl);
Delay400ms();
Delay400ms();
Delay400ms();
Delay400ms();
Delay400ms();
Delay400ms();
Delay400ms();
Delay400ms();
while(1)
{
temp&=0x7f;
if(temp<32)temp=32;
Display(temp++);
Delay400ms();
}
}
/****************************************/
void InitLcd(void)
{
WriteCommandLCM(0x38,0);
Delay5ms();
WriteCommandLCM(0x38,0);
Delay5ms();
WriteCommandLCM(0x38,0);
Delay5ms();
WriteCommandLCM(0x38,1);
WriteCommandLCM(0x08,1);
WriteCommandLCM(0x01,1);
WriteCommandLCM(0x06,1);
WriteCommandLCM(0x0c,1);
}
/*****************************************/
void Delay5ms(void)
{
uint i=5552;
while(i--);
}
/****************************************/
void Delay400ms(void)
{
uchar i=5;
uint j;
while(i--)
{
j=7269;
while(j--);
}
}
/*****************************************/
void LocateXY(char posx,char posy)
{
uchar temp;
temp&=0x7f;
temp=posx&0x0f;
posy&=0x01;
if(posy)temp|=0x40;
temp|=0x80;
WriteCommandLCM(temp,0);
}
/*****************************************/
void WaitForEnable(void)
{
DataPort=0xff;
LCM_RS=0;LCM_RW=1;_nop_();
LCM_EN=1;_nop_();_nop_();
while(DataPort&0x80);
LCM_EN=0;
}
/*****************************************/
void WriteDataLCM(uchar dataW)
{
WaitForEnable();
LCM_RS=1;LCM_RW=0;_nop_();
DataPort=dataW;_nop_();
LCM_EN=1;_nop_();_nop_();LCM_EN=0;
}
/*****************************************/
void WriteCommandLCM(uchar CMD,uchar Attribc)
{
if(Attribc)WaitForEnable();
LCM_RS=0;LCM_RW=0;_nop_();
DataPort=CMD;_nop_();
LCM_EN=1;_nop_();_nop_();LCM_EN=0;
}
/****************************************/
void Display(uchar dd)
{
uchar i;
for(i=0;i<16;i++){
DisplayOneChar(i,1,dd++);
dd&=0x7f;
if(dd<32)dd=32;
}
}
/****************************************/
void DisplayOneChar(uchar x,uchar y,uchar Wdata)
{
LocateXY(x,y);
WriteDataLCM(Wdata);
}
/****************************************/
void ePutstr(uchar x,uchar y,uchar code *ptr)
{
uchar i,l=0;
while(ptr[l]>31){l++;}
for(i=0;i<l;i++){
DisplayOneChar(x++,y,ptr[i]);
if(x==16){
x=0;y^=1;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -