OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3900|回复: 4

关于stm32和超声波传感器之间的事

[复制链接]

2

主题

6

帖子

0

精华

新手上路

积分
22
金钱
22
注册时间
2016-4-25
在线时间
4 小时
发表于 2016-5-12 14:11:43 | 显示全部楼层 |阅读模式
10金钱
这是改写的程序,原本要求是  需要将采集的数据(电脉冲信号)进行ad转换,然后再通过串口发出。现在似乎功能并没有实现   大神们  看看 哪里有错呢  急求!!!!!!!!!!!!!!

#include "led.h"
#include "delay.h"
#include "sys.h"
#include "key.h"
#include "usart.h"
#include "wdg.h"
#include "timer.h"
#include "pwm.h"
#include "lcd.h"
#include "adc.h"
#pragma diag_suppress 870
//ALIENTEK Mini STM32开发板范例代码13
//ADC 实验
//正点原子@ALIENTEK
//技术论坛:www.openedv.com

int main(void)
{
        u8 t;
        u8 len;       
        u16 times=0;
        u16 adcx;
        float temp;
        SystemInit();
        delay_init(72);             //延时初始化
        NVIC_Configuration();
        uart_init(11520);
        LED_Init();
        KEY_Init();
        LCD_Init();
        Adc_Init();      
        while(1)
        {
                adcx=Get_Adc(ADC_Channel_0);
                LCD_ShowNum(156,130,adcx,4,16);//显示ADC的值
                temp=(float)adcx*(3.3/4096);
                adcx=temp;
                LCD_ShowNum(156,150,adcx,1,16);//显示电压值
                temp-=adcx;
                temp*=1000;
                LCD_ShowNum(172,150,temp,3,16);
                printf("adc=%.3fV\r\n",temp);
                LED0=!LED0;
                delay_ms(250);
                         if(USART_RX_STA&0x80)
                {                                          
                        len=USART_RX_STA&0x3f;//得到此次接收到的数据长度
                        printf("\r\n您发送的消息为:\r\n");
                        for(t=0;t<len;t++)
                        {
                                USART1->DR=USART_RX_BUF[t];
                                while((USART1->SR&0X40)==0);//等待发送结束
                        }
                        printf("\n\n");//插入换行
                        USART_RX_STA=0;
                }else
                {
                        times++;
                        if(times%5000==0)
                        {
                                printf("\r\nMiniSTM32开发板 串口实验\r\n");
                                printf("正点原子@ALIENTEK\r\n\r\n\r\n");
                        }
                        if(times%200==0)printf("请输入数据,以回车键结束\r\n");  
                        if(times%30==0)LED0=!LED0;//闪烁LED,提示系统正在运行.
                        delay_ms(10);   
                }
        }         
        }


正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

2

主题

6

帖子

0

精华

新手上路

积分
22
金钱
22
注册时间
2016-4-25
在线时间
4 小时
 楼主| 发表于 2016-5-12 14:14:54 | 显示全部楼层
回复

使用道具 举报

2

主题

6

帖子

0

精华

新手上路

积分
22
金钱
22
注册时间
2016-4-25
在线时间
4 小时
 楼主| 发表于 2016-5-12 14:34:34 | 显示全部楼层
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "key.h"
#include "usart.h"
#include "wdg.h"
#include "timer.h"
#include "pwm.h"
#include "lcd.h"
#include "adc.h"
#pragma diag_suppress 870

int main(void)
{
       
        u16 adcx;
        float temp;
        SystemInit();
        delay_init(72);             //延时初始化
        NVIC_Configuration();
        uart_init(11520);
        LED_Init();                //LED端口初始化
        KEY_Init();                 //按键端口初始化
        Adc_Init();      
        while(1)
        {
                adcx=Get_Adc(ADC_Channel_0);
                temp=(float)adcx*(3.3/4096);
                adcx=temp;
                temp-=adcx;
                temp*=1000;
                printf("adc=%.3fV\r\n",temp);
                LED0=!LED0;
                delay_ms(250);
        }
}
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165536
金钱
165536
注册时间
2010-12-1
在线时间
2117 小时
发表于 2016-5-13 21:17:26 | 显示全部楼层
慢慢调试一下,精简到单一功能测试成功再加其他功能
回复

使用道具 举报

2

主题

6

帖子

0

精华

新手上路

积分
22
金钱
22
注册时间
2016-4-25
在线时间
4 小时
 楼主| 发表于 2016-5-15 14:37:35 | 显示全部楼层
正点原子 发表于 2016-5-13 21:17
慢慢调试一下,精简到单一功能测试成功再加其他功能

能够单一功能实现串口通信,,,,但不知道是否ad转换了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-6-10 19:57

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表