本人想用TIM定时器做一个秒计时器,中断函数要写入主函数,不会写,求解,

2019-08-20 18:17发布

本人想用TIM定时器做一个秒计时器,中断函数要写入主函数,不会写,求解,程序如下:
 int main(void)
  { 
  
short x,y,z,a,Tim1,hour,min,sec,b,c;
char tmp1[33],tmp2[33];
  short T,Temperature;
// short  Tim1,T1;
u16 t=0;  
u8 tmp_buf[33],count[80];
char buffer[33];
  delay_init();     //???±??????????
NVIC_Configuration();
uart_init(115200); //?®??????????9600
  LED_Init();   //????????LED??????????????
LCD_Init();   //??????LCD
  KEY_Init(); //°??ü??????
  NRF24L01_Init();     //??????NRF24L01
  TIM3_Int_Init(9999,7199);
  POINT_COLOR=RED;//?è??×??????ì?? 
LCD_ShowString(60,50,200,16,16,"Mini STM32");
LCD_ShowString(60,70,200,16,16,"MPU6050 NRF24L01 TEST");
LCD_ShowString(60,90,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(60,110,200,16,16,"2015/6/1");
   
上面是函数的初始化,下面是timer库函数;
#include "timer.h"
#include "led.h"




//?????????????¨?±?÷3!



void TIM3_Int_Init(u16 arr,u16 psc)
{
    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //?±??????

TIM_TimeBaseStructure.TIM_Period = arr; //?è???????????ü??????×°????????×?????×°???????÷???????? ??????5000??500ms
TIM_TimeBaseStructure.TIM_Prescaler =psc; //?è??????×÷??TIMx?±?????????????¤·?????  10Khz??????????  
TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1;//?è???±??·???:TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //TIM?ò??????????
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //?ù??TIM_TimeBaseInitStruct?????¨????????????TIMx???±???ù??????
 
TIM_ITConfig(  //?????ò???§?????¨??TIM????
TIM3, //TIM2
TIM_IT_Update ,
ENABLE  //????
);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;  //TIM3????
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  //??????????0??
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;  //????????3??
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨??±?????
NVIC_Init(&NVIC_InitStructure);  //?ù??NVIC_InitStruct?????¨???????????????èNVIC?????÷

TIM_Cmd(TIM3, ENABLE);  //????TIMx???è
 
}


  void TIM3_IRQHandler(void)  //TIM3????
 {
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //?ì?é???¨??TIM????·??ú??·?:TIM ?????? 
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update  );  //????TIMx???????????í??:TIM ?????? 
LED1=!LED1;
  

}
要用到中断服务函数,中断服务函数实现LED1的1S的翻转,本人想做定时器,实现时分秒的显示,想在后面写程序,但是这个程序就是调不到主函数里面去,求解 。。。。。。













  
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
yh411335
1楼-- · 2019-08-20 22:03
 精彩回答 2  元偷偷看……
八度空间
2楼-- · 2019-08-20 23:56
用结构体传递,数组传递,全局变量传递,局部变量传递,都是可以的
yh411335
3楼-- · 2019-08-21 04:30
回复【2楼】八度空间:
---------------------------------
就局部变量传递吧,怎么传,求大神解决呀。。。。。。

一周热门 更多>