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

📄 lcd.c

📁 HY-12896A-T01 LCD的驱动
💻 C
📖 第 1 页 / 共 2 页
字号:

//typedef unsigned short unsigned int ;
//typedef unsigned int unsigned int ;
//typedef unsigned char  unsigned char ;


#include "LCD.h"
#include "Board.h"
#include "lcd_mask_chinese.h"
#include "clock.h"

extern   int  get_charactor_dots_size(void);  //获取当前汉字字库的大小
//extern   TYPE_CCT_TM  clock_time;             //用来存放当前系统时间
extern   TYPE_CH_DOTS charactor_dots[];       //汉字库
extern   char  ASC_MSK[96*12];                //字符库

extern unsigned char GB_16[4*32];//ls 临时的字库 为调试用的

unsigned char  gCurRow,gCurCol;
unsigned char  gPage_addr,gPhysics_col;


/***********************************************************/
//open the back light
/**********************************************************/
 lcd_EnLight( )
 {
     AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB9); //enable backlignt
     return 1;
 }



 /*********************************************************/
 //close the back light
 /*********************************************************/
 lcd_DisLight( )
 {
   AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB9);	//Disabke backlignt
   return 1;
 }


/*************************************************************/
//返回光标所在的行号
/**************************************************************/
unsigned int fnGetRow(void)
{
	return gCurRow;
}


/*************************************************************/
//返回光标所在的列号
/**************************************************************/
unsigned int fnGetCol(void)
{
	return gCurCol;
}




/*************************************************************/
//廷时
/**************************************************************/
void lcd_delay(unsigned int nnn)
{
	unsigned int mmm;
	while(nnn-->0)
		for(mmm=0;mmm<1000;mmm++)
		{ }
}



/*************************************************************/
//写命令
/**************************************************************/
void wcomd(unsigned char cdat)
{
    unsigned int ic;
    int Bit ;
	
    AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); //  SCK=0;
    AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB0); //  RS=0;	
    AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB3); //  CS=0;	

	for(ic = 0; ic < 8; ic++)
	{
		Bit = cdat >> (7 - ic) & 0x01;
		
		if ( Bit == 1 )	
		{
                        AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1); // SDA=1 ;
		}
		else
		{
                        AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1); // SDA=0;	
		}
		
		AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); //    SCK=1;
		AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); //  SCK=0;	
	}
	
        AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB3); //  CS=1;
}



/*************************************************************/
//写数据
/**************************************************************/
void wdata(unsigned char ddat)
{
	unsigned int id;
	int Bit ;
	
	if( gPhysics_col < 127)
	{
                AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1);     //  SDA = 0;
		AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4);     //  SCK = 0;
                AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB0);       //  RS = 1;
                AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB3);     //  CS = 0;
		
		for(id = 0; id < 8; id++)
		{
			Bit = ddat >> (7 - id) & 0x01;
			
			if ( Bit == 1 )	
			{
                                AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1); // SDA=1 ;
			}
			else
			{
                                AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB1); // SDA=0;
			}
			
			AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); //    SCK=1;
			AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB4); //	SCK=0;	
		}
		
                AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB3); //  CS=1;
		//gPhysics_col++;
	}
}


/************************************************************************/
//设置热物理页码号和热处理列号
/************************************************************************/
void set_pos(unsigned char uPage, unsigned char uPhysics_col)
{
		unsigned char temp;

		if( uPage < 12  && uPhysics_col < 128)
		{
			wcomd(uPage + 0xb0);//set page address
			
			temp = uPhysics_col & 0x7F;
			temp = temp >> 4;
			temp = temp | 0x10;
			wcomd(temp);        //set col MSB
			
			temp = uPhysics_col & 0x0F;
			wcomd(temp);       //set col LSB

			gPage_addr = uPage;
			gPhysics_col = uPhysics_col;
		}
}


/*************************************************************/
//设置光标
/**************************************************************/
void set_cursor(unsigned int uUser_row, unsigned int uUser_col)
{
	if (uUser_row < 6   && uUser_col < 16)
	{
                set_pos(uUser_row * 2, uUser_col * 8);

		gCurRow = uUser_row;
		gCurCol = uUser_col;
	}

}



/*************************************************************/
//全部为亮或才全部为暗
//当d1 为0xff时显示器上所有的点就全部为亮
//当d1 为0x00时显示器上所有的点就全部为暗
/**************************************************************/
void disp_all(unsigned int d1)
{
	unsigned int i,j;

	for(j=0;j<12;j++)
	{
		wcomd(0xb0+j);
		wcomd(0x10);
		wcomd(0x00);

		for(i=0;i<64;i++)
		{
			wdata(d1);//每一个点得写两次才行
			wdata(d1);

			wdata(d1);
			wdata(d1);
		}
	}
}



