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

📄 lcdutl.c

📁 一个瑞萨单片机的程序。。。供大家学习用。。。。。。。。。。。。。。。。。。
💻 C
📖 第 1 页 / 共 2 页
字号:
/*""FILE COMMENT""*************************************************************
*  System Name : for eduction (NO TRANSFERRING)
*  File	Name   : lcdutl.c
*  Contents	   : control LCD
*  Model	   : for OAKS8-LCD Board 
*  CPU		   : R8C/Tiny series
*  Compiler	   : NC30WA(V.5.30 Release 1)
*  OS		   : not be used 
*  Programer   : RENESAS Semiconductor Training Center
*  Note		   : for OAKS8-R5F21114FP(R8C/11 group,20MHz)
*******************************************************************************
* COPYRIGHT(C) 2004	RENESAS	TECHNOLOGY CORPORATION
* AND RENESAS SOLUTIONS	CORPORATION	ALL	RIGHTS RESERVED
*******************************************************************************
* History	   : ---
*""FILE	COMMENT	END""*********************************************************/

/*=====	include file =====*/
#include "defs.h"					/* common symbol definition					*/
#include "target.h"					/* SFR section definition file			*/
#include "lcd1.h"					/* definitin file of low level program for LCD	*/
#include "lcdutl.h"					/* header file for LCD				*/


/*=====	macro definition =====*/


/*--- instruction definition ---*/
#define	CMD_CLEAR				0x01	/* 00000001							 */
										/* clear all display + move home		 */
#define	CMD_HOME				0x02	/* 00000010							 */
										/* move home + cancel shift			 */
#define	CMD_ENTORY_DEC			0x04	/* 00000100							 */
										/* direction of cursor (decrement)	 */
#define	CMD_ENTORY_DEC_SHIFT	0x05	/* 00000101							 */
										/* direction of cursor				 */
										/* (decrement) + display shift		 */
#define	CMD_ENTORY_INC			0x06	/* 00000110							 */
										/* direction of cursor				 */
										/* (increment)					 */
#define	CMD_ENTORY_INC_SHIFT	0x07	/* 00000111							 */
										/* direction of cursor				 */
										/* (increment) + display shift	 */
#define	CMD_DISP_DS				0x08	/* 00001000							 */
										/* not display(all display OFF + cursor OFF +	 */
										/* blink OFF)					 */
#define	CMD_DISP_EN				0x0c	/* 00001100							 */
										/* display(all display ON + cursor OFF +	 */
										/* blink OFF)					 */
#define	CMD_DISP_EN_CUR			0x0e	/* 00001110							 */
										/* display(all display ON + cursor ON +		 */
										/* blink OFF)					 */
#define	CMD_DISP_EN_CUR_BLINK	0x0f	/* 00001111							 */
										/* display(all disply ON + cursor ON +		 */
										/* blink ON)						 */
#define	CMD_MOVE_CUR_LEFT		0x10	/* 00010000							 */
										/* left shift cursor					 */
#define	CMD_MOVE_CUR_RIGHT		0x14	/* 00010100							 */
										/* right shift cursor					 */
#define	CMD_MOVE_SRC_LEFT		0x18	/* 00011000							 */
										/* left shift source 				 */
#define	CMD_MOVE_SRC_RIGHT		0x1c	/* 00011100							 */
										/* right shift source				 */
#define	CMD_FUNC_D4_N2_F7		0x28	/* 00101000							 */
										/* interface data length 4 bits	 */
										/* 2 lines, 5*7 dots display			 */

/*=====	define function prototype =====*/
static int read_creg(void);				/* read command from LCD		 */
static void	write_creg(int command);	/* write command to LCD			 */
static int read_dreg(void);				/* read data from LCD			 */
static void	write_dreg(int	data);		/* write data to LCD			 */
static void	move_cursol(void);			/* move cursor position			 */
static void	init_timerC(void);			/* initialize timer C				 */
static void	set_busy(unsigned int time);/* set waiting time					 */

void INT_cmp0(void)	;					/* compare 0 (timer C) interrupt	 */

/*=====	define variable =====*/
static int	cursol_x;					/* cursor position (horizontal)		 */
static int cursol_y;					/* cursor positon (vertical)			 */
static int F_busy;						/* busy flag					 */
										/* 0:command process end丄1:command processing	 */
static int init_hard;					/* variable for hardware initialization management	 */
										/* 0:not be initialized, 1:initialized	 */

