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

📄 k6963.c

📁 在keil开发环境下
💻 C
字号:
#include "busdefine.h"
#include "k6963.h"
#define   HIGH   128
//****-------------------****************************************************
//*** 状态位 判断函数 *************************
//---------------------------
#ifdef LCMCW
void  rstatew(void)    //DMA
{                     //mov dptr,#LCMCW   movx A,@dptr   ANL  A,#03H
   data6963 = LCMCW ;
     }

#else	  // using indirective access 6963
void rstatew(void){    //can in init e6963=0; only change in w373
   dataport=0xff;      //but must guarantee wr=1 and rd=1 in no r/w state
                   cd6963=1; r6963=0;   //benifit w/r operate after rstatew
   data6963 = dataport;
   r6963=1 ;
   }

/*uchar r6963d(void){    //can in init e6963=0; only change in w373
   dataport=0xff;      //but must guarantee wr=1 and rd=1 in no r/w state
   cd6963=0; r6963=0;   //benifit w/r operate after rstatew
   data6963 = dataport;
   r6963=1 ;
   return (data6963);
   }*/

void  w6963cm(uchar temp){
	cd6963=1;
    dataport = temp;   //note: in write a add parameter command,
    w6963 = 0;         //w parameter cd=0,but w command cd=1 !!!
	_nop_();
	w6963=1 ;
	                    }

void  w6963d(uchar temp){
	cd6963=0;
    dataport = temp;    //note: in write a add parameter command,
	w6963 = 0;          //w parameter cd=0,but w command cd=1 !!!
    _nop_();
	w6963=1 ;
	                    }
#endif


//****-------------------******************************************************
//*** 状态位判断函数 **********************************************************
//***状态位ST01判断函数
uchar Jst01(void) {   //ST01:command and data r/w state flag,0 is busy
  uchar i;
  for(i=10;i>0;i--) {   // in 10*times no ready,this is error
    rstatew();
    if((data6963 & 0x03) == 0x03)
	break;
  }
  return i; 	// 若返回零,说明错误
}

// --状态位ST2判断函数 ---
/*uchar Jst2(void)
{	         //st2: data auto read, 1 is ready
  uchar i;
  for(i=10;i>0;i--) {
    rstatew();
    if((data6963 & 0x04) == 0x04)
		break;
  }
  return i;
} */

// 状态位ST3判断函数 *********
uchar Jst3(void)
{           //st3: data auto write, 1 is ready
  uchar i;
  for(i=10;i>0;i--) {
    rstatew();
    if((data6963 & 0x08) == 0x08)
		break;
  }
  return i;
}

//--状态位ST6判断函数 *****
/*uchar Jst6(void)
{              //ST6:屏读/屏拷贝,1 is error,0 is right
  uchar i;
  for(i=10;i>0;i--) {
    rstatew();
    if((data6963 & 0x40) == 0x40)
		break;
  }
  return i;
}
*/

//---read and write LCM6963 *********************************************
//---------------------------------
void w2parCmd(uchar upar1,uchar upar2,uchar ucmd)
{
  if(Jst01() == 0);    //writed paramter before writing command word
    w6963d(upar1);
  if(Jst01() == 0);
    w6963d(upar2);
  if(Jst01() == 0);
    w6963cm(ucmd);
}

//写单参数命令函数 **********
void  w1parCmd(uchar upar1,uchar ucmd)
{
   if(Jst01() == 0) ;
    w6963d(upar1);
   if(Jst01() == 0);
    w6963cm(ucmd);
}

//写无参数命令函数 **********
void  w0parCmd( uchar ucmd)
{
  // if(ucmd==Sword_autowr) EA=0 ;
  //guarantee large of data right,but much effect wave !!!
  if(Jst01() == 0);
  w6963cm(ucmd);
  // if(ucmd==Sword_autover) EA=1 ;
 }

// auto写数据函数 ----------
void autowdata(uchar udata)
{
   if(Jst3() == 0);      //auto write ready = 1
   w6963d(udata);
}


// 读数据函数 -------------
/*uchar srdata(void) {
  if(Jst01() == 0)
		return 1;
  return (r6963d);
}
*/

