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

📄 testled2.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 :	LED2.c
**  Abstract :	This file implements the LED lighting control function.(Channel2)
**
**  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:
**  	LED2_init
**
**  Parameters:
**  	None
**
**  Returns:
**  	None
**
**-----------------------------------------------------------------------------
*/ 
void LED2_init(void)
{
	/* set output to the PWM2 port mode */
	PORT_MODE_PWM2 = OUTPUT;
	/* stops TMH0 count operation */
	TMHE0 = BIT_CLR;
	/* set fPRS/2^6 to the count clock of TMH0 */
	/* TMH0 operating PWM output mode, Active-high, timer output enabled */
	TMHMD0 = TMHMD0_INIT_VALUE;
	/* set the PWM cycle */
	CMP00 = CMP00_INIT_VALUE;
}

/*
**-----------------------------------------------------------------------------
**
**  function name:
**  	LED2_set
**
**  Parameters:
**  	short    duty value to adjust brightness of LED2
**
**  Returns:
**  	void
**
**-----------------------------------------------------------------------------
*/
void LED2_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[1]) {
		/* nothing is done and it comes off processing */
		return;
	}
	/* preserve the set duty */
	g_ucDuty[1] = (unsigned char)shDuty;
	
	switch (shDuty) {
		case 0: /* when the set duty equal 0 */
			/* TMH0 count operation disabled */
			TMHE0 = BIT_CLR;
			/* output Low-level from PWM2 port */
			PORT_PWM2 = LEVEL_LOW;
			break;

		default:/* when the set duty not equal 0 */
			/* set the set duty to CMP10 */
			CMP10 = g_ucDuty[1] - 1;
			/* when TMH0 count operation is disabled */
			if (TMHE0 == BIT_CLR) {
				/* TMH0 count operation enabled */
				TMHE0 = BIT_SET;
			}
			break;
	}
}

⌨️ 快捷键说明

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