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

📄 lcd.c

📁 实现ucos任务调度时保存LCD上的显示信息
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
********************************************************************************
*				 		C8051F340 LCD modular
*
*		        	  Ambition Comm Tech Ltd.Cop
*						   Jason.D.Proakis
*
* File Name		   : LCD.c
* File Description : C file of LCD modular TBM12F64-36A.
*			  	     
* Create Date	   : 04-21-2008
* Version	       : V1.00
* Modified History :
*					None
*
* All rights reserved.
********************************************************************************
*/

/*
* rd_inst(), LCD_get_stat(), set_disp(), set_sta_line() 
* not even test
*/

/*
********************************************************************************
*							HEADER FILE INCLUDE
********************************************************************************
*/
#include <C8051F340.h>
#include "LCD.h"
#include "dataflash.h"

/*
********************************************************************************
*						INTERNAL FUNCTION DECLARATION
********************************************************************************
*/

static void put_asc(unsigned char ch);
static void put_asc_rev(unsigned char ch);
static void put_hz(unsigned int indx);
static void put_hz_rev(unsigned int indx);

/* set display start line, virtually set Z counter value */ 
static void set_sta_line(unsigned char num_of_line,bit cs);

/* set page address, virtually set X counter value */
static void set_pg_addr(unsigned char pg_addr,bit cs);

/* set Y address, virtually set Y counter value, column number */
static void set_y_addr(unsigned char y_addr,bit cs);

/* srt cursor to next line */
static void nxt_line(void);

/* clear end of line */
static void clr_eol(void);

/* display Ambition Logo */
static void disp_logo(void);

/* display cursor at last of character */
static void disp_cur(void);

/* set sepecified part of LCD display ON or OFF */
static void set_disp(bit stat,bit cs);

/* wait specified chip ready */
static void wt_rdy(bit cs);

/* write one byte data to specified chip of LCD */
static void wr_dat(unsigned char dat,bit cs);

/* write one byte instruction to specified chip of LCD */
static void wr_inst(unsigned char inst,bit cs);

/* read one byte instruction from specified chip of LCD */
static unsigned char rd_inst(bit cs);

/*
********************************************************************************
*						 		STATIC VARIABLES 	
********************************************************************************
*/
static unsigned char code logo[32] = {
   	0xC0,0x03,0xF0,0x05,0xF8,0x15,0x3C,0x2A,0xDE,0x6A,0x2E,0x74,0xAF,0xFB,0x5F,0xFC,
    0x9F,0xFF,0xBF,0xFF,0x3E,0x7F,0x9E,0x7E,0x9C,0x3E,0x18,0x1F,0x10,0x0F,0xC0,0x03,
};

static unsigned char reverse = 0x00;
static unsigned char cur_x;
static unsigned char cur_y;
static bit cur_ic;

/*
********************************************************************************
*						EXTERNAL INTERFACE FUNCTION 
********************************************************************************
*/
/*
********************************************************************************
* Function Name : LCD_init 
* Description	: initial LCD port, wait until reset done, set display ON
* Parameter		: none
* Return		: none
********************************************************************************
*/
void LCD_init(void)
{
	P1MDOUT |= 0x30;					/* set CS1, CS2 push-pull output	  		*/
	P3MDOUT |= 0xF0;					/* set D/I, R/W, E, BEN, push-pull output 	*/
	P4MDOUT  = 0xFF; 					/* set data port push-pull output			*/
	
	LCD_E = 0;
	LCD_CS1 = 0;
	LCD_CS2 = 0;
	LCD_DI = 1;
	LCD_RW = 0;
	LCD_BEN = 1;	
	
	while(rd_inst(LCD_IC1) & 0x10);		/* wait IC1 until reset done				*/
	while(rd_inst(LCD_IC2) & 0x10);		/* wait IC2 until reset done				*/	
	
	LCD_clr();

	set_disp(LCD_DISP_ON,LCD_IC1);		/* set IC1 display ON						*/
	set_disp(LCD_DISP_ON,LCD_IC2);		/* set IC2 display ON						*/
	
	set_sta_line(0,LCD_IC1);			/* set IC1 start line 0						*/
	set_sta_line(0,LCD_IC2);			/* set IC2 start line 0						*/
	
	LCD_cur_home();						/* set position home						*/
	//disp_logo();
}

/*
********************************************************************************
* Function Name : LCD_get_stat 
* Description	: get LCD current status
* Parameter		: cs, bit type, sepecify which chip status is to get.
*					can be set LCD_IC1 or LCD_IC2, other value is not permitted.
* Return		: value of status register, unsigned char type
*				  bit7	bit6  bit5	bit4  bit3	bit2  bit1	bit0	 
*				  BUSY	 0   ON/OFF  RET   0     0     0     0
********************************************************************************
*/
unsigned char LCD_get_stat(bit cs)
{
	return (rd_inst(cs));
}