// 液晶模块初始化函数 *******************
void LCM240ini(void) {
  w2parCmd(0x00,0x00,Sword_txtsadd) ; /* 文本显示区首地址 0000--07ffh*/
  w2parCmd(0x1e,0x00,Sword_txtwid); // 文本显示区宽度240/8
   //after address and screen position by this ,must by factal size of screen
  w2parCmd(0x00,addh_disramg,Sword_grasadd); /* 图形显示区首地址 0800--17ffh*/
  w2parCmd(0x1e,0x00,Sword_grawid); // 图形显示区宽度240/8

  w0parCmd(Sword_cursha | 0x01); 	/* 光标形状 */
  w0parCmd(Sword_modor); 		    /* 显示方式设置 */
  w0parCmd(dissw_model | 0x0c);    /* 图形and文本显示all启用 */

}


//-----清屏函数 ****************************
void clr(void) {
  uint i;
  w2parCmd(0,0,Sword_disramadd); 	/* 置display Ram 地址指针 */
  w0parCmd(Sword_autowr);				/* 自动写 */
  for(i=0;i<1024*8;i++) {  //clear 6k display memory+ 2k cgram/cgrom lib
	          //
		autowdata(0x00); 				/* 写数据 */
  }
  w0parCmd(Sword_autover); 			/* 自动写结束 */
}


//----------------------
//---display text***********************************************************
//---create cgram region ********************
void  creat_cgram(uchar count, uchar *cgram)
{             //putout 8*8 dots when count==1
  uint  i;    //32*32 max size
  w2parCmd(0x03,0x00,Sword_cgram);   //set cgram address in enable cgrom
  w2parCmd(0x00,0x1c,Sword_disramadd);
  w0parCmd(Sword_autowr);     //count must < 128 in enable cgrom
  for (i=0;i< count*8 ; i++) autowdata( cgram[i] );
  w0parCmd(Sword_autover);
                           }

//--------------------------------------
void  discgrom(uchar linewide, uchar *pgraph )
{
    uchar temp_char;
    uchar temp_column;
loop:
    temp_column=column;//put a string,format 8*8 by row sequency                                        //row  0--7 ,columa 0--29 for 240*64 in tex
	addl = (row * 30 + column)%256 ;    //row  0--7 , columa 0--29 for 240*64 in graph
	addh = (row * 30 + column)/256 ;    //graph display ram start 0000h
    w2parCmd(addl,addh,Sword_disramadd);
    w0parCmd(Sword_autowr);			     /* 自动写 */
    while (*pgraph>=0x20 && *pgraph<=0x7f)//must require string has end flag
  {               //skip it while space is the first letter in row
	 if( (*pgraph==0x20) && (temp_column==0) ) pgraph++;
     if( (*pgraph==0x20) && (temp_column==column) && indentfg ) pgraph++;
	 temp_char = *pgraph;
	 temp_char  -= 0x20;  // ascii change to inner 6963
 	 autowdata(temp_char);
  	 pgraph++ ;
	 temp_column++;
    if(temp_column==linewide) temp_column=0;
                    //can change linewide and set auto indent
    if( indentfg && (temp_column==linewide) )
    {
    w0parCmd(Sword_autover); row++; goto loop;
	}
                    //linewide <30
    if((temp_column==linewide) && (linewide <30) )
	{
    w0parCmd(Sword_autover); row++; column=0; goto loop;
	}
     }
     w0parCmd(Sword_autover);    // 自动写结束
  	}

//----------------------
void  distext(uchar width,uchar high)
{ // by row include cgrom and cgram
  uchar i;
  while( high--)
  {
  addl = (row * 30 + column)%256 ;   //30 must calculate by in fact size of screen
  addh = (row * 30 + column)/256;   //graphic display ram start 0800h
  w2parCmd(addl,addh,Sword_disramadd);
  w0parCmd(Sword_autowr);				/* 自动写 */
  for(i=0;i<width;)  //width + column(start) must <= 30
  {//cant while( width--), while only use one time.
	autowdata(0x80); 				/* 写数据 */
		autowdata(0);
			autowdata(0);
				autowdata(0);
					autowdata(0x81);
					i+=5;
  }
  w0parCmd(Sword_autover); 			/* 自动写结束 */
    row++;
           }
  }

