初级会员

- 积分
- 113
- 金钱
- 113
- 注册时间
- 2014-4-17
- 在线时间
- 4 小时
|
5金钱
不知道为什么数据值总是显示38, 不会变化,不知道哪里出问题了。
#include <stm32f10x_lib.h>
#include "usart.h"
#include "12864.h"
#include "delay.h"
#include "sys.h"
#include "led.h"
#include "timer.h"
u16 TIM,S;
u8 bai,shi,ge;
int main(void)
{
Stm32_Clock_Init(9);//系统时钟设置
delay_init(72); //延时初始化
uart_init(72,9600); //串口1初始化
IO_Init();
LED_Init();
init();
//timerx_Init(4999,7199);
while(1)
{
timerx_Init(4999,7199);
TRIG_TX=1;
delay_us(25);
TRIG_TX=0;
TIM3->CNT=0;
TIM3->CR1|=0x01;
while(ECHO_RX);
TIM=TIM3->CNT;
TIM3->CR1|=~0x01;
S=TIM;
bai=S/100%10;
shi=S/10;
ge =S%10;
write_com(0x83);
write_data(0x30+bai);
write_data(0x30+shi);
write_data(0x30+ge);
write_data(0x60+11);
write_data(0x60+13);
write_data(0x20+15);
write_data(0x60+8);
delay_ms(70);
}
}
#include "timer.h"
#include "led.h"
#include "12864.h"
#include "delay.h"
void timerx_Init(u16 arr,u16 psc)
{
RCC->APB1ENR|=1<<1; //使能时钟3
TIM3->ARR=arr;
TIM3-> SC=psc;
TIM3->DIER|=1<<0;
TIM3->DIER|=1<<6;
}
#include <stm32f10x_map.h>
#include <stm32f10x_nvic.h>
#include "led.h"
void LED_Init(void)
{
RCC->APB2ENR|=1<<2; //使能PORTA时钟
GPIOA->CRH&=0XF00FFFFF;
GPIOA->CRH|=0X08300000; //A13为输出 A14为输入
GPIOA->ODR|=1<<14;
}
#ifndef __LED_H
#define __LED_H
#include "sys.h"
#define LED0 PAout(8)// PD2
#define TRIG_TX PAout(13)
#define ECHO_RX PAin(14)
void LED_Init(void);//初始化
#endif
|
|