#include <stm32f10x_lib.h>
#include "sys.h"
#include "usart.h"
#include "delay.h"
void TIM3_External_Clock_CountingMode(void)
{
GPIO_InitTypeDef GPIO_InitStructure; // 定义管脚函数;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// TIM_ICInitTypeDef? TIM_ICInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//开启时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化调用
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; /*定时器时钟(CK_INT)频率与数字滤波器(ETR,TIx)
使用的采样频率之间的分频比为1*/
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure); // Time base configuration函数调用
/*
tmpccmr1 |= (uint16_t)(TIM_ICFilter << 12); // CCMR1_IC2F
tmpccmr1 |= (uint16_t)(TIM_ICSelection << 8); // CCMR1_CC2S
由TIM_TIxExternalCLK1Source_TI2决定了
TIM_ICSelection=TIM_ICSelection_DirectTI: CCMR1_CC2S = 01;
TIM_ICPolarity_Rising = CCER_CC2P
TIM_TIxExternalCLK1Source_TI2 = TIM_SMCR_TS
该函数定义了TIM_SlaveMode_External1;外部时钟模式1
*/
TIM_TIxExternalClockConfig(TIM3,TIM_TIxExternalCLK1Source_TI2,TIM_ICPolarity_Rising,0);
// TIM_SetCounter(TIM3, 0); // 清零计数器CNT
//TIM_Cmd(TIM3,ENABLE);
}
int main(void)
{
u16 i ;
TIM3_External_Clock_CountingMode();
TIM_SetCounter(TIM3, 0); // 清零计数器CNT
TIM_Cmd(TIM3,ENABLE);
SecCnt = 0;
TFgs.Secok = 0;
i=0;
while(1)
{
extern Delay_Nms(1000);
CountPulse = TIM_GetCounter(TIM3);
DisplayDat(10,10+24*i,CountPulse,5);
extern TFgs.Secok = 0;
if(++CountTims>=120)
{
TIM_Cmd(TIM3,DISABLE);
CountPulse = TIM_GetCounter(TIM3);
DisplayDat(10,10+24*i,CountPulse,5);
if(++i>11)i=0;
TIM_SetCounter(TIM3, 0);// 清零计数器CNT
TIM_Cmd(TIM3,ENABLE);
SecCnt = 0;
TFgs.Secok = 0;
CountTims =0;
}
}
}
编译后:
Build target 'Target 1'
compiling test.c...
test.c(48): error: #154: expression must have struct or union type
test.c(52): error: #79: expected a type specifier
test.c(53): error: #20: identifier "CountPulse" is undefined
test.c(54): warning: #223-D: function "DisplayDat" declared implicitly
test.c(55): error: #268: declaration may not appear after executable statement in block
test.c(55): warning: #260-D: explicit type is missing ("int" assumed)
test.c(55): error: #65: expected a ";"
test.c(56): error: #20: identifier "CountTims" is undefined
test.c(65): error: #154: expression must have struct or union type
test.c(42): warning: #550-D: variable "SecCnt" was set but never used
Target not created
|