|
发表于 2009-1-10 20:14:47
|
显示全部楼层
/*-----------写1602的CGRAM,定义汉字字模“年月日三四五六周”的函数--------------*/
/*---LCD_sendIN()和LCD_sendDA()函数分别为已定义好的向1602写指令和写数据的函数---*/
void LCD_CHN()
{
LCD_sendIN(0x40);//写指令0x40,开始CGRAM写操作
delay(5);
LCD_sendDA(0x08);
LCD_sendDA(0x0f);
LCD_sendDA(0x12);
LCD_sendDA(0x0f);
LCD_sendDA(0x0a);
LCD_sendDA(0x1f);
LCD_sendDA(0x02);
LCD_sendDA(0x02); //定义位于字模地址0x00处的字符,“年”
LCD_sendDA(0x0f);
LCD_sendDA(0x09);
LCD_sendDA(0x0f);
LCD_sendDA(0x09);
LCD_sendDA(0x0f);
LCD_sendDA(0x09);
LCD_sendDA(0x09);
LCD_sendDA(0x13);//定义位于字模地址0x01处的字符,“月”
LCD_sendDA(0x0f);
LCD_sendDA(0x09);
LCD_sendDA(0x09);
LCD_sendDA(0x0f);
LCD_sendDA(0x09);
LCD_sendDA(0x09);
LCD_sendDA(0x0f);
LCD_sendDA(0x00);//定义位于字模地址0x02处的字符,“日”
//硬字库地址0x2d处的字符就是汉字“一”
//硬字库地址0xc6处的字符就是汉字“二”
LCD_sendDA(0x00);
LCD_sendDA(0x0e);
LCD_sendDA(0x00);
LCD_sendDA(0x00);
LCD_sendDA(0x0e);
LCD_sendDA(0x00);
LCD_sendDA(0x00);
LCD_sendDA(0x1f);//定义位于字模地址0x03处的字符,“三”
LCD_sendDA(0x00);
LCD_sendDA(0x1f);
LCD_sendDA(0x17);
LCD_sendDA(0x17);
LCD_sendDA(0x1b);
LCD_sendDA(0x1f);
LCD_sendDA(0x00);
LCD_sendDA(0x00);//定义位于字模地址0x04处的字符,“四”
LCD_sendDA(0x00);
LCD_sendDA(0x1f);
LCD_sendDA(0x04);
LCD_sendDA(0x0f);
LCD_sendDA(0x05);
LCD_sendDA(0x09);
LCD_sendDA(0x1f);
LCD_sendDA(0x00);//定义位于字模地址0x05处的字符,“五”
LCD_sendDA(0x00);
LCD_sendDA(0x08);
LCD_sendDA(0x04);
LCD_sendDA(0x1f);
LCD_sendDA(0x00);
LCD_sendDA(0x0a);
LCD_sendDA(0x11);
LCD_sendDA(0x00);//定义位于字模地址0x06处的字符,“六”
LCD_sendDA(0x0f);
LCD_sendDA(0x15);
LCD_sendDA(0x1f);
LCD_sendDA(0x1f);
LCD_sendDA(0x1b);
LCD_sendDA(0x1f);
LCD_sendDA(0x13);
LCD_sendDA(0x11);//定义位于字模地址0x07处的字符,“周”
LCD_sendIN(0x02);//地址归位
delay_50ms(1);
LCD_sendIN(0x80);//设定DDRAM 地址
}
//==========================================
定义完上述字模后,只要LCD不断电就可以一直使用。直接写ASCII码“0x00,0x01,0x02,0x2d,0xc6,0x03,0x04,0x05,0x06,0x07”,即可显示汉字“年,月,日,一,二,三,四,五,六,周”。不过由于点阵太少,“四”和“周”两个字显示效果不太理想,不过远看也还凑合。
这是我以前用Keil C51写的,这段代码不牵涉到与MCU具体硬件相关的操作,因此再AVR上一样可以用。只要用自己现成的给1602写指令和写数据的函数替换掉上面的LCD_sendIN()和LCD_sendDA()就能直接用。另外,这段代码是以前写的,写的比较罗唆,呵呵,其实可以用查表的方法来实现的,楼上的朋友自己优化下吧……
本贴被 i387DX 编辑过,最后修改时间:2009-01-10,20:17:20. |
|