知之者不如好之,好之者不如乐之
分类: 嵌入式
2015-07-07 23:06:13
#include<reg52.h> #define uchar unsigned char #define uint unsigned int sbit lcdrs=P1^0; sbit lcden=P1^2; sbit lcdwr=P1^1; uchar CGCODE[]={0x08,0x0F,0x12,0x0F,0x0A,0x1F,0x02,0x02,//"年"代码 0x00 0x0F,0x09,0x0F,0x09,0x0F,0x09,0x13,0x00,//"月"代码 0x01 0x0F,0x09,0x09,0x0F,0x09,0x09,0x0F,0x00,//"日"代码 0x02 0x07,0x04,0x07,0x04,0x07,0x00,0x04,0x07,//"星"左上半部分代码 0x03 0x1F,0x01,0x1F,0x01,0x1F,0x08,0x08,0x1F,//"星"右上半部分代码 0x04 0x08,0x17,0x00,0x1F,0x00,0x00,0x00,0x00,//"星"左下半部分代码 0x05 0x08,0x1F,0x08,0x1F,0x00,0x00,0x00,0x00//"星"右下半部分代码 0x06 }; uchar tab[]={'0','8',0x00,'0','3',0x01,'0','9',0x02};//显示"08年03月09日" void delay(uint t) { uint x,y; for(x=0;x<t;x++) for(y=0;y<110;y++); } void write_com(uchar com)//向1602写指令 { lcdrs=0; P2=com; delay(5); lcden=1; delay(5); lcden=0; } void write_date(uchar dat)//向1602写数据 { lcdrs=1; P2=dat; delay(5); lcden=1; delay(5); lcden=0; } void init()//程序初始化 { lcdwr=0; lcden=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); } void main()//主函数 { int i; init(); lcdrs=0; lcdwr=0; write_com(0x40);//将自定义字符写入CGRAM for(i=0;i<56;i++)//循环56次写入 { write_date(CGCODE[i]); } write_com(0x80);//写入初始地址 for(i=0;i<9;i++) { write_date(tab[i]); } write_com(0x80+9);//用09H和0AH显示"星"上部分 write_date(0x03); write_date(0x04); write_com(0x80+0x40+9);//用49H和4AH显示"星"上部分 write_date(0x05); write_date(0x06); while(1);
}
其他相关页面: