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

📄 lcd.c

📁 实现ucos任务调度时保存LCD上的显示信息
💻 C
📖 第 1 页 / 共 2 页
字号:

	for(i = 0;i < 12;i ++)
	{
		wr_dat(font_dat[i] ^ reverse,cur_ic);
		cur_y ++;
		if(cur_y == 64) 
		{
			cur_ic = LCD_IC2;
			set_pg_addr(cur_x,cur_ic);
			set_y_addr(0,cur_ic);
		}
	}

	cur_y -= (LCD_FONT_WIDTH << 1);
	cur_ic = cur_y >> 6;
	set_pg_addr(cur_x + 1,cur_ic);
	set_y_addr(cur_y & 0xBF,cur_ic);
	
	for(i = 12;i < 24;i ++)
	{
		wr_dat(font_dat[i] ^ reverse,cur_ic);
		cur_y ++;
		if(cur_y == 64) 
		{
			cur_ic = LCD_IC2;
			set_pg_addr(cur_x + 1,cur_ic);
			set_y_addr(0,cur_ic);
		}
	}

	set_pg_addr(cur_x,cur_ic);
}

static void put_hz_rev(unsigned int indx)
{
	reverse = 0xFF;
	put_hz_rev(indx);
	reverse = 0x00;
}

/*
********************************************************************************
*
*						  INTERNAL STATIC FUNCTION
*
********************************************************************************
*/
/*
********************************************************************************
* Function Name : LCD_set_disp 
* Description	: set LCD display status
* Parameter		: stat, bit type, specify whether display DDRAM data on LCD.
*					can be set ON or OFF, other value is not permitted.
*                 cs, bit type, sepecify which chip is to set.
*					can be set LCD_IC1 or LCD_IC2, other value is not permitted.
* Return		: none
********************************************************************************
*/
void set_disp(bit stat,bit cs)
{
	wr_inst(0x3E | stat,cs);	
}

/*
********************************************************************************
* Function Name : LCD_set_sta_line 
* Description	: set LCD display start line
* Parameter		: num_of_line, unsigned char type, range from 0 to 63, specify 
*					which line start to display.
*                 cs, bit type, sepecify which chip is to set.
*					can be set LCD_IC1 or LCD_IC2, other value is not permitted.
* Return		: none
********************************************************************************
*/
static void set_sta_line(unsigned char num_of_line,bit cs)
{
	wr_inst(0xC0 + num_of_line,cs);	
}

/*
********************************************************************************
* Function Name : LCD_set_pg_addr 
* Description	: set LCD page address
* Parameter		: pg_addr, unsigned char type, range from 0 to 7, specify the
*					page address.
*                 cs, bit type, sepecify which chip is to set.
*					can be set LCD_IC1 or LCD_IC2, other value is not permitted.                
* Return		: none
********************************************************************************
*/
static void set_pg_addr(unsigned char pg_addr,bit cs)
{
	wr_inst(0xB8 + pg_addr,cs);	
}

/*
********************************************************************************
* Function Name : set_y_addr 
* Description	: set LCD column address
* Parameter		: y_addr, unsigned char type, range from 0 to 63, specify the
*					Y address.
*                 cs, bit type, sepecify which chip is to set.
*					can be set LCD_IC1 or LCD_IC2, other value is not permitted.                
* Return		: none
********************************************************************************
*/
static void set_y_addr(unsigned char y_addr,bit cs)
{
	wr_inst(0x40 + y_addr,cs);	
}

/*
********************************************************************************
* Function Name : nxt_line
* Description	: set cursor to next line
* Parameter		: none               
* Return		: none
********************************************************************************
*/
static void nxt_line(void)
{
	cur_x += 2;
	if(cur_x == 8) LCD_clr();
	else
	{
		cur_y = LCD_Y_DISP_STA_PIX;
		cur_ic = LCD_IC1;

		set_pg_addr(cur_x,LCD_IC1);
		set_y_addr(cur_y,LCD_IC1);
	}
}

/*
********************************************************************************
* Function Name : clr_eol
* Description	: clear to end of line
* Parameter		: none               
* Return		: none
********************************************************************************
*/
static void clr_eol(void)
{
	unsigned char i;

	if(cur_ic == LCD_IC1)
	{
		for(i = 0;i < (64 - cur_y);i++) wr_dat(0x00,cur_ic);

		set_pg_addr(cur_x + 1,cur_ic);
		set_y_addr(cur_y,cur_ic);

		for(i = 0;i < (64 - cur_y);i++) wr_dat(0x00,cur_ic);

		cur_y = 64;
		cur_ic = LCD_IC2;
	}
	set_pg_addr(cur_x,cur_ic);
	set_y_addr(cur_y & 0xBF,cur_ic);

	for(i = 0;i < (LCD_Y_DISP_STP_PIX - cur_y);i++) wr_dat(0x00,cur_ic);

	set_pg_addr(cur_x + 1,cur_ic);
	set_y_addr(cur_y & 0xBF,cur_ic);	

	for(i = 0;i < (LCD_Y_DISP_STP_PIX - cur_y);i++) wr_dat(0x00,cur_ic);

	cur_y = LCD_Y_DISP_STP_PIX;
}

/*
********************************************************************************
* Function Name : disp_logo
* Description	: display Ambition Tech Comm Ltd.Co logo
* Parameter		: none               
* Return		: none
********************************************************************************
*/
/*static void disp_logo(void)
{
	unsigned char i;

	cur_y = 0;
	set_y_addr(cur_y,cur_ic);

	for(i = 0;i < 32;i += 2)
	{
		wr_dat(logo[i],cur_ic);
		cur_y ++;
	}

	cur_y -= 16;
	set_pg_addr(cur_x + 1,cur_ic);
	set_y_addr(cur_y,cur_ic);

	for(i = 0;i < 32;i += 2)
	{
		wr_dat(logo[i + 1],cur_ic);
		cur_y ++;
	}
		
	set_pg_addr(cur_x,cur_ic);
}*/

