SAY 发表于 2024-4-21 00:16:32

T6963c(240*128)液晶驱动(AVR Mega128) C语言

/***********************************************************内置T6963C液晶控制器驱动程序(间接方式)***********************************************************///读取LCD状态字uchar readstate(void){uchar lcd_state;DDRA=0x00;DDRC|=(1<<3);DDRE|=(1<<6);PORTC|=(1<<3); // C/D=1PORTE&=~(1<<6); // /RD=0lcd_state=PINA&0xff; // 读取引脚A物理电平NOP();NOP();PORTE|=(1<<6); // /RD=1return 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=0NOP();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=0NOP();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=0NOP();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); //文本显示区域首地址0x0000twoparameter(0x20,0x00,0x41); //文本显示区域宽度32字节twoparameter(0x00,0x08,0x42); //图形显示区域首地址0x0800twoparameter(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~15void 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~127void 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,0xc0); //写入汉字字模左部oneparameter((cctab),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~127void 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~127void 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~127void 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~127void 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~127void 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; //修改显示存储器地址}}

111 发表于 2024-4-21 00:16:38

焊!!!!!!!!!!!!!!!!!!

isebufusiza 发表于 2024-4-21 00:16:54

thanks!!!!!!!!!!!!!!!!!!
页: [1]
查看完整版本: T6963c(240*128)液晶驱动(AVR Mega128) C语言