www.openedv.com
您好,欢迎您!    会员注册 | 登入 
公告:欢迎访问www.openedv.com开源电子网,开源共享共同进步,祝您新年快乐,万事如意!
设为首页 | 加入收藏
论坛首页 » ARM技术 前往: 
原子哥帮看看定时器实验的程序问题
发表人 内容
[Down] [Up]
[楼主位] 411706246

等级:NO
注册时间:
2011/10/25 22:20
文章: 8
来自: 陕西
离线

先是主函数
 #include<stm32f10x_lib.h>
#include<sys.h>
#include<delay.h>
#include<usart.h>
#include<led.h>
#include<timer3.h>

//定时器实验
 u8 t=0;
int main(void)
{
  Stm32_Clock_Init(9);
  delay_init(72);
  uart_init(72,9600);
  LED_Init();
  timer3_init(5000,7199); //10KHz的计数频率, 计数到5000为500ms
  while(1)
  {
   LED1=!LED1;
   printf("%d\n",t);
   delay_ms(400);
  }


}

中断函数和初始化,
#include<timer3.h>
#include<led.h>
#include<usart.h>
//定时器驱动

void timer3_init(u16 arr,u16 psc)
{
  RCC->APB1ENR|=1<<1; //enabel timer3 clock
  TIM3->PSC=psc;   //set the psc
  TIM3->ARR=arr;   //set the rerest load register
  TIM3->DIER|=1<<0;   //enable update and tiger interrupt
  TIM3->DIER|=1<<6;
  TIM3->CR1|=0x01;   //enable timer
  MY_NVIC_Init(1,3,TIM3_IRQChannel,2);//set the intertupt 2 rod 2 prioriry and sector 2
}


 //中断服务函数
 extern u8 t;
 void TIM3_IRQHandler(void)
 {
  if(TIM3->SR&0x0001)
  {
   LED0=!LED0;
   printf("ok\n");
   t=1;
  }
 
  TIM3->SR&=~(1<<0);//清除中断标志位
  
 }
都向你写的改了,可是一直在中断里面不出来,用串口试过就是一直都在法会“OK”。



[加为好友] 回复 引用回复
[Down] [Up]
[1楼] 正点原子


等级:NO
注册时间:
2010/12/02 10:41
文章: 8097
来自: 湖南
在线

如果和我的一摸一样,肯定是OK的.
不信你可以先用我的代码试试.

如果用我的可以,那就慢慢对照吧,总有哪里没抄对的.



我的淘宝小店:http://shop62103354.taobao.com
[加为好友] 回复 引用回复
 
前往: 

Powered by ALIENTEK工作室 © 粤ICP备12000418号-1