/*
********************************************************************************
* Function Name : LCD_clr 
* Description	: clear LCD screen and set cursor home
* Parameter		: none
* Return		: none
********************************************************************************
*/
void LCD_clr(void)
{
	unsigned char i,j;
	
	for(i = 0;i < 8;i++)				/* set DDRAM all 0							*/
	{
		set_pg_addr(i,LCD_IC1);			/* X counter will not increase auto			*/
		set_y_addr(0,LCD_IC1);
		set_pg_addr(i,LCD_IC2);
		set_y_addr(0,LCD_IC2);

		for(j = 0;j < 64;j++)			/* Y counter increase auto after operation */
		{
			wr_dat(0x00,LCD_IC1);	
			wr_dat(0x00,LCD_IC2);
		}
	}
	LCD_cur_home();
}

/*
********************************************************************************
* Function Name : LCD_cur_home 
* Description	: set cursor position to home
* Parameter		: none
* Return		: none
********************************************************************************
*/
void LCD_cur_home(void)
{
	cur_x = 0;
	cur_y = LCD_Y_DISP_STA_PIX;	
	cur_ic = LCD_IC1;

	set_pg_addr(0,cur_ic);
	set_y_addr(cur_y,cur_ic);
}

/*
********************************************************************************
* Function Name : LCD_set_cur_pos
* Description	: set cursor position
* Parameter		: line, unsigned char type, range from 0 to 3.
*				  ch_addr, unsigned char type, range from 0 to 
*					(LCD_Y_DISP_STP_PIX - LCD_Y_DISP_STA_PIX)/LCD_FONT_WIDTH - 1.
* Return		: none
********************************************************************************
*/
void LCD_set_cur_pos(unsigned char line,unsigned char ch_addr)
{
	cur_x = line << 1;
	cur_y = ch_addr * LCD_FONT_WIDTH + LCD_Y_DISP_STA_PIX;
	cur_ic = cur_y >> 6;

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

void LCD_putc(unsigned int buf)
{
	if(buf > 0x80) put_hz(buf);
	else (put_asc((unsigned char)buf));
}

void LCD_putc_rev(unsigned int buf)
{
	if(buf > 0x80) put_hz_rev(buf);
	else (put_asc_rev((unsigned char)buf));
}

void LCD_puts(unsigned char * buf)
{
	while(*buf)
	{
		if(*buf > 0x80)
		{
			put_hz(*(unsigned int *)buf);
			buf += 2;
		}
		else
		{
			put_asc(*buf);
			buf ++;
		}
	}
}
void LCD_puts_rev(unsigned char * buf)
{
	reverse = 0xFF;
	while(*buf)
	{
		if(*buf > 0x80)
		{
			put_hz(*(unsigned int *)buf);
			buf += 2;
		}
		else
		{
			put_asc(*buf);
			buf ++;
		}
	}

	reverse = 0x00;
}

void LCD_putn(unsigned char * buf,unsigned char n)
{
	 while((*buf != '\0') && (n > 0))
	 {
	 	if(*buf > 0x80)
		{
			put_hz(*(unsigned int *)buf);
			buf += 2;
		}
		else
		{
			put_asc(*buf);
			buf ++;
		}
		n--;
	 }
}



static void put_asc(unsigned char ch)			   
{
	unsigned char i;
	unsigned char font_dat[LCD_FONT_WIDTH << 1];

	DF_rd(LCD_FONT_ASC_BASE + (ch - 0x20) * (LCD_FONT_WIDTH << 1),font_dat,LCD_FONT_WIDTH << 1);

	if(ch == '\n') nxt_line();
	else 
	{
		if(cur_y == 64) 
		{
			cur_ic = LCD_IC2;
			set_pg_addr(cur_x,cur_ic);
			set_y_addr(cur_y & 0xBF,cur_ic);
		}
		else if(cur_y == LCD_Y_DISP_STP_PIX)
			nxt_line();

		for(i = 0;i < LCD_FONT_WIDTH;i ++)
		{
			wr_dat(font_dat[i] ^ reverse,cur_ic);
			cur_y ++;
		}

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

		for(i = LCD_FONT_WIDTH;i < (LCD_FONT_WIDTH << 1);i ++)
		{
			wr_dat(font_dat[i] ^ reverse,cur_ic);
			cur_y ++;
		}
		
		set_pg_addr(cur_x,cur_ic);
	}
}

static void put_asc_rev(unsigned char ch)
{
	 reverse = 0xFF;
	 put_asc(ch);
	 reverse = 0x00;
}

static void put_hz(unsigned int indx)
{
	unsigned char i;
	unsigned char font_dat[LCD_FONT_WIDTH << 2];
	unsigned long addr;

	indx -= 0xB0A1;
	addr = LCD_FONT_HZ_BASE + (unsigned long)((indx >> 8)*94 + (unsigned char)indx)* (LCD_FONT_WIDTH << 2);
	
	DF_rd(addr,font_dat,sizeof(font_dat));
	if(cur_y > (LCD_Y_DISP_STP_PIX - (LCD_FONT_WIDTH << 1))) nxt_line();

⌨️ 快捷键说明

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