void lcdinit() //LCD initialization
{
lcdcmd0(0x80); //Set the display mode, text or graphics
lcdcmd2(0x00,0x00,0x42); //Set the cursor first address
lcdcmd2(30,0x00,0x43); //Set the width of the graphics area
lcdcmd2(0x00,0x00,0x40); //Set the first address of the text display area
lcdcmd2(30,0x00,0x41); ////Set the text area width
lcdcmd0(0x9f); //Set cursor to blink, not display, text and graphics display
lcdcmd0(0xa2); //Set the cursor shape
lcdcmd2(0x00,0x00,0x21); //Set the cursor pointer
lcdcmd2(0x00,0x00,0x22); //Set CGRAM offset address
lcdcmd2(0x00,0x00,0x24); //Set address pointer
}
Now the cursor can be displayed, but no characters are displayed.
Main program:
lcdinit();
dis_clr(0);//Clear screen
write_lcd(16,0,"123abc----------");
The function to display characters is as follows:
//---------------------------------------------
// Write the specified character to the LCD at the specified position
//
//
//---------------------------------------------
void write_lcd(uchar x,uchar y,char *cha)
{
uint place,i=0;
uchar length,c1,c2,j,k;
for(length=0;cha[length]!=0;length++);
do
{
c1=cha[i]; //Get the ASCII code of the string
c2=cha[i+1];
place=x*30+y;
if(c1<=128) //######Less than 128 is a character, greater than 128 is a Chinese character
{
for(k=0;k<16;++k) //Character is set to 16*8
{
lcddatw(place&0xff); //Write to the low bit of the address
lcddatw(place/256); //Write to the high bit of the address
lcdcmd0(0x24); //Address setting
lcdcmd0(0xb0); //Set data to write automatically
lcddatw(ASC_MSK[(c1-0x20)*16+k]); /*---For example: the ASCII code of 0 is 0x30,
The position in ASC_MSK is 0x10*16 --- 16 bytes of code are written to LCD in sequence --- */
lcdcmd0(0xb2); //auto reset
place=place+30;
}
if(y>28) //When y>28, a line break is required
{x=x+16;y=0;}
else //Otherwise, do not wrap and continue to write the next character
{y++;}
i++;
}
else //#####c1 is greater than 128 and is a Chinese character
{
for(j=0;j<sizeof(GB_16)/sizeof(GB_16[0]);j++) //Find Chinese characters
{
if(c1==GB_16[j].Index[0]&&c2==GB_16[j].Index[1])
break; //jump out if Chinese characters are found
}
if(j<sizeof(GB_16)/sizeof(GB_16[0])) //------If the Chinese character is in the subcode table
{
for(k=0;k<16;k++) //Character is set to 16*8
{
lcddatw(place&0xff); //Write to the low bit of the address
lcddatw(place/256); //Write to the high bit of the address
lcdcmd0(0x24); //Address setting
lcdcmd0(0xb0); //Address setting
lcddatw(GB_16[j].Msk[k*2]);
lcddatw(GB_16[j].Msk[k*2+1]); //16*16, 2 bytes per line
lcdcmd0(0xb2); //auto reset
place=place+30; //next line
}
}
else //-----If no corresponding Chinese character is found, blacken it
{
for(k=0;k<16;k++) //Character is set to 16*8
{
lcddatw(place&0xff); //Write to the low bit of the address
lcddatw(place/256); //Write to the high bit of the address
lcdcmd0(0x24); //Address setting
lcdcmd0(0xb0); //Address setting
lcddatw(0xff);
lcddatw(0xff);
lcdcmd0(0xb2); //auto reset
place=place+30; //next line
}
}
if(y>27) //-------line break
{x+=16;y=0;}
else //--------No line break, then the next word
{y+=2;}
i+=2;
}
}
while(i<length);
}
Please give me some advice, thank you!
|