標(biāo)題:
stm32基于定時(shí)器實(shí)現(xiàn)不同速度流水燈
[打印本頁]
作者:
1634588522
時(shí)間:
2021-2-21 11:28
標(biāo)題:
stm32基于定時(shí)器實(shí)現(xiàn)不同速度流水燈
通過按鍵改變流水燈速度
單片機(jī)源程序如下:
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "key.h"
#include "timer.h"
extern u16 num,count,flag;
int main(void)
{
u8 t=0;
delay_init(); //延時(shí)函數(shù)初始化
LED_Init(); //初始化與LED連接的硬件接口
KEY_Init(); //初始化與按鍵連接的硬件接口
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// 設(shè)置中斷優(yōu)先級(jí)分組2
TIM3_Int_Init(4999,7199);//10Khz的計(jì)數(shù)頻率,計(jì)數(shù)到5000為500ms
LED1=0; LED0 =1; //點(diǎn)亮LED
while(1)
{
if(flag)
{
flag=0;
LED0=!LED0;
LED1=!LED1;
}
delay_ms(10);
t=KEY_Scan(0); //得到鍵值
switch(t)
{
case KEY0_PRES:
count=2;
break;
case KEY1_PRES:
count=6;
break;
case WKUP_PRES:
LED0 =1;LED1 =1;
break;
default:
delay_ms(10);
}
}
}
復(fù)制代碼
所有程序51hei提供下載:
按鍵定時(shí)器不同速度流水燈.7z
(186.48 KB, 下載次數(shù): 28)
2021-2-21 15:19 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1