⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 g6963.c

📁 T6963128*64液晶显示驱动程序!
💻 C
字号:
//         电机节电器
//液晶显示器地址:p27--CS  P26--C/D  WR--WR  RD--RD 则
//                00 00 0000 0000 0000(数据通道)
//                01 00 0000 0000 0000(指令通道)
//               ;
//g6963.c--图形方式下的汉字、字符显示程序
//

#include <reg51.h>
#include <absacc.h>       // XBYTE
#include <intrins.h>    //_nop_()

//#define CWADD XBYTE[0x4000]                  //写指令代码地
//#define DWADD XBYTE[0x0000]                  //写数据通道地址
#define CWADD XBYTE[0xa000]                  //写指令代码地
#define DWADD XBYTE[0x8000]                  //写数据通道地址


void sta01(void)                           //判断状态位
{
   while((CWADD&3)!=3);

    }
/*
void sta2(void)
{
while((CWADD&4)!=4);
	 }
*/
void sta3(void)
{
//_nop_();
//_nop_();
//_nop_();
while((CWADD&8)!=8);

	 }

/*
void sta6(void)
{
while((CWADD&0x40)!=0x40);
	 }
*/

//写指令和写数据子程序

void writecode(unsigned char com)             //写无参数指令
{  
   sta01();
   CWADD=com;
   }
void write1byte(unsigned char dat1,unsigned char com)    //写单字节参数指令
{  
   sta01();
   DWADD=dat1;
   sta01();
   CWADD=com;
   }

void write2byte(unsigned char dat1,unsigned char dat2,unsigned char com)
{                                                        //写双字节参数指令 
   
   sta01();
   DWADD=dat1;

   sta01();
   DWADD=dat2;

   sta01();
   CWADD=com;
   }

/*
unsigned char readdata(void)    //读数据子程序
{   unsigned char x;

    sta01();
	x=DWADD;
    return(x);
	}

*/

void disp_ini(void)                //显示屏初始化子程序
{
    write2byte(0x00,0x00,0x40);//设置显示区域首地址0000h
 	write2byte(0x10,0x00,0x41);//设置文本显示的宽度,即一行所占的字节数(12864t,16个8X8点阵字符)
	write2byte(0x00,0x08,0x42);//设置图形显示区域首地址0800h,或为文本属性区域首地址
	write2byte(0x10,0x00,0x43);//设置图形显示区域宽度,或为文本属性区域宽度(12864t,16个8x8点阵字符)

	writecode(0xa7);//光标形状设置
	writecode(0x9c);//显示开关设置,g\t all on!
	writecode(0x80);//显示方式设置,逻辑或合成/////////////////////////////////


	}

void clearram(void)                //清屏程序
{   
    unsigned int  i;

    write2byte(0x00,0x00,0x24);//设置显示ram首地址0000h

	writecode(0xb0);           //设置自动写方式

	for(i=8192;i>0;i--)   //往显示区域写0;区域大小8k
	{
	   sta3();
	   DWADD=0;
	   };

	writecode(0xb2);              //关闭自动写指令

	}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//汉字点阵,存储在程序存储器中
/* 点阵:16x16
   提取点阵方向:横向(先上->下, 再左->右)
   字节掉转:否
   字节方式:C语言 */


unsigned char code yi[32]={ 
0x1F,0x10,0x10,0x1F,0x10,0x10,0x1F,0x08,    // 易    
0x1F,0x24,0x44,0x88,0x10,0x21,0x02,0x04,
0xF0,0x10,0x10,0xF0,0x10,0x10,0xF0,0x04,
0xFE,0x44,0x44,0x84,0x84,0x04,0x28,0x10};

unsigned char code xian[32]={ 
0x01,0x11,0x11,0x1F,0x11,0x21,0x01,0xFF,    // 先           
0x04,0x04,0x04,0x08,0x08,0x10,0x20,0x40,
0x00,0x00,0x10,0xF8,0x00,0x00,0x04,0xFE,
0x80,0x80,0x80,0x80,0x82,0x82,0x7E,0x00};

