📄 ylf240128a._c
字号:
RD_SET;
CD_CLR;
NOP();NOP();NOP();
return data;
}
void WriteCmd(uchar command)
{
while ( (ReadSta()&0x03) !=0x03);
RD_SET;
CD_SET;
OUT_DIR;
DDRB=0xFF;
PORTB=command;
// NOP();NOP();NOP();
WR_CLR;
NOP();NOP();NOP();
WR_SET;
CD_CLR;
}
void WriteData(uchar data)
{
while ( (ReadSta()&0x03) !=0x03);
RD_SET;
CD_CLR;
OUT_DIR;
DDRB=0xFF;
PORTB=data;
// NOP();NOP();NOP();
WR_CLR;
NOP();NOP();NOP();
WR_SET;
}
void WrTwoParCmd(uchar par1,uchar par2,uchar command)
{
WriteData(par1);
WriteData(par2);
WriteCmd(command);
}
void WrOneParCmd(uchar par,uchar command)
{
WriteData(par);
WriteCmd(command);
}
void ClrRam(uint data)
{
uint i;
WrTwoParCmd(0x00,0x00,ADPSET);
WrTwoParCmd(0x00,0x00,ADPSET);//No Repeat--False Code
while((ReadSta()&0x08)!=8);
WriteCmd(AWRON);
for(i=0;i<(LCDCOLUMN*LCDLINE);i++)
WriteData(data);
WriteCmd(AWROFF);
}
void WrCGRAM(void)
{
uint i,j,len;
WrTwoParCmd(0x00,0x00,OFFSET);
WrTwoParCmd(0x00,0x04,ADPSET);
while((ReadSta()&0x08)!=8);
WriteCmd(AWRON);
for(i=0;i<10;i++) { //8*8
for(j=0;j<8;j++)
WriteData(GrCode[i*8+j]);
}
len=(uchar)sizeof(ChCode); //16*16
for (j=0;j<len;j++) {
for(i=0;i<16;i+=2)
WriteData(ChCode[j][i]);
for(i=1;i<16;i+=2)
WriteData(ChCode[j][i]);
for(i=16;i<32;i+=2)
WriteData(ChCode[j][i]);
for(i=17;i<32;i+=2)
WriteData(ChCode[j][i]);
}
WriteCmd(AWROFF);
}
void LcdInit(void)
{
CE_CLR;
FS_CLR;
WR_SET;RD_SET;CD_SET;
RST_CLR;
delay(1000);
RST_SET;
ClrRam(0x00);
WrTwoParCmd(0x00,0x00,TXHOME);
WrTwoParCmd(0x1E,0x00,TXAREA);
WrTwoParCmd(0x00,0x08,GRHOME);
WrTwoParCmd(0x1E,0x00,GRAREA);
WrTwoParCmd(0x00,0x00,CUPSET);
WriteCmd(0xA0);
WriteCmd(0x80);
WriteCmd(0x97);
// ClrRam(0x00);
WrCGRAM();
WrTwoParCmd(0x00,0x00,ADPSET);
WrTwoParCmd(0x00,0x00,CUPSET);
}
//Character Code Display--8*8
//x:0~29; y:0~15
void WrCharCode(uchar x,uchar y,uchar charcode)
{
uint address;
address=y*LCDCOLUMN+x;
WrTwoParCmd((uchar)(address),(uchar)(address>>8),ADPSET); //Set Display Ram Address
WrOneParCmd(charcode,0xC4); //Load Character Code,Address Non Variable
address+=0x800; //Text Attribute mode:blink
WrTwoParCmd((uchar)(address),(uchar)(address>>8),ADPSET);
WrOneParCmd(0x08,0xC4);
}
uchar AsctoCharCode(uchar asc)
{
uchar charcode;
charcode=(asc<20)? 0:(asc-0x20);
return charcode;
}
void WrCharStr(uchar x,uchar y,char charstr[])
{
uchar i,len;
len=strlen(charstr);
for(i=0;i<len;i++) {
WrCharCode(x,y,AsctoCharCode(charstr[i]) );
if (x<LCDCOLUMN)x++;
else
{
y++;
x=0;
}
}
}
void WrNumeral(uchar x,uchar y,uchar grade,uint numeral)
{
uchar i,g[5];
uchar str[5];
for(i=0;i<5;i++) {
g[i]=numeral%grade;
numeral/=grade;
str[4-i]=(g[i]>9)?(g[i]+0x37):(g[i]+0x30);
}
for(i=0;i<5;i++) { //clear high bit 0
if (str[i]==0x30 && i!=4)
str[i]=0x00;
else break;
}
for(i=0;i<5;i++) {
WrCharCode(x,y,AsctoCharCode(str[i]) );
WrCharCode(x,y+1,0x83);
if (x<LCDCOLUMN)x++;
else {
y++;
x=0;
}
}
}
//Define Character Code Display---16*16
//x:0~29; y:0~15
void WrDefChar(uchar x,uchar y,uchar defcodenum)
{
uint address,cgramnum;
address=address=y*30+x;
cgramnum=0x8A+(defcodenum<<2);
WrTwoParCmd((uchar)(address),(uchar)(address>>8),ADPSET); //Set Display Ram Address
WrOneParCmd(cgramnum++,0xC0);
WrOneParCmd(cgramnum++,0xC0);
address+=30;
WrTwoParCmd((uchar)(address),(uchar)(address>>8),ADPSET); //Set Display Ram Address
WrOneParCmd(cgramnum++,0xC0);
WrOneParCmd(cgramnum,0xC0);
}
void WrDefCharStr(uchar x,uchar y,uchar defcharstr[],uchar len)
{
uchar i;
for(i=0;i<len;i++) {
WrDefChar(x,y,defcharstr[i]);
if (x<LCDCOLUMN)x+=2;
else
{
y+=2;
x=0;
}
}
}
void main (void)
{
uint i,j;
char charstr[30];
uchar defcharstr[6]={BLANK};
uint tt=0;
// SP=0x45f;
McuInit();
LcdInit();
strcpy(charstr,"CHANGSHA HUNAN CHINA");
WrCharStr(5,0,charstr);
defcharstr[0]=ONE;
defcharstr[2]=JIAN;
defcharstr[3]=KONG;
defcharstr[4]=HUA;
defcharstr[5]=MIAN;
WrDefCharStr(2,2,defcharstr,sizeof(defcharstr));
defcharstr[0]=TWO;
defcharstr[2]=CAN;
defcharstr[3]=SHU;
defcharstr[4]=SE1;
defcharstr[5]=ZHI;
WrDefCharStr(2,4,defcharstr,sizeof(defcharstr));
defcharstr[0]=THREE;
defcharstr[2]=XIN1;
defcharstr[3]=HAO;
defcharstr[4]=CE;
defcharstr[5]=SHI;
WrDefCharStr(2,6,defcharstr,sizeof(defcharstr));
defcharstr[0]=FOUR;
defcharstr[2]=HUA1;
defcharstr[3]=YANG;
defcharstr[4]=BIAN;
defcharstr[5]=ZHI1;
WrDefCharStr(2,8,defcharstr,sizeof(defcharstr));
defcharstr[0]=FIVE;
defcharstr[2]=QUAN;
defcharstr[3]=XIAN;
defcharstr[4]=BLANK;
defcharstr[5]=BLANK;
WrDefCharStr(2,10,defcharstr,sizeof(defcharstr));
while (1) {
i=tt/30;
j=tt%30;
WrTwoParCmd(j,i,CUPSET);
WrNumeral(20,8,10,tt);
WrNumeral(20,10,16,tt);
delay(1000);
if (tt<480)tt++;
else tt=0;
}
}
/*--------------------------------------------
END
----------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -