意图:测验,电阻,接入不同的频率方波,都会变成什么姿态。
//#include
#include “key.h”
#include “SYSTICK.h”
void main()
{
init();
GPIOC->CRL &=~ (0xff<<0);
GPIOC->CRL |= (3<<0)|(3<<4);
GPIOC->ODR |= 0;
TIM5->ARR = 500 ;
TIM5->CCR1 = 250;
while(1)
{
scan();
}
}
void init()
{
SystemInit();
SYSTICK_Init(72);
RCC->APB2ENR |= (1<<11) | (1<<4) | (1<<2) | (1<<0); //翻开pc pa和t1时钟
GPIOC->CRL &=~ (0xff<<0);
GPIOC->CRL |= (1<<3)|(1<<7);
GPIOC->ODR |= (1<<0)|(1<<1);//按钮io初始化
GPIOA->CRH |= (11<<0)|(11<<4)|(11<<8)| (11<<12);//设置PA口为50M复用推挽输出
RCC->APB1ENR |= (1<<3); //敞开t5的时钟 led
RCC->APB2ENR |= (1<<2)|(1<<0);
TIM5->CR1 |= (0<<4)|(1<<7);//向上计数,使能重装载寄存器
TIM5->ARR = 20;//周期设置
TIM5->PSC = 0; //预分频设置
TIM5->CCMR1 &=~ ((3<<8)|(3<<0));////设置为ch1 ch2为输出形式
TIM5->CCMR1 |= (7<<12)|(1<<11)|(7<<4)|(1<<3); //pwm形式和输出比较预装载使能
TIM5->CCMR2 &=~ ((3<<8)|(3<<0));//设置为ch4 ch3为输出形式
TIM5->CCMR2 |= (7<<12)|(1<<11)|(7<<4)|(1<<3); //pwm形式和输出比较预装载使能
TIM5->CCER |= (1<<12)|(1<<8)|(1<<4)|(1<<0);//敞开ch4输出
TIM5->CR1|=(1<<0);
TIM5->CCR1 = 10;
GPIOA->CRL |= (2<<2)|(3<<0);
GPIOA->CRL &=~ (0xf<<4);
GPIOA->CRL |= (2<<6)|(3<<4);
GPIOA->CRL &=~ (0xf<<8);
GPIOA->CRL |= (2<<10)|(3<<8);
GPIOA->CRL &=~ (0xf<<12);
GPIOA->CRL |= (2<<14)|(3<<12);
}
{
if(Scan_Mode())
{
TIM5->ARR = TIM5->ARR+100 ;
TIM5->CCR1 = TIM5->CCR1+50 ;
TIM5->EGR = 1;
}
if(Scan_Add())
{
TIM5->ARR = TIM5->ARR-50 ;
TIM5->CCR1 = TIM5->CCR1-25 ;
TIM5->EGR = 1;
}
}
这是直接丈量管角上的波形
这是接了一块十分欠好的导线,丈量的波形