51_LanQiaoBei/模板/蓝桥杯全模块测试例程/DS18B20温度模块/User/Listings/main.lst
2025-04-13 01:02:19 +08:00

157 lines
5.7 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 MAIN 05/02/2024 15:57:33 PAGE 1
C51 COMPILER V9.59.0.0, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN .\Objects\main.obj
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE main.c OPTIMIZE(8,SPEED) BROWSE INCDIR(..\Driver) DEBUG OBJECTEXTEND PRI
-NT(.\Listings\main.lst) TABS(2) OBJECT(.\Objects\main.obj)
line level source
1 #include "main.h"
2 /* LED显示 */
3 uchar ucLed[8] = {0, 0, 0, 0, 0, 0, 0, 0};
4
5 /* 数码管显示 */
6 uchar Seg_Slow_Down; // 数码管减速
7 uchar Seg_Buf[8] = {10, 10, 10, 10, 10, 10, 10, 10}; // 数码管显示的值
8 uchar Seg_Pos; // 数码管指示
9 uchar Seg_Point[8] = {0, 0, 0, 0, 0, 0, 0, 0}; // 某位是否显示小数点
10
11 /* 键盘方面 */
12 uchar Key_Slow_Down;
13
14 /* 数据 */
15 uint temperature_value_10x; // 温度数据
16 bit C_F_flag; // 摄氏度转华氏度
17
18 #define N 10
19 uint data_array[N]; // 窗口大小
20 uint sum_temp; // 总和
21 uchar index_temp; // 计数
22 uchar arr_count; // 数组数据数量
23
24 uint filter(uint new_data)
25 {
26 1 sum_temp -= data_array[index_temp];
27 1 data_array[index_temp] = new_data;
28 1 sum_temp += data_array[index_temp];
29 1 index_temp = (++index_temp) % N; // 保证index_temp在0~N-1之间轮转
30 1 arr_count = (++arr_count == N + 1) ? N : arr_count; // 锁定数组中的元素个数
31 1 return sum_temp / arr_count;
32 1 }
33
34 /* 键盘处理函数 */
35 void Key_Proc()
36 {
37 1 static uchar Key_Val, Key_Down, Key_Up, Key_Old;
38 1 if (Key_Slow_Down)
39 1 return;
40 1 Key_Slow_Down = 1;
41 1
42 1 Key_Val = Key_Read();
43 1 Key_Down = Key_Val & (Key_Old ^ Key_Val);
44 1 Key_Up = ~Key_Val & (Key_Old ^ Key_Val);
45 1 Key_Old = Key_Val;
46 1 if (Key_Down == 4)
47 1 C_F_flag ^= 1;
48 1 }
49 /* 数码管处理函数 */
50 void Seg_Proc()
51 {
52 1 if (Seg_Slow_Down)
53 1 return;
54 1 Seg_Slow_Down = 1;
C51 COMPILER V9.59.0.0 MAIN 05/02/2024 15:57:33 PAGE 2
55 1 temperature_value_10x = filter(rd_temperature() * 10);
56 1 if (C_F_flag)
57 1 temperature_value_10x = temperature_value_10x * 1.8 + 320; // 华氏度
58 1 Seg_Buf[0] = temperature_value_10x / 1000 % 10;
59 1 Seg_Buf[1] = temperature_value_10x / 100 % 10;
60 1 Seg_Buf[2] = temperature_value_10x / 10 % 10;
61 1 Seg_Buf[3] = temperature_value_10x % 10;
62 1 Seg_Buf[4] = (C_F_flag) ? 12 : 11;
63 1 Seg_Point[2] = 1;
64 1 }
65
66 /* LED处理函数 */
67 void Led_Proc()
68 {
69 1 }
70
71 /* 定时器0中断初始化 */
72 void Timer0_Init(void) // 1毫秒@12.000MHz
73 {
74 1 AUXR &= 0x7F; // 定时器时钟12T模式
75 1 TMOD &= 0xF0; // 设置定时器模式
76 1 TL0 = 0x18; // 设置定时初始值
77 1 TH0 = 0xFC; // 设置定时初始值
78 1 TF0 = 0; // 清除TF0标志
79 1 TR0 = 1; // 定时器0开始计时
80 1 ET0 = 1;
81 1 EA = 1;
82 1 }
83
84 /* 定时器0中断函数 */
85 void Timer0_ISR(void) interrupt 1
86 {
87 1 if (++Key_Slow_Down == 10)
88 1 Key_Slow_Down = 0;
89 1 if (++Seg_Slow_Down == 500)
90 1 Seg_Slow_Down = 0;
91 1 if (++Seg_Pos == 8)
92 1 Seg_Pos = 0;
93 1 Seg_Disp(Seg_Pos, Seg_Buf[Seg_Pos], Seg_Point[Seg_Pos]);
94 1 Led_Disp(Seg_Pos, ucLed[Seg_Pos]);
95 1 }
96
97 void Delay750ms(void) //@12.000MHz
98 {
99 1 unsigned char data i, j, k;
100 1
101 1 _nop_();
102 1 _nop_();
103 1 i = 35;
104 1 j = 51;
105 1 k = 182;
106 1 do
107 1 {
108 2 do
109 2 {
110 3 while (--k)
111 3 ;
112 3 } while (--j);
113 2 } while (--i);
114 1 }
115
116 void main()
C51 COMPILER V9.59.0.0 MAIN 05/02/2024 15:57:33 PAGE 3
117 {
118 1 System_Init();
119 1 Timer0_Init();
120 1 rd_temperature();
121 1 Delay750ms();
122 1 while (1)
123 1 {
124 2 Key_Proc();
125 2 Seg_Proc();
126 2 Led_Proc();
127 2 }
128 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 477 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 57 ----
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)