/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : void LCD__initialize(void)
* function        : initialize LCD
* parameter       : none
* return          : none
* function used   : _lcd1__initial() ; initialize LCD control port
*                 : _lcd1__wait()    ; software wait for t*100us order
*                 : write_creg()     ; write command to LCD 
*                 : _lcd1__wr_nibble_creg() ; write command register 
* notice          : 側偟
* History	      : ---
*""FUNC	COMMENT	END""*********************************************************/
void LCD__initialize(void)
{
	init_hard =	TRUE;					/* LCD module "initialized"		*/

	_lcd1__initial();					/* initialize LCD control port		*/
	init_timerC();						/* initialize timer C 			*/

	/*--- initialization after LCD reset ---*/
	_lcd1__wait(300);				/* wait 15ms(50us*300) after VDD stable*/
	_lcd1__wr_nibble_creg(0x03);	/* functin set 8 bits (0x03)		*/

	_lcd1__wait(82);					/* wait 4.1ms(50us*82)				*/
	_lcd1__wr_nibble_creg(0x03);		/* functin set 8 bits (0x03)	*/

	_lcd1__wait(2);						/* wait 0.1ms(50us*2)				*/
	_lcd1__wr_nibble_creg(0x03);		/* functin set 8 bits (0x03)	*/

	_lcd1__wait(2);						/* wait 0.1(50us*2)ms				*/
	_lcd1__wr_nibble_creg(0x02);		/* function set 4 bits (0x02)	*/
	_lcd1__wait(2);						/* wait 0.1(50us*2)ms				*/
	write_creg(CMD_FUNC_D4_N2_F7);		/* interface data length 4 bits	*/
										/* 2 lines, 5*7dots				*/

	_lcd1__wait(2);						/* wait 0.1ms(50us*2)				*/

	write_creg(CMD_DISP_DS);			/* display OFF							*/
	_lcd1__wait(1);						/* wait 50us						*/
	
	write_creg(CMD_CLEAR);				/* > clear display						*/
	_lcd1__wait(40);					/* wait 2ms(50us*40)				*/

	write_creg(CMD_ENTORY_INC);			/* entry mode, increment	*/
	_lcd1__wait(1);						/* wait 50us						*/
 
	write_creg(CMD_DISP_EN);			/* display ON, cursor OFF			*/
										/* blink OFF					*/
	_lcd1__wait(1);						/* wait 50us						*/

	write_creg(0x80);					/* set display address				*/
	_lcd1__wait(1);						/* wait 50us						*/
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : int  LCD__clear(void)
* function        : clear all display, move cursor home
* parameter       : none
* return          : int OK   ; normal end
*                 :     ERR  ; not be initialized 
* functin used    : set_busy();
*                 : write_creg();
* notice          : 側偟
* History	      : 
*""FUNC	COMMENT	END""*********************************************************/
int	LCD__clear(void)
{
	if(init_hard){						/* if initialized				 */
		while(F_busy);					/* wait LCD process						 */
		write_creg(CMD_CLEAR);			/* clear display					 */
		set_busy(32);					/* set 1.6ms(50us*32) busy flag */
		return OK;						/* normal end							 */
	}
										/* if not be initialized				 */
	return ERR;							/* return error					 */
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : int  LCDUTL__set_cursol(int x, int y)
* function        : set cursor position(position for inner display buffer)
* parameter       : int x;   X axis(left 0 - right 0xf)
*                 : int y;   Y axis(up 0 - down 1)
* return          : int OK   ; normal end
*                 :     ERR  ; not be initialized 
* function used   : set_busy();
*                 : write_creg();
* notice          : none
* History	      : 
*""FUNC	COMMENT	END""*********************************************************/
int	LCD__setcursol(int x, int y)
{
	cursol_x = x;						/* set cursor position					 */
	cursol_y = y;

	if(init_hard){						/* if initialized				 */
		while(F_busy);					/* 	wait LCD process					 */
		write_creg(0x80	| y*0x40 + x);	/*	address of the second line 0x40-0x4f	 */
		set_busy(1);					/*	set 50us busy flag			 */
		return	OK;						/* 	normal end						 */
	}
										/* if not be initialized			 */
	return	ERR;						/* return error				 */
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : int  LCD__putchar(int c)
* function        : display character on LCD
* parameter       : int c;    character to be displayed
* return          : int OK   ; normal end
*                 :     ERR  ; not be initialized
* functin used    : set_busy();
*                 : write_creg();
* notice          : none
* History	      : 
*""FUNC	COMMENT	END""*********************************************************/
int	LCD__putchar(int c)
{
	if(init_hard){						/* if initialized			 */
		if(c != '\n'){					/* not line feed code			 */
			while(F_busy);				/* 		wait LCD process			 */
			write_dreg(c);				/* 		write Data-Register	 */
			set_busy(1);				/*		set 50us busy flag		 */
			move_cursol();				/* 		move cursor position		 */
		}
		else{							/*	if line feed code*/
			do{
				while( F_busy );		/*			wait LCD process		 */
				write_dreg(' ');		/* 			output ' '			 */
				set_busy(1);			/*			wait 50us				 */
				move_cursol();			/* 			move cursor position	 */
			}while(cursol_x !=	0);	/* 		if cursor comes begin of line	 */
		}
		return OK;						/* 	normal end 				 */
	}
										/* if not be initialized				 */
	return ERR;							/* return error */
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : int  LCD__puts(const unsigned char *s)
* function        : display string on LCD
* parameter       : const unsigned char *s;  pointer to string to be displayed
* return          : int OK   ; normal end
*                 :     ERR  ; if not be initialized
* function usde   : LCD__putchar();
* notice          : none
* History      	  :
*""FUNC	COMMENT	END""*********************************************************/
int	LCD__puts(const unsigned char *s)
{
	if(init_hard){						/* if initialized				 */
		for(; '\0'	!= *s; s++){		/* loop before null code			 */
			LCD__putchar(*s);			/* display character on LCD			 */
		}
		return OK;						/* 	normal end						 */
	}
										/* if not be initialized				 */
	return ERR;							/* return error					 */
}

⌨️ 快捷键说明

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