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

📄 testled3.c

📁 这是一个基于nec78f8024的led驱动程序
💻 C
字号:
/*
*******************************************************************************
**  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 :	LED3.c
**  Abstract :	This file implements the LED lighting control function.(Channel3)
**
**  Device :	uPD78F8024
**
**  Compiler :	NEC/CC78K0
**
*******************************************************************************
*/
/*
*******************************************************************************
**  Include files
*******************************************************************************
*/
#include "testmacrodriver.h"
#include "testLED.h"

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

/*
**-----------------------------------------------------------------------------
**
**  function name:
**  	LED3_init
**
**  Parameters:
**  	None
**
**  Returns:
**  	None
**
**-----------------------------------------------------------------------------
*/ 
void LED3_init(void)
{
	/* set output to the PWM3 port mode */
	PORT_MODE_PWM3 = OUTPUT;
	/* stops TMH1 count operation */
	TMHE1 = BIT_CLR;
	/* set fPRS/2^6 to the count clock of TMH1 */
	/* TMH1 operating PWM output mode, Active-high, timer output enabled */
	TMHMD1 = TMHMD1_INIT_VALUE;
	/* set the PWM cycle */
	CMP01 = CMP01_INIT_VALUE;
}

/*
**-----------------------------------------------------------------------------
**
**  function name:
**  	LED3_set
**
**  Parameters:
**  	short    duty value to adjust brightness of LED3
**
**  Returns:
**  	void
**
**-----------------------------------------------------------------------------
*/
void LED3_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[2]) {
		/* nothing is done and it comes off processing */
		return;
	}
	/* preserve the set duty */
	g_ucDuty[2] = (unsigned char)shDuty;

	switch (shDuty) {
		case 0: /* when the set duty equal 0 */
			/* TMH1 count operation disabled */
			TMHE1 = BIT_CLR;
			/* output Low-level from PWM3 port */
			PORT_PWM3 = LEVEL_LOW;
			break;

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

⌨️ 快捷键说明

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