writedata(dataw); }
void displaylistchar(unsigned char x,unsigned char y,unsigned char *p) //显示字符串 {
while(*p) //当一个字符型数组读完时*P指的为零 {
displayonechar(x,y,*(p++)); x++; } }
void WriteCgram(unsigned char address,unsigned char *p) //写CGRAM的数据 {
unsigned char i=8;
writecmd(address); //CGRAM里的地址 初始值0x40 每次加0x80 while(i--) {
writedata(*p); p++; } }
void DisplayOneChar(unsigned char x,unsigned char y,unsigned char address,unsigned char *p) //显示一个自定义字符 {
unsigned char i=8;
writecmd(address); //CGRAM里的地址 初始值0x40 每次加0x08 while(i--) {
writedata(*p); p++; }
location(x,y); //设定要显示的位置
writedata((address&=0x3f)/0x08); //要从CGRAM中读出数据在1602上显示 搞了半天发现CGRAM里的地址
} //和DDRAM里的地址有上面的转换关系
void displynumber(unsigned char x,unsigned char y,unsigned long num) //显示一个整数 {
unsigned int number[8]; int k,gh;
for(k=0;;k++) {
*(number+k)=(unsigned int)(num);//强制类型转换 num=num/10; if(num==0)break; }
for(gh=k;gh>=0;gh--) {
displyonechar(x,y,(*(number+gh)+48)); x++; } }
//字型码
uchar code nian[]={0x08,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02};// \年\ uchar code yue[]={0x0f,0x09,0x0f,0x09,0x0f,0x09,0x0b,0x11};// \月%uchar code ri[]={0x1f,0x11,0x11,0x1f,0x11,0x11,0x11,0x1f};// \日\
//显示汉字
displyonecharacter(0,0,0x40,nian); displyonecharacter(1,0,0x80,yue); displyonecharacter(1,0,0xc0,ri);
相关推荐: