|
本帖最后由 shipeng 于 2017-11-21 15:01 编辑
再附上我的带字库12864的自定义字符的例程:
const u8 pic16x16[][32]=
{
{
0x0C,0x00,0x0E,0x00,0x09,0x00,0x08,0x80,0x08,0x40,0x08,0x20,0x08,0x10,0x08,0x08,
0x08,0x04,0x08,0x3C,0x09,0x20,0x0A,0x90,0x0C,0x90,0x00,0x48,0x00,0x48,0x00,0x30,/*"Mouse1.bmp",0*/
},
{
0x07,0xE0,0x18,0x18,0x20,0x04,0x43,0x02,0x47,0x02,0x8E,0x01,0x9C,0x01,0xBF,0xFD,
0xBF,0xFD,0x9C,0x01,0x8E,0x01,0x47,0x02,0x43,0x02,0x20,0x04,0x18,0x18,0x07,0xE0,/*"LeftDirection.bmp",1*/
},
{
0x00,0x00,0x03,0xFC,0x19,0x0C,0x25,0x04,0x25,0x04,0x19,0x10,0x01,0x10,0x01,0xF0,
0x01,0x10,0x01,0x10,0x01,0x00,0x01,0x00,0x01,0x00,0x03,0x80,0x00,0x00,0x00,0x00,/*"¡®F",2*/
},
{
0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x04,0x20,0x04,0x20,0x02,0x40,0x01,0x80,
0x01,0x80,0x01,0xC0,0x01,0xC0,0x01,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"16x16key.bmp",3*/
},
}; unsigned char Byte_Conv(unsigned char sou)
{
unsigned char i,j=sou;
for (i=0;i<7;i++)
{
j<<=1;
sou>>=1;
j|=sou&1;
}
return (j);
}
//--------------------------------------------------------------------------------------------
//¼ì2éLCDÃ|×′ì¬
//·μ»Ø1ÎaÃ|,·μ»Ø0ÎaÏD
u8 ReadStatusLCD(void)
{
u8 buf;
LCD_DATA_OUTPORT |= 0xff; //GOIOB->ODR êy¾Yêä3ö¶Ë¿ú
LCD_DATA_IN(); //éèÖÃêy¾Y¶Ë¿úÎaéÏà-êäèë
LCD_EN = 0;
delay_us(5);
LCD_RS = 0;//RSÎaμí RWÎa¸ß ¶á3öÃ|±êÖ¾¼°μØÖ·¼ÆêyÆ÷μÄ×′ì¬
LCD_RW = 1;
delay_us(5);
LCD_EN = 1;
delay_us(5);
while (LCD_DATA_INPORT&1);
buf = LCD_DATA_INPORT;
LCD_EN = 0;
return Byte_Conv(buf); //由于我的屏DB0-DB7对应我的IO口的P7-P0所以MSB,LSB要颠倒一下,Byte_Conv()是一个字节高低位转换函数
}
//--------------------------------------------------------------------------------------------
//D′Ö¸áîμ½LCD
void LCD_Wcmd(u8 cmd)
{
ReadStatusLCD();
LCD_RS = 0;
LCD_RW = 0; //D′Ö¸áî
LCD_EN = 0; //èôEÎa¸ßÔòÎa¶á2ù×÷
delay_us(5);
LCD_DATA_OUTPORT &= 0xFF00;
LCD_DATA_OUTPORT |= Byte_Conv(cmd);
LCD_DATA_OUT();
delay_us(5);
LCD_EN = 1; //E′ó¸ßμ½μíÅäoÏ/WÃüáî½øDDD′êy¾Y»òÖ¸áî
delay_us(5);
LCD_EN = 0;
}
//--------------------------------------------------------------------------------------------
///D′ÏÔê¾êy¾Yμ½LCD
void LCD_Wdata(u8 data)
{
ReadStatusLCD();
LCD_RS = 1;
LCD_RW = 0; //D′êy¾Y
LCD_EN = 0;
delay_us(5);
LCD_DATA_OUTPORT &= 0xFF00;
LCD_DATA_OUTPORT |= Byte_Conv(data);
LCD_DATA_OUT();
delay_us(5);
LCD_EN = 1;
delay_us(5);
LCD_EN = 0;
}
void WriteCGRAM(void)
{
u8 i,j;
LCD_Wcmd(0x30);//»ù±¾Ö¸áî delay(1);
LCD_Wcmd(0x02);//ÔêDíDT¸ÄCGμØÖ· delay(1);
LCD_Wcmd(0x40);//CGμØÖ· delay(1);
for (i=0;i<4;i++)
{
for(j=0;j<32;j++)
{
LCD_Wdata(pic16x16[j]);
}
}
}
//--------------------------------------------------------------------------------------------
//LCD3õê¼»ˉ
void LCD_Init(void)
{
LCD_Wcmd(0x34); //à©3äÖ¸áî2ù×÷
delay_ms(100);
LCD_Wcmd(0x30); //»ù±¾Ö¸áî2ù×÷
delay_us(100);
LCD_Wcmd(0x0C); //ÏÔ꾿a£¬1Ø1a±ê
delay_us(100);
LCD_Wcmd(0x01); //Çå3yLCDμÄÏÔê¾ÄúèY
delay_ms(5);
WriteCGRAM();
}
//--------------------------------------------------------------------------------------------
void LCD_Clear(void)
{
LCD_Wcmd(0x01); //Çå3yLCDμÄÏÔê¾ÄúèY
delay_ms(5);
}
//--------------------------------------------------------------------------------------------
//é趨ÏÔê¾Î»ÖÃ
//x=0-3,y=0-7
void LCD_SetCursor(u8 x,u8 y)
{
y=y>>1|y<<1&3;
y=0x80+y*8;
LCD_Wcmd(x+y); //ÏÔê¾μØÖ·
}
void Disp1Char(u8 x,u8 y,u8 ascii)
{
LCD_SetCursor(x,y);
LCD_Wdata(ascii);
}
//--------------------------------------------------------------------------------------------
//′ó(x,y)′|¿aê¼ÏÔê¾ò»¸ö×Ö·û′®
//*p:′yÏÔê¾×Ö·û′®
void LCD_ShowString(u8 x,u8 y,const unsigned char *p)
{
u8 i=(8-x)*2;
LCD_SetCursor(x,y);
while(*p!='\0')
{
LCD_Wdata(*p++);
if (--i==0)
{
if (y==3)break;
else LCD_SetCursor(0,y+1);
}
}
}
//--------------------------------------------------------------------------------------------
|
|