unsigned char code jun[32]={ 
0x00,0x7F,0x42,0x82,0x3F,0x04,0x09,0x11,    // 军           
0x3F,0x01,0x01,0xFF,0x01,0x01,0x01,0x01,
0x00,0xFE,0x02,0x14,0xF8,0x00,0x00,0x10,
0xF8,0x00,0x04,0xFE,0x00,0x00,0x00,0x00};

unsigned char code hao[32]={
0x10,0x11,0x10,0x10,0xFC,0x24,0x24,0x27,    // 好
0x24,0x44,0x28,0x10,0x28,0x44,0x84,0x00,
0x00,0xFC,0x04,0x08,0x10,0x20,0x24,0xFE,
0x20,0x20,0x20,0x20,0x20,0x20,0xA0,0x40
};

unsigned char code wen[32]={
0x00,0x43,0x32,0x12,0x83,0x62,0x22,0x0B,    // 温
0x10,0x27,0xE4,0x24,0x24,0x24,0x2F,0x20,
0x08,0xFC,0x08,0x08,0xF8,0x08,0x08,0xF8,
0x00,0xFC,0xA4,0xA4,0xA4,0xA4,0xFE,0x00};

unsigned char code du[32]={
0x01,0x00,0x3F,0x22,0x22,0x3F,0x22,0x23,    // 度
0x20,0x2F,0x22,0x21,0x20,0x43,0x8C,0x30,
0x00,0x84,0xFE,0x20,0x28,0xFC,0x20,0xE0,
0x00,0xF0,0x20,0x40,0x80,0x60,0x1E,0x04};

unsigned char code wei[32]={
0x00,0x10,0x0C,0x04,0x00,0xFF,0x01,0x01,    // 为
0x02,0x02,0x04,0x08,0x10,0x20,0x40,0x00,
0x80,0x80,0x80,0x80,0x84,0xFE,0x04,0x04,
0x04,0x84,0x64,0x24,0x04,0x04,0x28,0x10};


//本文件为8×16点阵西文字库文件,字的横向8点构成一字节,左边点在字节的高位,字符点阵四角按左上角→右上角→左下角→右下角取字*/
/*0    */
unsigned char code ch0[16]={
0x00,0x00,0x7C,0xC6,0xC6,0xCE,0xD6,0xD6,
0xE6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00};

/*1    */
unsigned char code ch1[16]={
0x00,0x00,0x18,0x38,0x78,0x18,0x18,0x18,
0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00};

/*2    */
unsigned char code ch2[16]={
0x00,0x00,0x7C,0xC6,0x06,0x0C,0x18,0x30,
0x60,0xC0,0xC6,0xFE,0x00,0x00,0x00,0x00};

/*3    */
unsigned char code ch3[16]={
0x00,0x00,0x7C,0xC6,0x06,0x06,0x3C,0x06,
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00};

/*4    */
unsigned char code ch4[16]={
0x00,0x00,0x0C,0x1C,0x3C,0x6C,0xCC,0xFE,
0x0C,0x0C,0x0C,0x1E,0x00,0x00,0x00,0x00};

/*5    */
unsigned char code ch5[16]={
0x00,0x00,0xFE,0xC0,0xC0,0xC0,0xFC,0x0E,
0x06,0x06,0xC6,0x7C,0x00,0x00,0x00,0x00};

/*6    */
unsigned char code ch6[16]={
0x00,0x00,0x38,0x60,0xC0,0xC0,0xFC,0xC6,
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00};

/*7    */
unsigned char code ch7[16]={
0x00,0x00,0xFE,0xC6,0x06,0x06,0x0C,0x18,
0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00};

/*8    */
unsigned char code ch8[16]={
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7C,0xC6,
0xC6,0xC6,0xC6,0x7C,0x00,0x00,0x00,0x00};

/*9    */
unsigned char code ch9[16]={
0x00,0x00,0x7C,0xC6,0xC6,0xC6,0x7E,0x06,
0x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00
};


