|
最近本人在搞频率计,用的处理器是stm32F4,代码从F1的移植过来。测出来的结果有点小误差,见谅a!
单片机源程序如下:
- #include "stm32f4xx.h"
- #include "delay.h"
- #include "usart.h"
- #include "counter.h"
- //#include "SysTick.h"
- #include "sys.h"
- #include "stdio.h"
- /***********************************************************************************************
- 定时器外部时钟模式
- ************************************************************************************************/
- u32 count_s;
- u16 count_ms;
- extern u16 count_i;
- extern u16 count_over;
- int main(void)
- {
- NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(9600); //串口初始化为9600
- TIM3_External_Clock_CountingMode();
- TIM4_timer_Init();
- while(1)
- {
- if(count_i>100)
- {
- count_ms = TIM3->CNT;
- count_s = count_over*65535.0 + count_ms;
- printf("%.3f kHz\r\n ",count_s/1000.0); //打印数据
- count_i=0;
- count_over=0;
- TIM3->CNT=0;
- }
- }
- }
复制代码
所有资料51hei提供下载:
|
|