/*
********************************************************************************
* Function Name : disp_cur
* Description	: display cursor at last of character
* Parameter		: none               
* Return		: none
********************************************************************************
*/
/*static void disp_cur(void)
{
	unsigned char i;
	set_pg_addr(cur_x + 1,cur_ic);
	for(i = 0;i < LCD_FONT_WIDTH;i ++) wr_dat(0x80,cur_ic);
	set_pg_addr(cur_x,cur_ic);
	set_y_addr(cur_y,cur_ic);
}*/

/*
********************************************************************************
* Function Name : wt_rdy
* Description	: wait specified chip ready
* Parameter		: cs, bit type, sepecify which chip is to write.
*					can be set LCD_IC1 or LCD_IC2, other value is not permitted.                
* Return		: none
********************************************************************************
*/
static void wt_rdy(bit cs)
{
	while(rd_inst(cs) & 0x80);			/* BF is bit7 of status register, 1 busy	*/ 	
}

/*
********************************************************************************
* Function Name : wr_dat 
* Description	: write one byte data to specified chip of LCD
* Parameter		: dat, unsigned char type, data will be written.
*                 cs, bit type, sepecify which chip is to write.
*					can be set LCD_IC1 or LCD_IC2, other value is not permitted.                
* Return		: none
********************************************************************************
*/
static void wr_dat(unsigned char dat,bit cs)
{
	unsigned char i;
	
	LCD_E  = 0;							/* E period time 1000ns(min)				*/
	LCD_RW = 0;							/* set to write operation					*/
	LCD_DI = 1;							/* write data								*/
	if(cs == LCD_IC1) LCD_CS1 = 1;      /* select chip to operate					*/
	else 			  LCD_CS2 = 1;
	for(i = 0;i < 25;i++);				/* address setup time 140ns(min)			*/
										/* E low level period 450ns(min)			*/
	LCD_E = 1;
	LCD_DAT = dat;
	for(i = 0;i < 25;i++);				/* data setup time 200ns(min)				*/
										/* E high level period 450ns(min)			*/									
	LCD_E = 0;							/* E fall edge latch the data into DR		*/
		 								/* address hold time 10ns(min)				*/
										/* data hold time 20ns(min)					*/
	if(cs == LCD_IC1) LCD_CS1 = 0;		/* deselect chip							*/
	else 			  LCD_CS2 = 0;

	for(i = 0;i < 15;i++);
}

/*
********************************************************************************
* Function Name : wr_inst 
* Description	: write one byte instruction to specified chip of LCD
* Parameter		: inst, unsigned char type, instruction will be written.
*                 cs, bit type, sepecify which chip is to write.
*					can be set LCD_IC1 or LCD_IC2, other value is not permitted.                
* Return		: none
********************************************************************************
*/
static void wr_inst(unsigned char inst,bit cs)
{
	unsigned char i;
	
	LCD_E  = 0;							/* E period time 1000ns(min)				*/
	LCD_RW = 0;							/* set to write operation					*/
	LCD_DI = 0;							/* write instruction						*/
	if(cs == LCD_IC1) LCD_CS1 = 1;		/* select chip to operate					*/
	else 			  LCD_CS2 = 1;
	for(i = 0;i < 25;i++);				/* address setup time 140ns(min)			*/
										/* E low level period 450ns(min)			*/
	LCD_E = 1;
	LCD_DAT = inst;
	for(i = 0;i < 25;i++);				/* data setup time 200ns(min)				*/
										/* E high level period 450ns(min)			*/									
	LCD_E = 0;							/* E fall edge latch the instruction into IR*/
										/* address hold time 10ns(min)				*/
										/* data hold time 20ns(min)					*/
	if(cs == LCD_IC1) LCD_CS1 = 0;		/* deselect chip							*/
	else 			  LCD_CS2 = 0;

	for(i = 0;i < 15;i++);
}

/*
********************************************************************************
* Function Name : rd_inst 
* Description	: read one byte instruction from specified chip of LCD
* Parameter		: cs, bit type, sepecify which chip is to write.
*					can be set LCD_IC1 or LCD_IC2, other value is not permitted.                
* Return		: unsigned char type, status register value will be returned.
********************************************************************************
*/
static unsigned char rd_inst(bit cs)
{
	unsigned char i,inst;
	
	P4MDOUT = 0x00;						/* set LCD data port open-drain output		*/
	LCD_DAT = 0xFF;						/* set LCD data port input					*/

	LCD_E  = 0;							/* E period time 1000ns(min)				*/	
	LCD_RW = 1;							/* set to read operation					*/
	LCD_DI = 0;							/* read instruction							*/
	if(cs == LCD_IC1) LCD_CS1 = 1;		/* select chip to operate					*/
	else 			  LCD_CS2 = 1;
	for(i = 0;i < 25;i++);				/* address setup time 140ns(min)			*/
										/* E low level period 450ns(min)			*/
	LCD_E = 1;
	for(i = 0;i < 40;i++);				/* data delay time 320ns(max)				*/
										/* E high level period 450ns(min)			*/
	inst = LCD_DAT;						/* read data when E is high					*/
	LCD_E = 0;							/* address hold time 10ns(min)				*/
										/* data hold time 20ns(min)					*/
	if(cs == LCD_IC1) LCD_CS1 = 0;		/* deselect chip							*/
	else 			  LCD_CS2 = 0;

	P4MDOUT = 0xFF;						/* set LCD data port push-pull output		*/
	
	for(i = 0;i < 15;i++);
		
	return inst;
}

⌨️ 快捷键说明

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