void gshowword(unsigned char y,unsigned char x,unsigned char *w_no) //图形方式下显示一个汉字字符(分为左右两半字模)
{        //128*64dots,x--显示在第x(0~15)字符列!,y--显示在第y(0~63)点阵!行,w_no为tab代码   
         //调用示例:gshowword(2,4,hao)  在第二行第四列显示"好" ----gshowword(点阵行,字符列,数组首地址)  
   unsigned int num;
   unsigned char d1,d2,i=16;
   num=y*16+x+0x800;                 //16--每行显示宽度为16个字符;0--图形显示区首地址为0800h
  
   
   
 for(i=16;i>0;i--)
  {    d1=num/256;                       //得到显示屏上汉字显示的相对位置
       d2=num%256;
       write2byte(d2,d1,0x24);
       write1byte(*w_no,0xc0);            //写汉字左代码
       write1byte(*(w_no+16),0xc0);       //写汉字右代码
       w_no++;
       num+=0x10;                         //显示ram地址修正

    	}

  }

void gshowchar(unsigned char y,unsigned char x,unsigned char *w_no) //图形方式下显示一个字符(分为左右两半字模)
{                    //128*64dots,x--显示在第x(0~15)字符列!,y--显示在第y(0~63)点阵!行,w_no为tab代码   
                     //调用示例:gshowword(2,4,hao)  在第二点阵行第四字符列显示"好"   
   unsigned int num;
   unsigned char d1,d2,i=16;
   num=y*16+x+0x800;                 //16--每行显示宽度为16个字符;0--图形显示区首地址为0800h
 
   for(i=16;i>0;i--)
    {   
       d1=num/256;                       //得到显示屏上汉字显示的相对位置
       d2=num%256;
       write2byte(d2,d1,0x24);
	   write1byte(*w_no,0xc0);            //写汉字左代码
  //     write1byte(*(w_no+16),0xc0);       //写汉字右代码
       w_no++;
	   num+=0x10;                         //显示ram地址修正
    	}

  }

 
//////////////////////////////////////////////////////////////////////////////////////////////
/*
void disp3ch(unsigned char y,unsigned char x,unsigned int var) 
{           //带灭零处理的三位数显示子程序(可显示0~511),var指要显示的数据
    uchar d2,d1,d0;
    d2=(var&0x1ff)/100;d1=(var%100)/10;d0=(var%100)%10;
    
    if(d2==0)  gshowchar(y,x,clearchar);                   
    else gshowchar(y,x,ch0+0x10*d2);      //显示百位 
         
    if((d2==0)&&(d1==0)) {gshowchar(y,x,clearchar);gshowchar(y,x+1,clearchar);} 
    else gshowchar(y,x+1,ch0+0x10*d1);    //显示十位
    
    gshowchar(y,x+2,ch0+0x10*d0);                              //显示个位
}

void disp2ch_dot(unsigned char y,unsigned char x,uchar var) 
{           //带灭零处理及小数点的2位数显示子程序(可显示0.0~9.9),var指要10*(显示的数据)
    gshowchar(y,x,ch0+0x10*(var/10));        //显示个位
    gshowchar(y,x+1,dot);                    //显示小数点
    gshowchar(y,x+2,ch0+0x10*(var%10));      //显示十分位
}
*/
///////////////////////////////////////////////////////////////////////////////////////////////

void main(void)               //test program segment
{ //  AK=0;
	//FS=0;

    disp_ini();
    clearram();
 
 
    gshowword(4,4,yi);            //在第4行(点阵行!不是字符行!)第四列(字符列!)显示"易先军好"
    gshowword(4,6,xian);
    gshowword(4,8,jun);
  //  gshowword(4,10,hao);

 
	
	gshowchar(50,6,ch2);           //diaplay number:28
	gshowchar(50,7,ch0+0x10*8);  //以“0”所在的字库首址为基地址显示数据,
	                               //调用形式:gshowchar(y,x,ch0+0x10*n) 显示数字n

    while(1);
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -