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

📄 pbled_test.c

📁 基于visual dsp++开发环境
💻 C
字号:
/*****************************************************************************
**																			**
**	 Name: 	PB_LED_test.c															**
**																			**
******************************************************************************

(C) Copyright 2006 - Analog Devices, Inc.  All rights reserved.

Project Name:	BF538F POST ATE

Date Modified:	01 Sept 2006

Software:		VisualDSP++ 4.5

Hardware:		ADSP-BF538F EZ-KIT Lite


Purpose:		Setup up push buttons and LEDs

*****************************************************************************/

#include "PBLED_test.h"
#include "Timer_ISR.h"

//--------------------------------------------------------------------------//
// Function:	Init_LEDs													//
//																			//
// Parameters:	None														//
//																			//
// Return:		None														//
//																			//
// Description:	This function configures PORTC as output for LEDs
//--------------------------------------------------------------------------//
void Init_LEDs(void)
{
	*pPORTCIO_FER 		= 0x03F0;		// Setup PC4 - PC9 for LEDs
	*pPORTCIO_DIR		= 0x03F0;		// Setup port for output
	*pPORTCIO_SET 		= 0x03F0;		// Turn all LEDs on
	*pPORTCIO_CLEAR		= 0x03F0;		// Turn all LEDs off
}

//--------------------------------------------------------------------------//
// Function:	Init_PushButtons											//
//																			//
// Parameters:	None														//
//																			//
// Return:		None														//
//																			//
// Description:	This function configures PORTF as inputs for push buttons
//--------------------------------------------------------------------------//

void Init_PushButtons(void)
{
	*pFIO_INEN		= 0xF;		// Enable input buffer
	*pFIO_DIR		&= (~0xF);	// Setup port for inputs

}


//////////////////////////////////////////////////////////////////////////////
// void LED_Bar(const int iSpeed)
//
// PURPOSE:		Display a blinking LED bar
//
// INPUT:		iSpeed - the speed of the blink
//////////////////////////////////////////////////////////////////////////////
void LED_Bar(const int iSpeed)
{
	enLED n;
	int j;

	for( n = LED1; n < LAST_LED; (n <<= 1) )
	{
		ClearSet_LED(n, 3);
		Delay(iSpeed);
	}
}



//////////////////////////////////////////////////////////////////////////////
// void Blink_LED(const int enleds, const int iSpeed)
//
// PURPOSE:		Blink various LED's
//
// INPUT:		iSpeed - the speed of the blink
//				enleds - the LED to actually blink
//////////////////////////////////////////////////////////////////////////////
void Blink_LED(const int enleds, const int iSpeed)
{
	int j;
	enLED n;

	while( 1 )
	{
		for( n = LED1; n < LAST_LED; (n <<= 1) )
		{
			if( n & enleds )
			{
				ClearSet_LED(n, 3);
			}
		}

		Delay(iSpeed);
	}
}



//////////////////////////////////////////////////////////////////////////////
// void ClearSet_LED_Bank(const int enleds, const int iState)
//
// PURPOSE:		Clear or set a particular LED or group of LED's
//
// INPUT:		iState - the state ON, OFF, TGL
//				enleds - the LED(s) to actually blink
//////////////////////////////////////////////////////////////////////////////
void ClearSet_LED_Bank(const int enleds, const int iState)
{
	enLED n;
	int nTempState = iState;


	for( n = LED1; n < LAST_LED; (n <<= 1) )
	{
		if( n & enleds )
		{
			ClearSet_LED(n, (nTempState & 0x3) );
		}

		nTempState >>= 2;
	}
}


//////////////////////////////////////////////////////////////////////////////
// void ClearSet_LED(const enLED led, const int bState)
//
// PURPOSE:		Clear or set a particular LED (NOT A GROUP)
//
// INPUT:		iState - the state ON, OFF, TGL
//				enleds - the LED(s) to actually blink
//////////////////////////////////////////////////////////////////////////////
void ClearSet_LED(const enLED led, const int bState)
{
	if( 0 == bState ) // clear
	{
		*pPORTCIO_CLEAR = led;
	}
	else if( 1 == bState ) // set
	{
		*pPORTCIO_SET = led;
	}
	else // toggle the bits
	{
		*pPORTCIO_TOGGLE = led;
	}

}

int TEST_PBLED(void)
{
	// enable push button PB1, PB2, PB3, PB4
	*pFIO_INEN		= 0xF;		// Enable input buffer
	*pFIO_DIR		&= (~0xF);	// Setup port for inputs


	// clear all the LED's
	ClearSet_LED_Bank( (-1), 0x0000);

	int nPushed = 0;
	int temp = 0;
	unsigned int nTimer = SetTimeout(0x400000);
	if( ((unsigned int)-1) != nTimer )
	{
		do{
			temp = *pFIO_FLAG_D;
			if( 0x1 == (temp & 0x1) )
			{	// PB1 was pressed.
				nPushed |= 0x1;
				ClearSet_LED_Bank( (LED1|LED2|LED3|LED4|LED5|LED6), 0x15 );
			}
			else if( 0x2 == (temp & 0x2) )
			{	// PB2 was pressed.
				nPushed |= 0x2;
				ClearSet_LED_Bank( (LED1|LED2|LED3|LED4|LED5|LED6), 0x540);
			}
			else if( 0x4 == (temp & 0x4) )
			{	// PB2 was pressed.
				nPushed |= 0x4;
				ClearSet_LED_Bank( (LED1|LED2|LED3|LED4|LED5|LED6), 0x111);
			}
			else if( 0x8 == (temp & 0x8) )
			{	// PB2 was pressed.
				nPushed |= 0x8;
				ClearSet_LED_Bank( (LED1|LED2|LED3|LED4|LED5|LED6), 0x444);
			}
		}while( (0xF != nPushed) && (!IsTimedout(nTimer))  );
	}
	ClearTimeout(nTimer);

	// either a timeout occured, or all the push buttons were not depressed.

	// disable  push button PB1, PB2, PB3, PB4
	*pFIO_INEN		= 0x0000;			// Pushbutton
	*pFIO_DIR		&= (~0x0000);		// Pushbutton

	return (0xF == nPushed);
}

⌨️ 快捷键说明

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