找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5394|回復(fù): 6
收起左側(cè)

基于GP2Y0A+ST32F103RCT6的紅外測距程序分享

[復(fù)制鏈接]
ID:455103 發(fā)表于 2018-12-26 09:35 | 顯示全部樓層 |閱讀模式
因為老師讓做這個課程設(shè)計,所以我把做好的東西發(fā)到這分享給大家。
測距用的是夏普的GP2Y0A。屏幕用的是OLED顯示屏。

單片機源程序如下:
  1. #include "sys.h"
  2. #include "delay.h"
  3. #include "usart.h"
  4. #include "oled.h"
  5. #include "adc.h"
  6. #include "led.h"

  7. extern u8 nonside[];

  8. int main(void)
  9. {       
  10.         u16 adcx;u8 display[8];
  11.         delay_init();
  12.   LED_Init();         
  13.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  14.         uart_init(115200);       
  15.         OLED_Init();
  16.         Adc_Init();       
  17.   LCD_Print(15, 0, "GYJ16481314",TYPE16X16,TYPE8X16);
  18.         LCD_Print(0, 16, "Infrared距離",TYPE16X16,TYPE8X16);
  19.         Draw_BMP(32,48,nonside);
  20.         Draw_BMP(48,48,nonside);
  21.         Draw_BMP(64,48,nonside);         
  22.         while(1)
  23.         {  
  24.                
  25.                
  26.                 adcx=Get_Adc_Average(ADC_Channel_11,10);
  27.                 if (adcx>472&&adcx<=558)
  28.                 {
  29.                         display[0]='8';
  30.                         display[1]='0';
  31.                         display[3]='c';
  32.                         display[4]='m';
  33.      LCD_Print(40, 32, display,TYPE16X16,TYPE6X8);
  34.                 }
  35.                                 else if (adcx>558&&adcx<=620)
  36.                 {
  37.      LCD_Print(40, 32, "70cm",TYPE16X16,TYPE6X8);
  38.                 }
  39.                                 else if (adcx>620&&adcx<=730)
  40.                 {
  41.      LCD_Print(40, 32, "60cm",TYPE16X16,TYPE6X8);
  42.                 }
  43.                 else if (adcx>730&&adcx<=807)
  44.                 {
  45.      LCD_Print(40, 32, "50cm",TYPE16X16,TYPE6X8);       
  46.                 }
  47.                 else if (adcx>807&&adcx<=992)
  48.                 {
  49.      LCD_Print(40, 32, "40cm",TYPE16X16,TYPE6X8);
  50.                 }
  51.                 else if (adcx>992&&adcx<=1303)
  52.                 {
  53.      LCD_Print(40, 32, "30cm",TYPE16X16,TYPE6X8);
  54.                 }
  55.                 else if (adcx>1303&&adcx<=1551)
  56.                 {
  57.      LCD_Print(40, 32, "25cm",TYPE16X16,TYPE6X8);
  58.                 }
  59.                 else if (adcx>1551&&adcx<=1861)
  60.                 {
  61.      LCD_Print(40, 32, "20cm",TYPE16X16,TYPE6X8);               
  62.                 }
  63.                 else if (adcx>1861&&adcx<=2419)
  64.                 {
  65.     LCD_Print(40, 32, "15cm",TYPE16X16,TYPE6X8);
  66.                 }
  67.                 else if (adcx>2419&&adcx<=3102)
  68.                 {
  69.      LCD_Print(40, 32, "10cm",TYPE16X16,TYPE6X8);
  70.                 }
  71.                 else if (adcx>3102&&adcx<=3660)
  72.                 {
  73.      LCD_Print(40, 32, "8cm",TYPE16X16,TYPE6X8);               
  74.                 }
  75.                 else if (adcx>3660&&adcx<=3784)
  76.                 {
  77.      LCD_Print(40, 32, "7cm",TYPE16X16,TYPE6X8);
  78.                 }
  79.                 else if (adcx>3784&&adcx<=3908)
  80.                 {
  81.      LCD_Print(40, 32, "5cm",TYPE16X16,TYPE6X8);
  82.                 }
  83.                 else if (adcx>3908&&adcx<=4095)
  84.                 {
  85.      LCD_Print(40, 32, "6cm",TYPE16X16,TYPE6X8);
  86.                 }
  87.                 if(adcx>1551)        GPIO_ResetBits(GPIOA,GPIO_Pin_8);
  88.                 else GPIO_SetBits(GPIOA,GPIO_Pin_8);
  89.                 delay_ms(10);
  90.         }
  91. }
復(fù)制代碼

所有資料51hei提供下載:
紅外測距.rar (288.68 KB, 下載次數(shù): 73)


評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

相關(guān)帖子

回復(fù)

使用道具 舉報

ID:357733 發(fā)表于 2019-2-7 22:09 | 顯示全部樓層
感謝樓主的資源
回復(fù)

使用道具 舉報

ID:467500 發(fā)表于 2019-2-25 19:35 | 顯示全部樓層
感謝樓主的分享
回復(fù)

使用道具 舉報

ID:467500 發(fā)表于 2019-2-25 19:39 | 顯示全部樓層
感謝樓主
回復(fù)

使用道具 舉報

ID:430308 發(fā)表于 2019-7-20 15:45 | 顯示全部樓層
多謝樓主
回復(fù)

使用道具 舉報

ID:650030 發(fā)表于 2019-12-5 17:13 | 顯示全部樓層
這個是怎樣實現(xiàn)測距的呢?比如距離到一定值之后單片機會有什么反應(yīng)?
回復(fù)

使用道具 舉報

ID:657963 發(fā)表于 2019-12-8 13:57 來自觸屏版 | 顯示全部樓層
樓主你是用正點原子迷你版做的嗎
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表