本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
- /***********************************************************
- 内置T6963C液晶控制器驱动程序(间接方式)
- ***********************************************************/
- //读取LCD状态字
- uchar readstate(void)
- {
- uchar lcd_state;
- DDRA=0x00;
- DDRC|=(1<<3);
- DDRE|=(1<<6);
- PORTC|=(1<<3); // C/D=1
- PORTE&=~(1<<6); // /RD=0
- lcd_state=PINA&0xff; // 读取引脚A物理电平
- NOP();
- NOP();
- PORTE|=(1<<6); // /RD=1
- return lcd_state;
- }
- //判断指令(数据)读写状态
- void st01(void)
- {
- while((readstate()&0x03)!=3)
- ;
- }
- //判断数据自动读状态
- void st2(void)
- {
- while((readstate()&0x04)!=4)
- ;
- }
- //判断数据自动写状态
- void st3(void)
- {
- while((readstate()&0x08)!=8)
- ;
- }
- //指令写入函数
- void writecode(uchar comd0)
- {
- st01();
- DDRA=0xff; //A口方向为输出
- PORTA=comd0; //送数据到A口寄存器
- DDRE|=(1<<7);
- PORTE&=~(1<<7); // /WR=0
- NOP();
- PORTE|=(1<<7); // /WR=1
- }
- //数据写入函数
- void writedata(uchar onedata)
- {
- st01();
- DDRC|=(1<<3);
- PORTC&=~(1<<3); // C/D=0,数据通道
- DDRA=0xff; //A口方向为输出
- PORTA=onedata; //送数据到A口寄存器
- DDRE|=(1<<7);
- PORTE&=~(1<<7); // /WR=0
- NOP();
- PORTE|=(1<<7); // /WR=1
- }
- //数据自动写入函数
- void writeauto(uchar onedata)
- {
- st3();
- DDRC|=(1<<3);
- PORTC&=~(1<<3); // C/D=0,数据通道
- DDRA=0xff; //A口方向为输出
- PORTA=onedata; //送数据到A口寄存器
- DDRE|=(1<<7);
- PORTE&=~(1<<7); // /WR=0
- NOP();
- PORTE|=(1<<7); // /WR=1
- }
- //一字节参数指令写入函数
- void oneparameter(uchar onep1,uchar comd1)
- {
- writedata(onep1);
- writecode(comd1);
- }
- //两字节参数指令写入函数
- void twoparameter(uchar twop1,uchar twop2,uchar comd2)
- {
- writedata(twop1);
- writedata(twop2);
- writecode(comd2);
- }
- /***********************************************************
- 液晶初始化,清屏
- ***********************************************************/
- //内置T6963C控制器液晶初始化函数
- void lcd_init(void)
- {
- twoparameter(0x00,0x00,0x40); //文本显示区域首地址0x0000
- twoparameter(0x20,0x00,0x41); //文本显示区域宽度32字节
- twoparameter(0x00,0x08,0x42); //图形显示区域首地址0x0800
- twoparameter(0x20,0x00,0x43); //图形显示区域宽度32字节
- writecode(0xa7); //光标形状
- writecode(0x80); //显示方式设置(使用内部CGROM,逻辑或合成)
- writecode(0x9c); //显示开关(开文本和图形显示方式,禁止光标显示和闪烁)
- }
- //清除屏幕(清所有8K存储空间)
- void lcd_clear(void)
- {
- uint cl_count;
- twoparameter(0x00,0x00,0x24); //设置显示存储器首地址
- writecode(0xb0); //设置自动写状态
- for(cl_count=8192;cl_count>0;cl_count--)
- writeauto(0x00);
- writecode(0xb2); //关闭自动写状态
- }
- /********************************************************
- 西文字符,汉字,点阵显示函数
- ********************************************************/
- //西文字符写入函数
- //x_asc:0~29; y_asc:0~15
- void writeasc(uchar x_asc,uchar y_asc,uchar code_asc)
- {
- uint address;
- address=y_asc*32+x_asc;
- twoparameter((uchar)(address),(uchar)(address>>8),0x24); //设置显示存储器地址
- oneparameter(code_asc,0xc4); //装入字符代码,写入数据,地址不变
- }
- //汉字写入函数
- //x_hz:0~29; y_hz:0~127
- void writehz(uchar x_hz,uchar y_hz,uchar code_hz)
- {
- uchar i_hz;
- uint address,addr_hz;
- address=y_hz*32+x_hz+0x0800; //计算显示存储器地址
- addr_hz=code_hz*32; //计算汉字字模地址(cctab的下标)
- for(i_hz=0;i_hz<16;i_hz++) //计数值16
- {
- twoparameter((uchar)(address),(uchar)(address>>8),0x24); //设置显示存储器地址
- oneparameter(cctab[addr_hz],0xc0); //写入汉字字模左部
- oneparameter((cctab[16+addr_hz++]),0xc0); //写入汉字字模右部
- address+=32; //修改显示存储器地址,显示下一列(共16列)
- }
- }
- //显示一个点函数
- //x:0~239; y:0~127(消除点)128~255(显示点)
- void writepoint(uchar x,uchar y)
- {
- uchar x_pt,y_pt;
- uint address;
- x_pt=x;
- y_pt=y;
- address=(y_pt&0x7f)*32+x_pt/8+0x0800; //计算显示存储器地址
- twoparameter((uchar)(address),(uchar)(address>>8),0x24); //设置显示存储器地址
- x_pt=(~(x_pt%8))&0x07;
- y_pt=((y_pt&0x80)>>4)|0xf0;
- writecode(x_pt|y_pt); //写入数据
- }
- //显示矩形框
- //x:0~239; y:0~127
- void rectangle(uchar xstar,uchar xend,uchar ystar,uchar yend)
- {
- uchar i;
- ystar+=128; //显示点
- yend+=128;
- for(i=xstar;i<=xend;i++) //两水平线
- {
- writepoint(i,ystar);
- writepoint(i,yend);
- }
- for(i=ystar;i<=yend;i++) //两垂直线
- {
- writepoint(xstar,i);
- writepoint(xend,i);
- }
- }
- //擦除矩形框
- //x:0~239; y:0~127
- void clrrect(uchar xstar,uchar xend,uchar ystar,uchar yend)
- {
- uchar i;
- for(i=xstar;i<=xend;i++) //两水平线
- {
- writepoint(i,ystar);
- writepoint(i,yend);
- }
- for(i=ystar;i<=yend;i++) //两垂直线
- {
- writepoint(xstar,i);
- writepoint(xend,i);
- }
- }
- //8*8点阵显示
- //x:0~239; y:0~127
- void disp88(uchar x,uchar y)
- {
- uchar i,datpt,x_temp,y_temp;
- y_temp=y;
- for(i=8;i>0;i--)
- {
- datpt=*ptr0++; //取数据
- x_temp=x; //重装x值
- if(datpt&0x80)
- writepoint(x_temp++,(y_temp+128));
- else writepoint(x_temp++,y_temp);
- if(datpt&0x40)
- writepoint(x_temp++,(y_temp+128));
- else writepoint(x_temp++,y_temp);
- if(datpt&0x20)
- writepoint(x_temp++,(y_temp+128));
- else writepoint(x_temp++,y_temp);
- if(datpt&0x10)
- writepoint(x_temp++,(y_temp+128));
- else writepoint(x_temp++,y_temp);
- if(datpt&0x08)
- writepoint(x_temp++,(y_temp+128));
- else writepoint(x_temp++,y_temp);
- if(datpt&0x04)
- writepoint(x_temp++,(y_temp+128));
- else writepoint(x_temp++,y_temp);
- if(datpt&0x02)
- writepoint(x_temp++,(y_temp+128));
- else writepoint(x_temp++,y_temp);
- if(datpt&0x01)
- writepoint(x_temp++,(y_temp+128));
- else writepoint(x_temp++,y_temp);
- y_temp++;
- }
- }
- //16*8点阵显示
- //x:0~29; y:0~127
- void disp168(uchar x,uchar y)
- {
- uchar i;
- uint address;
- address=y*32+x+0x0800; //计算显示存储器地址
- for(i=8;i>0;i--)
- {
- twoparameter((uchar)(address),(uchar)(address>>8),0x24); //设置显示存储器地址
- oneparameter(*ptr0++,0xc0); //点阵左部
- oneparameter(*ptr0++,0xc0); //点阵右部
- address+=32; //修改显示存储器地址
- }
- }
- //连续写点阵
- //x:0~29; y:0~127
- void dispauto(uchar x,uchar y,uchar line,uchar column)
- {
- uchar i,j;
- uint address;
- address=y*32+x+0x0800; //计算显示存储器地址
- for(i=line;i>0;i--) //显示line行
- {
- twoparameter((uchar)(address),(uchar)(address>>8),0x24); //设置显示存储器地址
- writecode(0xb0); //数据自动写状态
- for(j=column;j>0;j--) //共column列
- {
- writeauto(*ptr0++); //自动写入数据
- }
- writecode(0xb2); //关闭自动写状态
- address+=32; //修改显示存储器地址
- }
- }
复制代码 |