當前位置:首頁 > 單片機 > 單片機
[導讀]基于stm32 F401 discovery版實現(xiàn)button polling & interrupt點亮LED/*********************************************************************************@fileTemplate/main.c*@authorMCDApplicationTeam*@version

基于stm32 F401 discovery版實現(xiàn)button polling & interrupt點亮LED


/**

******************************************************************************

*@fileTemplate/main.c

*@authorMCDApplicationTeam

*@versionV1.0.0

*@date11-September-2013

*@briefMainprogrambody

******************************************************************************

*@attention

*

*

©COPYRIGHT2013STMicroelectronics

*

*LicensedunderMCD-STLibertySWLicenseAgreementV2,(the"License");

*YoumaynotusethisfileexceptincompliancewiththeLicense.

*YoumayobtainacopyoftheLicenseat:

*

*http://www.st.com/software_license_agreement_liberty_v2

*

*Unlessrequiredbyapplicablelaworagreedtoinwriting,software

*distributedundertheLicenseisdistributedonan"ASIS"BASIS,

*WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied.

*SeetheLicenseforthespecificlanguagegoverningpermissionsand

*limitationsundertheLicense.

*

******************************************************************************

*/

/*Includes------------------------------------------------------------------*/

#include"main.h"

/**@addtogroupTemplate

*@{

*/

/*Privatetypedef-----------------------------------------------------------*/

/*Privatedefine------------------------------------------------------------*/

#defineUSER_BUTTON_INTERRUPT

#defineKEY_ON0

#defineKEY_OFF1

/*Privatemacro-------------------------------------------------------------*/

/*Privatevariables---------------------------------------------------------*/

/*Privatefunctionprototypes-----------------------------------------------*/

staticvoidDelay(__IOuint32_tnCount);

uint8_tKey_Scan(GPIO_TypeDef*GPIOx,u16GPIO_Pin);

/*Privatefunctions---------------------------------------------------------*/

/**

*@briefMainprogram

*@paramNone

*@retvalNone

*/

intmain(void)

{

/*!

thisisdonethroughSystemInit()functionwhichiscalledfromstartup

file(startup_stm32f401xx.s)beforetobranchtoapplicationmain.

ToreconfigurethedefaultsettingofSystemInit()function,referto

system_stm32f4xx.cfile

*/

/*Addyourapplicationcodehere*/

/*InitializeLEDS*/

STM_EVAL_LEDInit(LED3);

STM_EVAL_LEDInit(LED4);

STM_EVAL_LEDInit(LED5);

STM_EVAL_LEDInit(LED6);

#ifdefUSER_BUTTON_INTERRUPT

/*Initializethebuttoninterrupt*/

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);

STM_EVAL_PBInit(BUTTON_USER,BUTTON_MODE_EXTI);

#endif

#ifdefUAER_BUTTON_POLLING

/*Initializethebuttonnormal*/

STM_EVAL_PBInit(BUTTON_USER,BUTTON_MODE_GPIO);

while(1)

{

if(Key_Scan(GPIOA,GPIO_Pin_0)==KEY_ON)

{

/*LED1·′×a*/

STM_EVAL_LEDToggle(LED3);

}

}

#endif

#ifdefLED_ON_OFF

while(1)

{

STM_EVAL_LEDOn(LED3);

/*Insertdelay*/

Delay(0x3FFFFF);

/*PD13tobetoggled*/

STM_EVAL_LEDOn(LED4);

/*Insertdelay*/

Delay(0x3FFFFF);

/*PD14tobetoggled*/

STM_EVAL_LEDOn(LED5);

/*Insertdelay*/

Delay(0x3FFFFF);

/*PD15tobetoggled*/

STM_EVAL_LEDOn(LED6);

/*Insertdelay*/

Delay(0x7FFFFF);

STM_EVAL_LEDOff(LED3);

STM_EVAL_LEDOff(LED4);

STM_EVAL_LEDOff(LED5);

STM_EVAL_LEDOff(LED6);

//GPIO_ResetBits(GPIOD,GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);

/*Insertdelay*/

Delay(0xFFFFFF);

}

#endif

/*Infiniteloop*/

while(1)

{

}

}

#ifdefUSE_FULL_ASSERT

/**

*@briefReportsthenameofthesourcefileandthesourcelinenumber

*wheretheassert_paramerrorhasoccurred.

*@paramfile:pointertothesourcefilename

*@paramline:assert_paramerrorlinesourcenumber

*@retvalNone

*/

voidassert_failed(uint8_t*file,uint32_tline)

{

/*Usercanaddhisownimplementationtoreportthefilenameandlinenumber,

ex:printf("Wrongparametersvalue:file%sonline%drn",file,line)*/

/*Infiniteloop*/

while(1)

{

}

}

#endif

/**

*@}

*/

/**

*@briefDelayFunction.

*@paramnCount:specifiestheDelaytimelength.

*@retvalNone

*/

voidDelay(__IOuint32_tnCount)

{

while(nCount--)

{

}

}

/**

本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或將催生出更大的獨角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉型技術解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術公司SODA.Auto推出其旗艦產品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關鍵字: 汽車 人工智能 智能驅動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務中斷的風險,如企業(yè)系統(tǒng)復雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務連續(xù)性,提升韌性,成...

關鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網易近期正在縮減他們對日本游戲市場的投資。

關鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產業(yè)博覽會開幕式在貴陽舉行,華為董事、質量流程IT總裁陶景文發(fā)表了演講。

關鍵字: 華為 12nm EDA 半導體

8月28日消息,在2024中國國際大數(shù)據(jù)產業(yè)博覽會上,華為常務董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權最終是由生態(tài)的繁榮決定的。

關鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應對環(huán)境變化,經營業(yè)績穩(wěn)中有升 落實提質增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務引領增長 以科技創(chuàng)新為引領,提升企業(yè)核心競爭力 堅持高質量發(fā)展策略,塑強核心競爭優(yōu)勢...

關鍵字: 通信 BSP 電信運營商 數(shù)字經濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術學會聯(lián)合牽頭組建的NVI技術創(chuàng)新聯(lián)盟在BIRTV2024超高清全產業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術創(chuàng)新聯(lián)...

關鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關鍵字: BSP 信息技術
關閉
關閉