倒車測距proteus仿真 LCD1602顯示RF04
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機源程序如下:
- #include<reg52.h>
- #include "srf04.h"
- #include "lcd1602.h"
- #include "delay.h"
- uint dis,cnt;
- void main(void)
- {
- uchar i;
- LCD1602_Init();
- SRF04Init();
- delayms(10);
- LCD1602_Display_Str(1,19,"ULTRASONIC");
- LCD1602_Display_Str(2,17,"RANGING SYSTEM!");
- for(i=0;i<16;i++)
- {
- LCD1602_Write_Cmd(0x18);
- delayms(500);
-
- }
- delayms(500);
- LCD1602_ClearScreen();
- delayms(10);
- LCD1602_Display_Str(1,0,"Distance:");
- LCD1602_Display_Str(2,7,"D=");
- LCD1602_Display_Str(2,12,"CM");
- while(1)
- {
- dis=getAverageDistance();
- if(dis<200)
- {
- LCD1602_Display_Num(2,9,dis);
- }
- else
- LCD1602_Display_Str(2,9,"---");
-
- delayms(100);
-
- if(dis<100)
- {beep=0;
- delayms(200);
- beep=~beep;
- }
- }
-
- }
復制代碼
仿真Keil代碼資料51hei附件下載:
倒車測距.rar
(132.27 KB, 下載次數: 31)
2021-11-17 20:57 上傳
點擊文件名下載附件
|