/********************************************************************/
//清屏
//
/********************************************************************/
int  lcd_ClearScreen(void)
{
     disp_all(0x00);     //0x00 让每一个点阵都为暗
     set_cursor(0,0);	//把光标设置在(0,0)这个位置
     return 0;
}

/*************************************************************/
//夜晶初始化
/**************************************************************/
int lcd_init()
{
	//配置输出
	AT91F_PIO_CfgOutput(AT91C_BASE_PIOB,AT91C_PIO_PB0|AT91C_PIO_PB1|AT91C_PIO_PB2 |AT91C_PIO_PB3 | AT91C_PIO_PB4 | AT91C_PIO_PB9);
	lcd_DisLight( );

        //复位重启键,廷时一会,然后重启
        AT91F_PIO_ClearOutput(AT91C_BASE_PIOB,AT91C_PIO_PB2);	//  RST=0;
        lcd_delay(3);
        AT91F_PIO_SetOutput(AT91C_BASE_PIOB,AT91C_PIO_PB2);	//  RST=1;

	//display duty select
	wcomd(0x48);
	wcomd(0x60);  //1/96duty
	
        /*************************************************/
	//ADC select
	//SEG bi-directional selection
	//0xa0:normal direction
	//0xa1:reverse direction
        /***********************************************/
	// wcomd(0xa1); //s0 - s127 //closed by ChengDong Lu at 03/09/2006
	wcomd(0xa0);//added by ChengDong Lu at 03/09/2006
	
	
        /************************************************/
	//SHL select
	//COM bi-directional selection
	//0xc0:normal direction
	//0xc8:reverse direction
        /***********************************************/
	wcomd(0xc8);  //c0 - c127
	
	
	//com0 register select
	wcomd(0x44);
	wcomd(0x10);  //start from com0

	//////// set lcd operating voltage//////////
	//oscillator on start
	wcomd(0xab);
	//dc-dc step_up register select
	wcomd(0x67);  //6 times boosting circuit(64-3times,65-4times,66-5times)
	//regulator register select
	wcomd(0x27);  //(20-27): 1+(rb/ra)=2.3~7.2
	//set electronic volume register(select a from 0 to 63)
	wcomd(0x81);
	wcomd(0x24);  //(0~3f)

	//lcd bias select register
	wcomd(0x56);  //1/11
	wcomd(0x93);

	//lcd grap_scale set up
	wcomd(0x8f);
	wcomd(0xff);

	//power control
	wcomd(0x2c);	//internal voltage converter circuit is on
	lcd_delay(2);
	wcomd(0x2e);	//internal voltage regulator ciruit is on
	lcd_delay(2);
	wcomd(0x2f);	//internal voltage follower circuit is on
	lcd_delay(2);
	
	wcomd(0xaf);	//turns display on

	lcd_ClearScreen();   //清屏

	return 0;
}







/********************************************************************/
//功能:   请除某一行
//        row为当前要清除的行
/********************************************************************/
int  lcd_ClearLine(int row)
{
   unsigned char j , k;

   if(row >=0 && row <6)
   {
       for(j=0;j<2;j++)
       {
	   set_pos(row * 2 + j , 0);

	   for(k = 0; k < 64; k++)
	   {
	      wdata(0x00);
	      wdata(0x00);

	      wdata(0x00);
	      wdata(0x00);
	   }
       }

      set_cursor(row,0); //将光标设置在当前清除的行上.
      return 1;
   }
  return 0;
}


/********************************************************************/
//功能:  在显示器上打印字符
//        str指向字符的显示矩阵
//        reverse 为是否为反显
/********************************************************************/
void print_character(unsigned char * str,int reverse)
{
   unsigned char j,k;

   if(gCurCol >= 16)
   {
     gCurCol = 0;
     gCurRow++;
   }

   if(gCurRow >= 6)
   {
     gCurRow = 0;
   }

  set_cursor(gCurRow,gCurCol); //设置光标

   for(j=0;j<2;j++)
   {
        set_pos(gCurRow * 2 + j , gCurCol * 8);

        if( reverse == 0)//正显
	{
           for(k = 0; k < 8; k++)	
           {
	      wdata(str[j*8 +k]);
	      wdata(str[j*8 +k]);
	   }
	}
	else if (reverse == 1)//反显
	{
              for(k = 0; k < 8; k++)
	      {
		 wdata(~str[j*8 +k]);
		 wdata(~str[j*8 +k]);

⌨️ 快捷键说明

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