?? diceng1602.h
字號:
#define uchar unsigned char
#define uint unsigned int
#include "reg52.h"
#include "intrins.h"
sbit RS = P2^7;
sbit RW = P2^6;
sbit E = P2^5;
#define DPORT P0
const uchar NoDisp=0; //無顯示
const uchar NoCur=1; //有顯示無光標(biāo)
const uchar CurNoFlash=2; //有光標(biāo)但不閃爍
const uchar CurFlash=3; //有光標(biāo)且閃爍
void LcdPos(uchar,uchar); //確定光標(biāo)位置
void LcdWd(uchar); //寫字符
void LcdWc(uchar); //送控制字(檢測忙信號)
void LcdWcn(uchar ); //送控制字子程序(不檢測忙信號)
void mDelay(uchar ); //延時,毫秒數(shù)由j決定
void WaitIdle(); //正常讀寫操作之前檢測LCD控制器狀態(tài)
//在指定的行與列顯示指定的字符,xpos:行,ypos:列,c:待顯示字符
void WriteChar(uchar c,uchar xPos,uchar yPos)
{ LcdPos(xPos,yPos);
LcdWd(c);
}
void WriteString(uchar *s,uchar xPos,uchar yPos)
{ uchar i;
if(*s==0) //遇到字符串結(jié)束
return;
for(i=0;;i++)
{
if(*(s+i)==0)
break;
WriteChar(*(s+i),xPos,yPos);
xPos++;
if(xPos>=15) //如果XPOS中的值未到15(可顯示的最多位)
break;
}
}
void SetCur(uchar Para) //設(shè)置光標(biāo)
{ mDelay(2);
switch(Para)
{ case 0:
{ LcdWc(0x08); //關(guān)顯示
break;
}
case 1:
{ LcdWc(0x0c); //開顯示但無光標(biāo)
break;
}
case 2:
{ LcdWc(0x0e); //開顯示有光標(biāo)但不閃爍
break;
}
case 3:
{ LcdWc(0x0f); //開顯示有光標(biāo)且閃爍
break;
}
default:
break;
}
}
void ClrLcd() //清屏命令
{ LcdWc(0x01);
}
// 正常讀寫操作之前檢測LCD控制器狀態(tài)
void WaitIdle()
{ uchar tmp;
RS=0;
RW=1;
E=1;
_nop_();
for(;;)
{ tmp=DPORT;
tmp&=0x80;
if( tmp==0)
break;
}
E=0;
}
void LcdWd(uchar c) //寫字符子程序
{ WaitIdle();
RS=1;
RW=0;
DPORT=c; //將待寫數(shù)據(jù)送到數(shù)據(jù)端口
E=1;
_nop_();
_nop_();
E=0;
}
void LcdWc(uchar c) //送控制字子程序(檢測忙信號)
{ WaitIdle();
LcdWcn(c);
}
void LcdWcn(uchar c) //送控制字子程序(不檢測忙信號)
{ RS=0;
RW=0;
DPORT=c;
E=1;
_nop_();
E=0;
}
void LcdPos(uchar xPos,uchar yPos) //設(shè)置第(xPos,yPos)個字符的DDRAM地址
{ unsigned char tmp;
xPos&=0x0f; //x位置范圍是0~15
yPos&=0x01; //y位置范圍是0~1
if(yPos==0) //顯示第一行
tmp=xPos;
else
tmp=xPos+0x40;
tmp|=0x80;
LcdWc(tmp);
}
void RstLcd() //復(fù)位LCD控制器
{ mDelay(15); //如果使用12M或以下晶振,此數(shù)值不必改,如用24M晶振,須用30
LcdWc(0x38); //顯示模式設(shè)置
LcdWc(0x08); //顯示關(guān)閉
LcdWc(0x01); //顯示清屏
LcdWc(0x06); //顯示光標(biāo)移動位置
LcdWc(0x0c); //顯示開及光標(biāo)設(shè)置
}
void mDelay(uchar j) //延時,毫秒數(shù)由j決定
{ uint i=0;
for(;j>0;j--)
{ for(i=0;i<124;i++)
{;}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -