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

📄 pbled_test.c

📁 ADI blackfin processor BF527 Ezkti test driver
💻 C
字号:
/*****************************************************************************
**																			**
**	 Name: 	PB_LED_test.c											**	
**																			**
******************************************************************************

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

Pjoject Name:	BF537 ATE

Date Modified:	12/10/04				Ver 0.0

Software:		VisualDSP++ 4.0

Hardware:		ADSP-BF537 EZ-KIT Lite

Connections:	

Purpose:		Perform a POST ATE on the BF537 EZ-Kit Lite

*****************************************************************************/
#include "PBLED_test.h"
#include "Timer_ISR.h"





//--------------------------------------------------------------------------//
// Function:	Init_LEDs													//
//																			//
// Parameters:	None														//
//																			//
// Return:		None														//
//																			//
// Description:	This function configures PORTF2 as output for LEDs
//--------------------------------------------------------------------------//
void Init_LEDs(void)
{
#if (__SILICON_REVISION__ < 0x0001) // Workaround silicon anomaly 05000212
	int temp;	
	temp = *pPORTF_FER;
	temp++;
	*pPORTF_FER = 0x0000;
#endif
	*pPORTF_FER = 0x0000;
	
	*pPORTFIO_DIR		= 0x0FC0;		// LEDs
	*pPORTFIO_SET 		= 0x0FC0;
	*pPORTFIO_CLEAR		= 0x0FC0;
}

void Init_PushButtons(void)
{
	// enable push button PB1 and PB2
	*pPORTFIO_INEN		= 0x000C;			// Pushbutton
	*pPORTFIO_DIR		&= (~0x000C);		// Pushbutton
	
	*pPORTFIO_INEN		= 0x003C;			// Pushbutton
	*pPORTFIO_DIR		&= (~0x003C);		// Pushbutton
	
}


//////////////////////////////////////////////////////////////////////////////
// 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
	{
		*pPORTFIO_CLEAR = led;
	}
	else if( 1 == bState ) // set
	{
		*pPORTFIO_SET = led;	
	}
	else // toggle the bits
	{
		*pPORTFIO_TOGGLE = led;
	}

}

// 0x04 == PB1
// 0x08 == PB2
// 0x10 == PB3
// 0x20 == PB4
int TEST_PBLED(void)
{
	// enable push button PB1, PB2, PB3, PB4
	*pPORTFIO_INEN		= 0x003C;			// Pushbutton
	*pPORTFIO_DIR		&= (~0x003C);		// Pushbutton
	
	// 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 = *pPORTFIO;
			if( 0x04 == (temp & 0x04) )
			{	// PB1 was pressed.
				nPushed |= 0x04;
				ClearSet_LED_Bank( (LED1|LED2|LED3|LED4|LED5|LED6), 0x15 );
			}
			else if( 0x08 == (temp & 0x08) )
			{	// PB2 was pressed.
				nPushed |= 0x08;
				ClearSet_LED_Bank( (LED1|LED2|LED3|LED4|LED5|LED6), 0x540);
			}
			else if( 0x10 == (temp & 0x10) )
			{	// PB2 was pressed.
				nPushed |= 0x10;
				ClearSet_LED_Bank( (LED1|LED2|LED3|LED4|LED5|LED6), 0x111);
			}
			else if( 0x20 == (temp & 0x20) )
			{	// PB2 was pressed.
				nPushed |= 0x20;
				ClearSet_LED_Bank( (LED1|LED2|LED3|LED4|LED5|LED6), 0x444);
			}
		}while( (0x3C != nPushed) && (!IsTimedout(nTimer))  );
	}
	ClearTimeout(nTimer);
	
	// either a timeout occured, or all the push buttons were not depressed.
	
	// disable  push button PB1, PB2, PB3, PB4
	*pPORTFIO_INEN		= 0x0000;			// Pushbutton
	*pPORTFIO_DIR		&= (~0x0000);		// Pushbutton
	
	return (0x3C == nPushed);
}

⌨️ 快捷键说明

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