//------------------
void  clrtext(uchar width,uchar high)
{                           //put a string,format 8*8 by row sequency                                        //row  0--7 ,columa 0--29 for 240*64 in tex
  uchar i;
  while( high--)
  {
  addl = (row * 30 + column)%256 ;   //30 must calculate by in fact size of screen
  addh = (row * 30 + column)/256;   //graphic display ram start 0800h
  w2parCmd(addl,addh,Sword_disramadd);
  w0parCmd(Sword_autowr);				/* 自动写 */
  for(i=0;i<width;i++)  //width + column(start) must <= 30
  {//cant while( width--), while only use one time.
		autowdata(0);
  }
  w0parCmd(Sword_autover); 			/* 自动写结束 */
    row++;
           }
  }


//------************************************************************************
//---display word---------------------------------------------------------------
//---------------------------
void  disWord816_cgram(uchar startcode,uchar length)
{ // code is cotinuing! and putout one line !
    uchar temp,i,j;
    for(i=0;i<length;i++)
   {
    temp= row;
    for(j=2;j>0;j--)
	{
    addl = (temp * 30 + column)%256 ;   //30 must calculate by in fact size of screen
    addh = (temp * 30 + column)/256 ;
    w2parCmd(addl,addh,Sword_disramadd); //display grahhic only need write factal code
    w1parCmd(startcode++,sword_wr_inc);   //to relative address display ram of graphic
   	temp++;
	       }
	  column++;
	  }
  }

//--------------------------------
void  distime_cgram(uchar time)
{    //8*16 by row
    uchar temph,templ;
    temph = 0x80 + ( time/10 )*2;
	templ = 0x80 + ( time%10 )*2;
	disWord816_cgram(temph,1);
//	column ++;
	disWord816_cgram(templ,1);
  	}

//------------------
/*void  disWord1616_graph(uchar coordinate,uchar *graphic)
{   //scanf by row, per scanf 1/16 high of word, putout 16*16 namely a word.
    uchar  count,temp;
	temp= row;
    graphic = graphic + 32*coordinate;  //chinese 16*16 include 32 bytes, i is start address of
    for(count=0;count<16;count++) //32byte/2byte=16                //displayed code
	{
    addl = (temp * 30 + column)%256 ;   //30 must calculate by in fact size of screen
    addh = (temp * 30 + column)/256+addh_disramg;   //graphic display ram start 0800h
    w2parCmd(addl,addh,Sword_disramadd); //display grahhic only need write factal code
    w1parCmd(*graphic++,sword_wr_inc);   //to relative address display ram of graphic
    w1parCmd(*graphic++,sword_wr_inc);   //because no cgrom or cgram
	temp++;    // 4K display ram only display 32*4 =128(16*16=256 dots) chinese word
                      }    // namely 1024*8*4=256*128
                        }

//---------------------
void  disWord816_graph(uchar coordinate,uchar *graphic)
{   //scanf by row, per scanf 1/16 high of word, putout 8*16 namely a word.
    uchar  count,temp;
	temp= row;
    graphic = graphic + 16*coordinate;  //chinese 16*16 include 32 bytes, i is start address of
    for(count=0;count<16;count++) //32byte/2byte=16                //displayed code
	{
    addl = (temp * 30 + column)%256 ;   //30 must calculate by in fact size of screen
    addh = (temp * 30 + column)/256+addh_disramg;   //graphic display ram start 0800h
    w2parCmd(addl,addh,Sword_disramadd); //display grahhic only need write factal code
    w1parCmd(*graphic++,sword_wr_inc);   //to relative address display ram of graphic
	temp++;    // 4K display ram only display 32*4 =128(16*16=256 dots) chinese word
                      }    // namely 1024*8*4=256*128
                        }

//---------------------------
void  dismWord_graph(uchar coordinate,uchar numWord,uchar *graph)
{    //8*16 by row
   ;
  	}*/


//------------****************************************************************
//---dis picture----------------
//-----------------------------
void  dispicture(uint high, uchar width,uchar *graphic)//row 127 ,column 29 for 240*128
{ //scanf by row, per scanf one row, putout width * high graphic.
  uchar i;
  while( high--)
  {
  addl = (row * 30 + column)%256 ;   //30 must calculate by in fact size of screen
  addh = (row * 30 + column)/256+addh_disramg;   //graphic display ram start 0800h
  w2parCmd(addl,addh,Sword_disramadd);
  w0parCmd(Sword_autowr);				/* 自动写 */
  for(i=0;i<width;i++)  //width + column(start) must <= 30
  {//cant while( width--), while only use one time.
	autowdata(*graphic++); 				/* 写数据 */
  }
  w0parCmd(Sword_autover); 			/* 自动写结束 */
    row++;
           }
  }

