51_LanQiaoBei/模板/蓝桥杯全模块测试例程/DS1302时钟模块/User/Listings/Ultrasonic.lst
2025-04-13 01:02:19 +08:00

82 lines
2.6 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

C51 COMPILER V9.59.0.0 ULTRASONIC 02/24/2024 21:37:53 PAGE 1
C51 COMPILER V9.59.0.0, COMPILATION OF MODULE ULTRASONIC
OBJECT MODULE PLACED IN .\Objects\Ultrasonic.obj
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE ..\Driver\Ultrasonic.c OPTIMIZE(8,SPEED) BROWSE INCDIR(..\Driver) DEBUG
-OBJECTEXTEND PRINT(.\Listings\Ultrasonic.lst) TABS(2) OBJECT(.\Objects\Ultrasonic.obj)
line level source
1 #include "Ultrasonic.h"
2 #include "intrins.h"
3
4 sbit Tx = P1 ^ 0;
5 sbit Rx = P1 ^ 1;
6 void Delay12us(void) //@12.000MHz
7 {
8 1 unsigned char data i;
9 1
10 1 _nop_();
11 1 _nop_();
12 1 i = 33;
13 1 while (--i)
14 1 ;
15 1 }
16
17 void Ut_Wave_Init()
18 {
19 1 unsigned char i;
20 1 // 发送8个40kHz的方波
21 1 // f=40kHz->T=1/f=0.000025s=25us
22 1 // 12.5us 1 12.5us 0
23 1 for (i = 0; i < 8; i++)
24 1 {
25 2 Tx = 1;
26 2 Delay12us();
27 2 Tx = 0;
28 2 Delay12us();
29 2 }
30 1 }
31
32 unsigned char Ut_Wave_Data()
33 {
34 1 unsigned int time;
35 1 TMOD &= 0x0f;
36 1 TH1 = TL1 = 0;
37 1 Ut_Wave_Init();
38 1 TR1 = 1;
39 1 while ((Rx == 1) && (TF1 == 0))
40 1 ; // 数据读取未结束,并且没有溢出
41 1 TR1 = 0;
42 1 // 没有溢出,数据读取结束
43 1 if (TF1 == 0)
44 1 {
45 2 time = TH1 << 8 | TL1; // 单位为毫秒
46 2 // L=V*T/2
47 2 return (time * 0.017); // 返回的单位是cm
48 2 }
49 1 // 数据溢出,认定此次测量无效
50 1 else
51 1 {
52 2 TF1 = 0;
53 2 return 0;
54 2 }
C51 COMPILER V9.59.0.0 ULTRASONIC 02/24/2024 21:37:53 PAGE 2
55 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 90 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)