标题: stm32f1超声波测距+LCD显示代码 [打印本页]

作者: 李清波8    时间: 2019-1-2 16:11
标题: stm32f1超声波测距+LCD显示代码
单片机源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "usart.h"
  6. #include "exti.h"
  7. #include "beep.h"
  8. #include "timer.h"
  9. #include "wave.h"
  10. #include "sys.h"
  11. #include "lcd.h"
  12. #include "sg.h"
  13. u16 num,l=0,h=0;

  14. void kongzhi()
  15. {
  16.         if(h>=2)
  17.         {
  18.                 sg=1;delay_ms(1);
  19.                 sg=0;delay_ms(1);
  20.                
  21.         }       
  22.         else if(h<1)
  23.         {
  24.                 sg=0;delay_ms(1);
  25.                 sg=1;delay_ms(1);
  26.         }
  27. }
  28. int main(void)
  29. {               

  30.         delay_init();                     //延时函数初始化          
  31.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
  32.         uart_init(115200);         //串口初始化为115200
  33.         LED_Init();                                  //初始化与LED连接的硬件接口
  34.         BEEP_Init();                 //初始化蜂鸣器端口
  35.         KEY_Init();                 //初始化与按键连接的硬件接口
  36.         LCD_Init();
  37.         //EXTIX_Init();                         //外部中断初始化
  38.         //LED0=0;                                        //点亮LED0
  39.         Timer_SRD_Init(5000,7199);
  40.         Wave_SRD_Init();
  41.         LCD_Clear(WHITE);//清屏函数
  42.         while(1)
  43.         {            
  44.                 h=num/10000;
  45.                 l=num/100%100;
  46.                 LCD_ShowxNum(0,12,h,1,16,1);//显示数值
  47.                 LCD_ShowChar(9,12,0x2e,16,0);
  48.                 LCD_ShowxNum(12,12,l,2,16,1);//显示数值
  49.                 LCD_ShowString(30,12,12,12,16,"m");
  50.     LED1=!LED1;
  51.                 delay_ms(200);
  52.                 sg=0;
  53.                 kongzhi();
  54.                 LCD_Clear(WHITE);//清屏函数
  55.                 Wave_SRD_Strat();       
  56.                 num=EXTI9_5_IRQHandler();//读取数值
  57.         }
  58. }
复制代码

全部资料51hei下载地址:
超声波模块程序_STM32F103ZET6.7z (228.32 KB, 下载次数: 104)


stm32_F1 超声波加LCD.rar

3.39 MB, 下载次数: , 下载积分: 黑币 -5

stm32f1超声波测距LCD显示


作者: 孟榜鑫    时间: 2019-3-31 15:26
能用吗

作者: 环环紧扣    时间: 2020-3-3 11:12
需要用到,麻烦了




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1