//----------------------------
void  disanti_picture(uint high, uchar width,uchar *graphic)//row 127 ,column 29 for 240*128
{ //scanf by row, per scanf one row, putout width * high graphic.
  uchar i;
  uchar temp;
  while( high--)
  {
  addl = (row * 30 + column)%256 ;   //30 must calculate by in fact size of screen
  addh = (row * 30 + column)/256+addh_disramg;   //graphic display ram start 0800h
  w2parCmd(addl,addh,Sword_disramadd);
  w0parCmd(Sword_autowr);				/* 自动写 */
  for(i=0;i<width;i++)  //width + column(start) must <= 30
  {//cant while( width--), while only use one time.
    temp= ~(*graphic);
	autowdata(temp); 				/* 写数据 */
    graphic++;
  }
  w0parCmd(Sword_autover); 			/* 自动写结束 */
    row++;
           }
  }

//----------------------------
void  clrpicture(uint high, uchar width)//row 127 ,column 29 for 240*128
{ //scanf by row, per scanf one row, putout width * high graphic.
  uchar i;
  while( high--)     // high type cant overflow!
  {
  addl = (row * 30 + column)%256 ;   //30 must calculate by in fact size of screen
  addh = (row * 30 + column)/256+addh_disramg;   //graphic display ram start 0800h
  w2parCmd(addl,addh,Sword_disramadd);
  w0parCmd(Sword_autowr);				/* 自动写 */
  for(i=0;i<width;i++)   //cant while( width--), while only use one time.
  {//width + column(start) must <= 30
	autowdata(0x00); 				/* 写数据 */
  }
  w0parCmd(Sword_autover); 			/* 自动写结束 */
    row++;
           }
  }


//------------***********************************************************
//-----------------------------
//bit fgram,bit fgraph ,uchar *pstring,uchar cgram,uchar cgram_len,uchar graph_posi,uchar graph_len,uchar *graphic
//position by row and column
//only continue model shift enable
/*
void  disframe(uchar model_w, ...)    //the numbers of parameter can vary
{
   va_list  arg_ptr;    //define a arg_ptr pointer point to parameter list(va_list)
   va_start(arg_ptr,model_w);  //enable arg_ptr point to parameter list fgrom

  if( model_w  & 0x1 )
  {
   uchar *arg1;
   arg1 = va_arg(arg_ptr,uchar*);
   if(graph_model_fg)  {row /= 8; graph_model_fg =0;}
   discgrom(arg1);        //factul parameter is error
   }

  if( model_w  & 0x2 )
  {
  uchar arg2;
  uchar arg3;
  arg2 = va_arg(arg_ptr,uchar);
  arg3 = va_arg(arg_ptr,uchar);
  if(graph_model_fg)  {row /= 8; graph_model_fg =0;}
  for(;arg2>0;arg2--)  //row or column over lead unthinking error
  {
  discgram(arg3);
  column += 2;                         //error,unless only addresss is right
  arg3  += 4;
  if(column >=30) {column=0; row +=2;} //change == change >= or <= to avoid unthink
         }
		 }

  if( model_w  & 0x4 )
  {
  uchar arg4;
  uchar arg5;
  uchar *arg6;
  arg4 = va_arg(arg_ptr,uchar);
  arg5 = va_arg(arg_ptr,uchar);
  arg6 = va_arg(arg_ptr,uchar *);
  if(!graph_model_fg) {row *= 8;graph_model_fg =1;}     //format graph to graphic
  if(row%2 !=0) row++;   // avoid chinese word aparted
  if(column%2 !=0) column++;   // avoid chinese word aparted
  for(;arg4>0;arg4--)  //row or column over lead unthinking error
  {
  disWord(arg5++,arg6);
  column += 2;
  if(column >=30) {column=0; row +=16;} //change == change >= or <= to avoid unthink
         }   //calculator by the factal size of screen
           }              //format graphic  to graph
 		    } 
          */


⌨️ 快捷键说明

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