|
之前才学完51单片机是开始练习一些模块用的是SFR05超声波模块
以下源码- #include <REGX52.H>
- #include "LCD1602.h
- #include "Delay.h
- #include "Timer0.h
- unsigned char Distance;
- unsigned char i;
- unsigned int T;
- unsigned int T0Count;
- unsigned char Time;
- unsigned int a,b;
- sbit Trig = P2^0
- sbit Echo = P2^1;
- void Super_Wave_Init()
- {
- Trig = 0;
- Echo = 0;
- }
- void Distance_Init()
- {
- a=(TH0*256+TL0);
- // T=T-0x66fc;
- b=(a);
- T= b/46.3
- }
- void main()
- {
- LCD_Init();
- Timer0Init()
- LCD_ShowString(1,1,"Distance:");
- LCD_ShowString(2,6,"CM");
- while(1)
- {
- Trig=1;
- i = 4;
- while (--i)
- Trig=0;
- while(Echo==0)
- TR0=1;
- while(Echo);
- TR0=0;
- Distance_Init();
- LCD_ShowNum(2,1,T,5);
- Delay(250);
- TL0 = 0
- TH0 = 0;
- // Delay(20);
- Super_Wave_Init();
-
-
- }
- }
- void Timer0_Routine() interrupt 1
- {
- // TL0 = 0
-
- T0Count++;
- if(T0Count==18)
- {
- TR0 = 0;
- // TL0 = 0x66;
- // TH0 = 0xfc;
复制代码
|
-
这是其中包含的一些头文件
-
-
超声波测距.zip
41.93 KB, 下载次数: 18, 下载积分: 黑币 -5
评分
-
查看全部评分
|