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

📄 ledutl.c

📁 一个瑞萨单片机的程序。。。供大家学习用。。。。。。。。。。。。。。。。。。
💻 C
字号:
/*""FILE COMMENT""*************************************************************
*  System Name : for eduction (NO TRANSFERRING)
*  File Name   : LEDUTL.c
*  Contents    : control LED
*  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"					/* define common symbol					*/
#include "target.h"					/* SFR section definition file			 */
#include "ledutl.h"					/* header file for LED control				 */

/*===== define macro =====*/
#define PERIOD 	0x24				/* '.' */
#define SPACE 	0x25				/* ' ' */
#define MINUS 	0x26				/* '-' */

/*===== define function prototype =====*/


/*===== define variable =====*/
static int init_hard;				/* variable for hardware initialization management		 */
									/* 0:not be initialized, 1:initialized			 */

static const unsigned char ptntable[] = {	/* LED display pattern table		*/
 /* '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7' 	*/
	0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xf8,
 /* '8',  '9',  'A',  'b',  'c',  'd',  'E',  'F' 	*/
	0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E,
 /* 'G',  'H',  'I',  'J',  'K',  'L',  'M',  'N' 	*/
 	0x7F, 0x89, 0xCF, 0xF1, 0x7F, 0xC7, 0x7F, 0xAB,
 /* 'O',  'P',  'Q',  'R',  'S',  'T',  'U',  'V' 	*/
 	0xA3, 0x8C, 0x7F, 0xAF, 0x7F, 0x7F, 0xC1, 0x7F,
 /* 'W',  'X',  'Y',  'Z',  '.',  ' ',  '-' 		*/
 	0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xBF
};

static const unsigned char digtable[] = {	/* data table for deciding LED lighting	*/
/* ALL-OFF, LED0 , LED1 , LED2 , LED3  */
 	0xFF  , 0xFD , 0xFB , 0xF7 , 0xEF
};

/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : void LED__initialize(void)
* function        : LED port initialization
* parameter       : none
* return          : none
* function used   : none
* notice          : none
* History         : 
*""FUNC COMMENT END""*********************************************************/
void LED__initialize(void)
{
	init_hard	= TRUE;			/* LED "initialized"					 	*/

	p0			= 0xFF;			/* initialze port P0(unlight pattern)	 	*/
	prc2		= 1;			/* permit writing port P0 direction register	*/
	pd0			= 0x0F;			/* set port P0 to port P3 as output ports			*/
	p1			= 0xFF;			/* initialize port P1(decide light digit)		*/
	pd1			= 0xFF;			/* set port P10 to P17 as output ports			*/
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : int LED__putchar(int led , int c)
* function        : display decided character at decided LED
* parameter       : int  led :number of LED light
*                 : int  c  :character to be displayed
* return          : int OK   ; normal end
*                 :     ERR  ; not be initialized
* function used   : none
* notice          : none
* History         : 
*""FUNC COMMENT END""*********************************************************/
int LED__putchar(int led, int c)
{
	int err = ERR;					/* error code							*/
	int index = 0;					/* index for table serach 			*/
	
	if(init_hard){					/* confirm if initialized 				*/
		/* check the scope for display digit	*/
		if((0 <= led) && (led <= 3)){
			if(c >= 'a'){			/* if the decided character is small character		*/
				c = c - 0x20;		/* change to large character			*/
			}
		
			switch(c){				/* if decided character is					*/
				case  ' ' :			/* space (' ')					*/
					index = SPACE;
					err = OK;
					break;
				case '-' :			/* minus '-'								*/
					index = MINUS;
					err = OK;
					break;
				default :			/* number or alphabet							*/
					c = c - '0';	/* change to ASCII code				 	*/
					if(c < 10){		/* number								*/
						index = c;	
						err = OK;
					}				/* alphabet								*/
					else if((c >= 0x11) && (c <= 0x2A)){
						index = c - 0x07;
						err = OK;
					}
					else{
						index = PERIOD;
					}
					break;
			}
		}
		else{
			index = PERIOD;
			led = 0;
		}

		p1 = ptntable[SPACE];		/* protect bluring							*/
		p0 = digtable[led + 1];		/* output light digit to port P0		*/
		p1 = ptntable[c];			/* output display pattern to port P1			*/
	}

	return err;						/* return result						*/
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : int LED__puthex(int led , int hex)
* function        : display decided number('0'乣'F') at decided LED
* parameter       : int  led :number of light digit
*                 : int  hex :number to display('0'乣'F')
* return          : int OK   ; normal end
*                 :     ERR  ; not be initialized
* function used   : none
* notice          : none
* History         : 
*""FUNC COMMENT END""*********************************************************/
int LED__puthex(int led, int hex)
{
	int err = ERR;					/* error code						*/
	
	if(init_hard){					/* confirm if initialized 				*/
		/* 	check the scope for display digit	*/
		if((0 <= led) && (led <= 3)){
			/* check the scope for display number		*/
			if((0 <= hex) && (hex <= 0xf)){	
				err = OK;
			}
			else{					/* if displaying number is out of scope			*/
				hex = PERIOD;		/* set to display '.'						*/
			}
		}
		else{						/* if displaying digit is out of scope				*/
			hex = PERIOD;			/* display '.' at LED0						*/
			led = 0;
		}
		p1 = ptntable[SPACE];		/* protect bluring							*/
		p0 = digtable[led + 1];		/* output light digit to port P0 		*/
		p1 = ptntable[hex];			/* output display pattern to port P1		*/
	}

	return err ;					/* return result						*/
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : int LED__putdig(int led)
* function        : display at decided LED
* parameter       : int  led :number of light LED
* return          : int OK   : normal end
*                 :     ERR  : not be initialized
* function used   : none
* notice          : none
* History         : 
*""FUNC COMMENT END""*********************************************************/
int LED__putdig(int led)
{
	int err = ERR;						/* error code					*/

	if(init_hard){						/* confirm if initialized			*/
		if((0 <= led) && (led <= 3)){	/* check the scope for display digit	*/
			p0 = digtable[led + 1] ;	/* output light digit to port P0	*/
			err = OK;
		}
	}
	
	return err;							/* return result					*/
}


/*""FUNC COMMENT""*************************************************************
* ID              : ---
* function name   : int LED__putseg(int num)
* function        : display decided number
* parameter       : num  :number to display 
* return          : int OK   ; normal end
*                 :     ERR  ; not be initialized
* function used   : none
* notice          : none
* History         : 
*""FUNC COMMENT END""*********************************************************/
int LED__putseg(int num)
{
	int err = ERR;					/* error code						*/

	if(init_hard){					/* confirm if initialized				*/
		/* check the scope for display digit	*/
		if((0 <= num) && (num <= 0x0f)){
			p1 = ptntable[num];		/* output display pattern to port P1			*/
			err = OK;
		}
	}
	
	return err;						/* return result						*/
}


/* #############################################################################
 * ###	private function
 */


/******************************************************************************
	end	of file
******************************************************************************/

⌨️ 快捷键说明

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