📄 ledbutton_polled.c
字号:
/*********************************************************************************
Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.
This software is proprietary and confidential. By using this software you agree
to the terms of the associated Analog Devices License Agreement.
$RCSfile: LEDButton_Polled.c,v $
$Revision: 1.1 $
$Date: 2007/03/28 18:50:15 $
Description:
This is a little demo to show how to use the flag service for the
LEDs and push buttons.
On the ADSP-BF533 EZ-Kit, the push buttons on the EZ-Kit must be
enabled by having switches 1 through 4 turned on on the SW9 DIP switch
on the board.
On the ADSP-BF537 EZ-Kit, the push buttons on the EZ-Kit must be
enabled by having switches 1 through 4 turned on on the SW5 DIP switch
on the board.
On the ADSP-BF561 EZ-Kit, the push buttons on the EZ-Kit must be
enabled by having switches 1 through 4 turned on on the SW4 DIP switch
on the board.
*********************************************************************************/
/*********************************************************************
Include files
*********************************************************************/
#include "services\services.h" // system services
#include "ezkitutilities.h" // ezkit utilities
/*********************************************************************
Globals
*********************************************************************/
u32 timedelay = 250; //value in ms
/*********************************************************************
Function: main
Description: This function is main function of the demo. Everything
is done in main to show exactly how to use the flag
service.
In the unlikely event we get an error somewhere,
this demo uses the ezErrorCheck function to light
all the LEDs and spin in a loop.
*********************************************************************/
void main(void) {
u32 ResponseCount; // number of things a service can control
u32 ReturnValue; // the return value from calling flag functions
u32 i; // loop variable
// configure power
ezInit(1);
// initialize the flag manager because the LEDs and buttons connect via flags
// Since callbacks are not being used memory does not to be given to the service
ezErrorCheck(adi_flag_Init(NULL, 0, &ResponseCount, NULL));
// configure push buttons as inputs for button 1
adi_flag_Open(ezButtonToFlag[0]);
adi_flag_SetDirection(ezButtonToFlag[0], ADI_FLAG_DIRECTION_INPUT);
// configure push buttons as inputs for button 2
adi_flag_Open(ezButtonToFlag[1]);
adi_flag_SetDirection(ezButtonToFlag[1], ADI_FLAG_DIRECTION_INPUT);
// configure push buttons as inputs for button 3
adi_flag_Open(ezButtonToFlag[2]);
adi_flag_SetDirection(ezButtonToFlag[2], ADI_FLAG_DIRECTION_INPUT);
// ADSP-BF533 specific info
// initialize LEDS being used
#if defined(__ADSP_EDINBURGH__)
for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
ezInitLED(i);
}
#endif
// ADSP-BF537 & BF561 EZ-Kit specific info
// configure all the LEDS on the ADSP-BF537 & BF561 EZ-Kit
#if defined(__ADSP_BRAEMAR__) || defined (__ADSP_TETON__)
for (i=EZ_FIRST_LED; i < EZ_LAST_LED; i++){
adi_flag_Open(ezLEDToFlag[i]);
adi_flag_SetDirection(ezLEDToFlag[i], ADI_FLAG_DIRECTION_OUTPUT);
}
#endif
// Make sure all LEDS are turned off
ezTurnOffAllLEDs();
while (1){
//check if button 1 is pressed
adi_flag_Sense(ezButtonToFlag[0],&ReturnValue);
if (ReturnValue){
//if using ADSP-BF533 EZ-Kit program LED through ezkitutilities
#if defined(__ADSP_EDINBURGH__)
ezToggleLED(EZ_FIRST_LED);
#endif
//if using ADSP-BF537 or ADSP-BF561 EZ-Kit program LED through flag service
#if defined(__ADSP_TETON__) || defined(__ADSP_BRAEMAR__)
adi_flag_Toggle(ezLEDToFlag[0]);
#endif
ezDelay(timedelay);;
}
//check if button 2 is pressed
adi_flag_Sense(ezButtonToFlag[1],&ReturnValue);
if (ReturnValue){
//if using ADSP-BF533 EZ-Kit program LED through ezkitutilities
#if defined(__ADSP_EDINBURGH__)
ezToggleLED(EZ_FIRST_LED+1);
#endif
//if using ADSP-BF537 or ADSP-BF561 EZ-Kit program LED through flag service
#if defined(__ADSP_TETON__) || defined(__ADSP_BRAEMAR__)
adi_flag_Toggle(ezLEDToFlag[1]);
#endif
ezDelay(timedelay);
}
//check if button 3 is pressed and exit if it is pressed
adi_flag_Sense(ezButtonToFlag[2],&ReturnValue);
if (ReturnValue){
break;
}
}//end while
// terminate the flag service
adi_flag_Terminate();
// that's all folks!
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -