主函数
#include "led.h”
#include "delay.h"
#include "sys.h"
#include "timer.h"
#include "lcd.h"
#include "key.h"
#include "usart.h"
//ALIENTEK Mini STM32¿a·¢°å·¶ày′úÂë7
//¶¨ê±Æ÷ÖD¶ÏêμÑé
//¼¼êõÖ§3Ö£o
www.openedv.com
//1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾
extern u32 sec;
int main(void)
{
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// éèÖÃÖD¶ÏóÅÏ輶·Ö×é2
TIM3_Int_Init(4999,7199);//10KhzμļÆêyÆμÂ꣬¼Æêyμ½5000Îa500ms
//
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
uart_init(9600); //′®¿ú3õê¼»ˉÎa9600
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
LCD_Init();
POINT_COLOR=RED;
while(1)
{
LCD_ShowNum(150,162,sec,2,16);
}
}
timer函数
#include "timer.h"
#include "led.h"
#include "sys.h"
#include "usart.h"
#include "delay.h"
//////////////////////////////////////////////////////////////////////////////////
//±¾3ìDòÖ»1©Ñ§Ï°ê1óã¬Î′¾-×÷ÕßDí¿é£¬2»μÃóÃóúÆäËüèÎoÎóÃí¾
//Mini STM32¿a·¢°å
//í¨óö¨ê±Æ÷ Çy¶ˉ′úÂë
//ÕyμãÔ-×ó@ALIENTEK
//¼¼êõÂÛì3:
www.openedv.com
//DT¸ÄèÕÆú:2010/12/03
//°æ±¾£oV1.0
//°æè¨ËùóD£¬μá°æ±Ø¾¿¡£
//Copyright(C) ÕyμãÔ-×ó 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//í¨óö¨ê±Æ÷ÖD¶Ï3õê¼»ˉ
//Õaàïê±ÖóÑ¡ÔñÎaAPB1μÄ2±¶£¬¶øAPB1Îa36M
//arr£o×Ô¶ˉÖØ×°Öμ¡£
//psc£oê±ÖóÔ¤·ÖÆμêy
//Õaàïê1óÃμÄêǶ¨ê±Æ÷3!
volatile u32 sec=0;
volatile u32 min=0;
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //ê±Öóê1Äü
TIM_TimeBaseStructure.TIM_Period = arr; //éèÖÃÔúÏÂò»¸ö¸üDÂê¼t×°èë»î¶ˉμÄ×Ô¶ˉÖØ×°ÔؼÄ′æÆ÷ÖüÆúμÄÖμ ¼Æêyμ½5000Îa500ms
TIM_TimeBaseStructure.TIM_Prescaler =psc; //éèÖÃóÃà′×÷ÎaTIMxê±ÖóÆμÂê3yêyμÄÔ¤·ÖÆμÖμ 10KhzμļÆêyÆμÂê
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //éèÖÃê±Öó·Ö¸î:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //TIMÏòéϼÆêyÄ£ê½
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //¸ù¾YTIM_TimeBaseInitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉTIMxμÄê±¼ä»ùêyμ¥λ
TIM_ITConfig( //ê1Äü»òÕßê§ÄüÖ¸¶¨μÄTIMÖD¶Ï
TIM3, //TIM2
TIM_IT_Update ,
ENABLE //ê1Äü
);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //ÏèÕ¼óÅÏ輶0¼¶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; //′óóÅÏ輶3¼¶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
NVIC_Init(&NVIC_InitStructure); //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèNVIC¼Ä′æÆ÷
TIM_Cmd(TIM3, ENABLE); //ê1ÄüTIMxíaéè
}
void TIM3_IRQHandler(void) //TIM3ÖD¶Ï
{
u8 sec=0;
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //¼ì2éÖ¸¶¨μÄTIMÖD¶Ï·¢éúóë·ñ:TIM ÖD¶ÏÔ′
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //Çå3yTIMxμÄÖD¶Ï′y′|àíλ:TIM ÖD¶ÏÔ′
LED1=!LED1;
}
sec++;
if(sec==60)
{
sec=0;
min++;
}
}
{
u8 sec=0;
……
}
改为:
u8 sec=0;
void TIM3_IRQHandler(void)
{
……
}或者改为:
void TIM3_IRQHandler(void)
{
static u8 sec=0;
……
}
一周热门 更多>