单片机源程序如下:
- #include<reg52.h>
- #include"lcd1602.h"
- uint dis,cnt;
- main()
- {
- 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);
-
- }
- //while(1);
- delayms(5000);
- 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<300)
- {
- LCD1602_Display_Num(2,9,dis);
-
- }
- else
- LCD1602_Display_Str(2,9,"---");
- if(dis<30)
- {
- deep=0;
- }else deep=1;
- //LCD1602_Display_Num(2,11,getTemperature());
- delayms(100);
- //while(1);
- }
- }
复制代码
所有资料51hei提供下载:
|