* 很多程序都没有用,但是参照这些,起码可以驱动起来了。对刚拿到片子的或点不亮的希望有点帮助吧。 *
www.ouravr.com/bbs/bbs_content.jsp?bbs_sn=1389717&bbs_page_no=1&search_mode=3&search_text=friendljy&bbs_id=9999 *
* 会员ql-dz.com学习领会和修改部分内容 2008年9月17日
*
* 我是菜鸟,很多地方都似懂非懂,有的地方根本不明白.敬请原作者friendljy和大家给予指点,特别是打??的地方......
/**************************预处理*************************/ #include #include //=========================LCD接口引脚定义====================== sbit LCDA0=P2^5; sbit LCDSK=P2^6; sbit LCDSI=P2^7; sbit LCDRS=P2^4; //=========================函数声明============================= void //初始化函数 LCDInit(); void LCDWriteByte(char dat,char command); //一为待写内容,二为命令/数据选择(0命令,1数据) void LCDShiftWrite(char dat); //逐位写一个字节 void LCDSetXY(char x, char y); //行列坐标设置 void LCDcls(char); //清屏函数,全屏写入某个字节value void menushow(char line,char num,char state); //?? void gbshow(char x,char y,unsigned char *p); //?? void asc816show(char x,char y,unsigned char *p); //8x16点阵ASCII字符显示 void asc1632show(char x,char y,unsigned char *p); //16x32点阵ASCII字符显示 void asc1632bottom(char x,char state); //??? void delayms(unsigned char ms); //延时函数 //***************************数组列表******************************* extern unsigned char code hzcode[][128]; //?? extern unsigned char code gbcode[][32]; //?? extern unsigned char code asc816code[][16]; //?? extern unsigned char code asc1832code[][64]; //?? extern unsigned char code arrow[]; //?? //===========================主程序================================= void main(void) { //显示示例显示内容,????如何让其显示特定的字符串和需要的随机内容???? LCDInit(); while(1) { asc816show(1,3,30); LCDSetXY(0x00,0x00); LCDWriteByte(0x00,1); LCDSetXY(0x01,0x00); LCDWriteByte(0x3C,1); LCDSetXY(0x02,0x00); LCDWriteByte(0x7C,1); LCDSetXY(0x03,0x00); LCDWriteByte(0xC0,1); LCDSetXY(0x04,0x00); LCDWriteByte(0xC0,1); LCDSetXY(0x05,0x00); LCDWriteByte(0x7C,1); LCDSetXY(0x06,0x00); LCDWriteByte(0x3C,1); LCDSetXY(0x07,0x00); LCDWriteByte(0x00,1); LCDSetXY(0x00,0x01); LCDWriteByte(0x00,1); LCDSetXY(0x01,0x01); LCDWriteByte(0x00,1); LCDSetXY(0x02,0x01); LCDWriteByte(0x08,1); LCDSetXY(0x03,0x01); LCDWriteByte(0x0f,1); LCDSetXY(0x04,0x01); LCDWriteByte(0x0f,1); LCDSetXY(0x05,0x01); LCDWriteByte(0x08,1); LCDSetXY(0x06,0x01); LCDWriteByte(0x00,1); LCDSetXY(0x07,0x01); LCDWriteByte(0x00,1); } } //======================== 液晶================================= void LCDInit() { LCDRS=0; delayms(100); LCDRS = 1; delayms(100); LCDWriteByte(0xe2,0); 为0.)=== delayms(100); LCDWriteByte(0x84,0); LCDWriteByte(0x07,0); LCDWriteByte(0x82,0); LCDWriteByte(0x03,0); LCDWriteByte(0x85,0); 显示模块初始化 //?? //?? //复位(第二个数原为1疑有误,个人改 //?? //?? //?? //?? //?? LCDWriteByte(0x0a,0); //?? LCDWriteByte(0xa1,0); //0xa0为Segment正向,0xa1 为Segment反向(0xa0-0xa1为ADC方向选择) LCDWriteByte(0xc0,0); //0xc0正向扫描,0xc8反射扫描 LCDWriteByte(0xa6,0); //0xa6正向显示,0xa7反向显示 LCDWriteByte(0x26,0); 设置 LCDWriteByte(0x81,0); LCDWriteByte(0x0f,0); LCDWriteByte(0x2f,0); 随电路均开(0x28-0x2f为设置上电控制模式) LCDWriteByte(0xa4,0); LCDcls(0); 全屏写入0 LCDWriteByte(0xaf,0); } //======================== 写 一 个 据)============================= void LCDWriteByte(char dat,char command) { // LCDCS = 0; 只使用一片CS,已将其直接接地. if(command == 0) { LCDA0 = 0; 写命令 LCDShiftWrite(dat); } else { LCDA0 = 1; 写数据 LCDShiftWrite(dat); } //0x20-0x27为V5电压内部电阻调整 //电量设置模式 //0x01-0x3f电量寄存器设置模式 //0x2f升压电路,电压管理电路,电压跟 //0xa4正常显示,0xa5全屏点亮 //屏上的点都不点亮, //0xaf显示器开,0xae显示器关 字 节 ( 命 令 或 显 示 数 //CS=0.注:因 //A0=0,为 //A0=1,为 // LCDCS = 1; //CS=1.注:因只使用一片CS,已将其直接接地. } //===========================void LCDShiftWrite(char dat) { unsigned char i; //定义局部逐位(串行)写完一个字节 ================================ 变量 unsigned char Series,Temp; LCDSK = 0; Series = dat; for(i=0; i<8; i++) { LCDSK = 0; Temp=Series & 0x80; if(Temp) 则使SI=1.如果Temp+0,则使SI=0 { LCDSI = 1; } else { LCDSI = 0; } LCDSK = 1; Series = Series << 1; } } //定义局部变量 //SCL=0 //SCL=0 //屏蔽低7位 //如果Temp=1, //SI=1 //SI=0 //SCL=1上升沿写 //左移1位 因篇幅问题不能全部显示,请点此查看更多更全内容