標題: STM32定時器上電亮10s后熄滅 [打印本頁]

作者: sr861126    時間: 2022-3-3 13:51
標題: STM32定時器上電亮10s后熄滅
#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "usart.h"
#include "timer.h"
u8 num;

//定時器中斷實驗  

extern u8 i;      
int main(void)
{               

        delay_init();                     //延時函數(shù)初始化         
        NVIC_Configuration();          //設置NVIC中斷分組2:2位搶占優(yōu)先級,2位響應優(yōu)先級
        uart_init(9600);         //串口初始化為9600
        LED_Init();                             //LED端口初始化
        TIM3_Int_Init(4999,7199);//10Khz的計數(shù)頻率,計數(shù)到5000為500ms  
while(1)
        {
//                LED0=!LED0;
//                delay_ms(2000);                  
        if(i<10)
        {
//    i=0;      

        for(num=0;num<10;num++)
                {
               
               
                        LED0=0;
                        delay_ms(500);
                  LED0=1;
                  delay_ms(500);
                }
      
}
if(i>10)
        {
      
        LED0=1;
        TIM_Cmd(TIM3, DISABLE);  //使能TIMx               
        }
      
      
      
      
        }         


}  





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1