因?yàn)槔蠋熥屪鲞@個課程設(shè)計,所以我把做好的東西發(fā)到這分享給大家。
測距用的是夏普的GP2Y0A。屏幕用的是OLED顯示屏。
單片機(jī)源程序如下:
- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "oled.h"
- #include "adc.h"
- #include "led.h"
- extern u8 nonside[];
- int main(void)
- {
- u16 adcx;u8 display[8];
- delay_init();
- LED_Init();
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- uart_init(115200);
- OLED_Init();
- Adc_Init();
- LCD_Print(15, 0, "GYJ16481314",TYPE16X16,TYPE8X16);
- LCD_Print(0, 16, "Infrared距離",TYPE16X16,TYPE8X16);
- Draw_BMP(32,48,nonside);
- Draw_BMP(48,48,nonside);
- Draw_BMP(64,48,nonside);
- while(1)
- {
-
-
- adcx=Get_Adc_Average(ADC_Channel_11,10);
- if (adcx>472&&adcx<=558)
- {
- display[0]='8';
- display[1]='0';
- display[3]='c';
- display[4]='m';
- LCD_Print(40, 32, display,TYPE16X16,TYPE6X8);
- }
- else if (adcx>558&&adcx<=620)
- {
- LCD_Print(40, 32, "70cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>620&&adcx<=730)
- {
- LCD_Print(40, 32, "60cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>730&&adcx<=807)
- {
- LCD_Print(40, 32, "50cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>807&&adcx<=992)
- {
- LCD_Print(40, 32, "40cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>992&&adcx<=1303)
- {
- LCD_Print(40, 32, "30cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>1303&&adcx<=1551)
- {
- LCD_Print(40, 32, "25cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>1551&&adcx<=1861)
- {
- LCD_Print(40, 32, "20cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>1861&&adcx<=2419)
- {
- LCD_Print(40, 32, "15cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>2419&&adcx<=3102)
- {
- LCD_Print(40, 32, "10cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>3102&&adcx<=3660)
- {
- LCD_Print(40, 32, "8cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>3660&&adcx<=3784)
- {
- LCD_Print(40, 32, "7cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>3784&&adcx<=3908)
- {
- LCD_Print(40, 32, "5cm",TYPE16X16,TYPE6X8);
- }
- else if (adcx>3908&&adcx<=4095)
- {
- LCD_Print(40, 32, "6cm",TYPE16X16,TYPE6X8);
- }
- if(adcx>1551) GPIO_ResetBits(GPIOA,GPIO_Pin_8);
- else GPIO_SetBits(GPIOA,GPIO_Pin_8);
- delay_ms(10);
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
紅外測距.rar
(288.68 KB, 下載次數(shù): 73)
2018-12-26 12:32 上傳
點(diǎn)擊文件名下載附件
這是用OLED顯示的測距,顯示的東西可以修改,不會的可以問我 下載積分: 黑幣 -5
|