|
每隔一段時(shí)間閃爍 本例程PB9閃爍
IMG20180709134925.jpg (2.63 MB, 下載次數(shù): 46)
下載附件
2018-7-9 13:54 上傳
IMG20180709134919.jpg (2.6 MB, 下載次數(shù): 41)
下載附件
2018-7-9 13:54 上傳
0.png (45.06 KB, 下載次數(shù): 57)
下載附件
2018-7-10 03:24 上傳
單片機(jī)源程序如下:
- /******************************************************************************8
- 實(shí)驗(yàn)現(xiàn)象: 每隔一段時(shí)間閃爍
- *******************************************************************************/
- #include "stm32f10x_lib.h"
- /******************************** 變量定義 ---------------------------------------------------------*/
- GPIO_InitTypeDef GPIO_InitStructure;
- ErrorStatus HSEStartUpStatus;
- /*********************************聲明函數(shù) -----------------------------------------------*/
- void RCC_Configuration(void);
- void NVIC_Configuration(void);
- void Delay(vu32 nCount);
- /*******************************************************************************
- 主函數(shù)
- *******************************************************************************/
- int main(void)
- {
- #ifdef DEBUG
- debug();
- #endif
- RCC_Configuration(); //系統(tǒng)時(shí)鐘配置函數(shù)
- NVIC_Configuration(); //NVIC配置函數(shù)
- //使能APB2總線外設(shè)時(shí)鐘
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);//定義工作端口,目前使用的是A口和B口
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE); //關(guān)閉調(diào)試 端口重新映射 使用仿真器調(diào)試時(shí),不能用此語(yǔ)
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All; // 選擇所有腳
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //配置成推挽式輸出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //輸出模式下 I/O輸出速度 50M HZ
- GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化PA口
- GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化PB口
-
- while (1)
- {
- GPIO_Write(GPIOB, 0xffff); //寫一個(gè)字?jǐn)?shù)據(jù)到PB口
- Delay(0x8FFFFF); // 延時(shí)
- GPIO_Write(GPIOB, 0x0000); //寫一個(gè)字?jǐn)?shù)據(jù)到PB口
- Delay(0x8FFFFF); // 延時(shí)
- }
- }
- /*******************************************************************************
- * 配置RCC
- *******************************************************************************/
- void RCC_Configuration(void)
- {
- //復(fù)位RCC外部設(shè)備寄存器到默認(rèn)值
- RCC_DeInit();
- //打開外部高速晶振
- RCC_HSEConfig(RCC_HSE_ON);
- //等待外部高速時(shí)鐘準(zhǔn)備好
- HSEStartUpStatus = RCC_WaitForHSEStartUp();
- if(HSEStartUpStatus == SUCCESS) //外部高速時(shí)鐘已經(jīng)準(zhǔn)別好
- {
- //開啟FLASH的預(yù)取功能
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
- //FLASH延遲2個(gè)周期
- FLASH_SetLatency(FLASH_Latency_2);
-
- //配置AHB(HCLK)時(shí)鐘=SYSCLK
- RCC_HCLKConfig(RCC_SYSCLK_Div1);
-
- //配置APB2(PCLK2)鐘=AHB時(shí)鐘
- RCC_PCLK2Config(RCC_HCLK_Div1);
- //配置APB1(PCLK1)鐘=AHB 1/2時(shí)鐘
- RCC_PCLK1Config(RCC_HCLK_Div2);
- //配置PLL時(shí)鐘 == 外部高速晶體時(shí)鐘*9 PLLCLK = 8MHz * 9 = 72 MHz
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
- //使能PLL時(shí)鐘
- RCC_PLLCmd(ENABLE);
- //等待PLL時(shí)鐘就緒
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
- {
- }
- //配置系統(tǒng)時(shí)鐘 = PLL時(shí)鐘
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
- //檢查PLL時(shí)鐘是否作為系統(tǒng)時(shí)鐘
- while(RCC_GetSYSCLKSource() != 0x08)
- {
- }
- }
- }
- /*******************************************************************************
- * NVIC配置函數(shù)
- *******************************************************************************/
- void NVIC_Configuration(void)
- {
- #ifdef VECT_TAB_RAM
- /* Set the Vector Table base location at 0x20000000 */
- NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
- #else /* VECT_TAB_FLASH */
- /* Set the Vector Table base location at 0x08000000 */
- NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
- #endif
- }
- /*******************************************************************************
- * 延時(shí)函數(shù)
- *******************************************************************************/
- void Delay(vu32 nCount)
- {
- for(; nCount != 0; nCount--);
- }
- #ifdef DEBUG
- /*******************************************************************************
- * Function Name : assert_failed
- * Description : Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * Input : - file: pointer to the source file name
- * - line: assert_param error line source number
- * Output : None
- * Return : None
- *******************************************************************************/
- void assert_failed(u8* file, u32 line)
- {
- /* User can add his own implementation to report the file name and line number,
- ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
- /* Infinite loop */
- while (1)
- {
- }
- }
- #endif
- /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
復(fù)制代碼
所有資料51hei提供下載:
LED燈閃爍.rar
(225.62 KB, 下載次數(shù): 46)
2018-7-9 13:47 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|