找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3386|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

關(guān)于stm32單片機(jī)用SysTick 用作中斷使小燈閃 但是程序燒進(jìn)去后卻一直亮

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:188172 發(fā)表于 2017-4-10 18:29 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#ifndef bsp_led_h
#define bsp_led_h

#include "stm32f10x.h"

void RCC_Configuration(void);   
void DPIO_Configuration(void);  
void SysTick_Configuration(void);
void NVIC_Configuration(void);

void Delay(u32 n);
        
#endif




#include "bsp_led.h"

void RCC_Configuration()
{
        SystemInit();
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
        RCC_HCLKConfig(RCC_SYSCLK_Div1);
}

void DPIO_Configuration()
{
  GPIO_InitTypeDef GPIO_InitStructure;
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
        GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP;
        GPIO_Init(GPIOB,&GPIO_InitStructure);                        
}                 

void SysTick_Configuration()
{
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
        SysTick_Config(9000000);
}

void NVIC_Configuration()
{
  NVIC_InitTypeDef NVIC_InitStructure;
        
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
        
        NVIC_InitStructure.NVIC_IRQChannel =SysTick_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
}


在stm32f10x_it.c中的中斷處理函數(shù):
void SysTick_Handler(void)
{
        NVIC_ClearPendingIRQ(SysTick_IRQn);
        if(GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_5)==RESET)
        {
           GPIO_SetBits(GPIOB, GPIO_Pin_5);
        }
        else
        {
           GPIO_ResetBits(GPIOB, GPIO_Pin_5);
        }
}





分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表