新手上路
- 积分
- 45
- 金钱
- 45
- 注册时间
- 2015-7-22
- 在线时间
- 6 小时
|
5金钱
各位大神帮我看看这超声波测距显示程序哪出问题了(寄存器)
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "exti.h"
#define Trig PAout(1)
#define Echo PAin(0)
u16 duan[]={0x3fff,0x06ff,0x5bff,0x4fff,0x66ff,0x6dff,0x7dff,0x07ff,0x7fff,0x6fff};
u16 wei[]={0xfffe,0xfffd,0xfffb};
void xianshi_init(u16 s) //??????????
{
s=s/1000;
GPIOB->ODR=duan[(s%10)]&wei[0];
delay_ms(5);
GPIOB->ODR=duan[((s/10)%10)]&wei[1];
delay_ms(5);
GPIOB->ODR=duan[(s/100)]&wei[2];
delay_ms(5);
}
int main(void)
{
u16 s;
Stm32_Clock_Init(9);//?????±???è??
delay_init(72); //???±??????
xianshi_init(s); //????????????????
RCC->APB2ENR|=1<<3; //PB????
GPIOB->CRH&=0X00000000; //PB???ì????
GPIOB->CRH|=0X33333333;
GPIOB->CRL&=0X00000000;
GPIOB->CRL|=0X33333333;
GPIOB->ODR=0X00FF;
RCC->APB2ENR|=1<<2; //PC????
GPIOA->CRL&=0XFFFFFF00; //PC3???ì????,PC4????
GPIOA->CRL|=0X00000038;
GPIOA->ODR=0XFFF0;
RCC->APB1ENR|=1<<1;
while(1)
{
Trig=1;
delay_us(30);
Trig=0; //·??????ù?¨
TIM3->CNT=0;
while(Echo==0);
TIM3->CR1=0x01;
while((Echo==1)&&(TIM3->CNT<TIM3->ARR-10));
TIM3->CR1=0x00;
s=((TIM3->CNT)*272);
xianshi_init(s);
}
}
|
|