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

📄 testled1.bak

📁 这是一个基于nec78f8024的led驱动程序
💻 BAK
字号:
/*
*******************************************************************************
**  COPYRIGHT (C) NEC Electronics Corporation 2008
**  NEC ELECTRONICS CONFIDENTIAL AND PROPRIETARY
**  All rights reserved by NEC Electronics Corporation.
**  Use of copyright notice does not evidence publication.
**
**  Filename :	LED1.c
**  Abstract :	This file implements the LED lighting control function.(Channel1)
**
**  Device :	uPD78F8024
**
**  Compiler :	NEC/CC78K0
**
*******************************************************************************
*/
/*
*******************************************************************************
**  Include files
*******************************************************************************
*/
#include "macrodriver.h"
#include "LED.h"

/*
*******************************************************************************
**  External Variable Uniting
*******************************************************************************
*/
extern unsigned char g_ucDuty[4];	/* the present duty of each LED is preserved */

/*
**-----------------------------------------------------------------------------
**
**  function name:
**  	LED1_init
**
**  Parameters:
**  	None
**
**  Returns:
**  	None
**
**-----------------------------------------------------------------------------
*/ 
void LED1_init(void) 
{
	/* set output to the PWM1 port mode */
	PORT_MODE_PWM1 = OUTPUT;
	/* TM51 count operation disabled */
	TCE51 = BIT_CLR;
	/* set fPRS/2^6 to the count clock of TM51 */
	TCL51 = TCL51_INIT_VALUE;
	/* TM51 operating PWM (free-running) mode, Active-high, timer output enabled */
	TMC51 = TMC51_INIT_VALUE;
}

/*
**-----------------------------------------------------------------------------
**
**  function name:
**  	LED1_set
**
**  Parameters:
**  	short    duty value to adjust brightness of LED1
**
**  Returns:
**  	void
**
**-----------------------------------------------------------------------------
*/
void LED1_set(short shDuty) 
{
	/* when the set duty is outside the tolerance */
	if (( shDuty <= -1 )||(shDuty >= 256)) {
		/* nothing is done and it comes off processing */
		return;
	}
	/* when the set duty equal present duty */
	if (shDuty == g_ucDuty[0]) {
		/* nothing is done and it comes off processing */
		return;
	}
	/* preserve the set duty */
	g_ucDuty[0] = (unsigned char)shDuty;

	switch (shDuty) {
		case 0: /* when the set duty equal 0 */
			/* TM51 count operation disabled */
			TCE51 = BIT_CLR;
			/* output Low-level from PWM1 port */
			PORT_PWM1 = LEVEL_LOW;
			break;

		default:/* when the set duty not equal 0 */
			/* set the set duty to CR51 */
			CR51 = g_ucDuty[0];
			/* when TM51 count operation is disabled */
			if (TCE51 == BIT_CLR) {
				/* TM51 count operation enabled */
				TCE51 = BIT_SET;
			}
			break;
	}
}

⌨️ 快捷键说明

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