本帖最后由 liuchenzhouyan 于 2015-8-2 17:55 编辑
#include "sys.h"
#include "usart.h"
#include "delay.h"
#include "ex
ti.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;
GPIOB->CRH&=0X00000000
GPIOB->CRH|=0X33333333;
GPIOB->CRL&=0X00000000;
GPIOB->CRL|=0X33333333;
GPIOB->ODR=0X00FF;
RCC->APB2ENR|=1<<2;
GPIOA->CRL&=0XFFFFFF00;
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);
}
}
一周热门 更多>