main.lst
来自「手把手教你单片机」· LST 代码 · 共 542 行 · 第 1/2 页
LST
542 行
C51 COMPILER V7.08 MAIN 12/21/2010 08:24:33 PAGE 1
C51 COMPILER V7.08, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 * Easy calculator
3 *
4 * K4:+ K8:- K12:* K16:/ K14:CE K15:=
5 *
6 * Made by Kingst-刚哥
7 * date: 2010.12.21
8 */
9
10 #include <reg52.h>
11
12 typedef unsigned char uint8;
13 typedef unsigned int uint16;
14 typedef unsigned long uint32;
15 typedef char int8;
16 typedef int int16;
17 typedef long int32;
18
19 sbit KeyIn1 = P2^4;
20 sbit KeyIn2 = P2^5;
21 sbit KeyIn3 = P2^6;
22 sbit KeyIn4 = P2^7;
23 sbit KeyOut1 = P2^3;
24 sbit KeyOut2 = P2^2;
25 sbit KeyOut3 = P2^1;
26 sbit KeyOut4 = P2^0;
27 sbit ADDR0 = P1^0;
28 sbit ADDR1 = P1^1;
29 sbit ADDR2 = P1^2;
30 sbit ADDR3 = P1^3;
31 sbit ENLED = P1^4;
32 sbit BUZZ = P1^6;
33
34 #define FADD 10
35 #define FSUB 11
36 #define FMUL 12
37 #define FDIV 13
38 #define FRES 14
39 #define FEQU 15
40
41 #define KEY_DELAY 300
42 #define BUZ_DELAY 80
43
44 code uint8 Ledcode[13]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf,0x86};
45 uint8 Led_n=0;
46 uint8 Led_buf[6];
47 float Tmp1=0, Tmp2=0;
48 int8 C_flag=0;
49
50 /*
51 * 延时
52 */
53 void delay(uint16 n)
54 {
55 1 while (n--);
C51 COMPILER V7.08 MAIN 12/21/2010 08:24:33 PAGE 2
56 1 }
57
58 /*
59 * 蜂鸣器发声
60 */
61 void buzzer_sound(void)
62 {
63 1 uint16 i;
64 1
65 1 for (i=0; i<BUZ_DELAY; i++)
66 1 {
67 2 BUZZ = ~BUZZ;
68 2 delay(100);
69 2 }
70 1
71 1 BUZZ = 1;
72 1 }
73
74 /*
75 * 按键扫描
76 */
77 int8 scan_key(void)
78 {
79 1 int8 val=-1;
80 1
81 1 KeyOut1 = 0;
82 1 KeyOut2 = 1;
83 1 KeyOut3 = 1;
84 1 KeyOut4 = 1;
85 1 if (KeyIn1 == 0)
86 1 {
87 2 delay(KEY_DELAY);
88 2 if (KeyIn1 == 0)
89 2 val = 1;
90 2 }
91 1 if (KeyIn2 == 0)
92 1 {
93 2 delay(KEY_DELAY);
94 2 if (KeyIn2 == 0)
95 2 val = 2;
96 2 }
97 1 if (KeyIn3 == 0)
98 1 {
99 2 delay(KEY_DELAY);
100 2 if (KeyIn3 == 0)
101 2 val = 3;
102 2 }
103 1 if (KeyIn4 == 0)
104 1 {
105 2 delay(KEY_DELAY);
106 2 if (KeyIn4 == 0)
107 2 val = FADD;
108 2 }
109 1 while ((KeyIn1 == 0)||(KeyIn2 == 0)||(KeyIn3 == 0)||(KeyIn4 == 0));
110 1
111 1 KeyOut1 = 1;
112 1 KeyOut2 = 0;
113 1 KeyOut3 = 1;
114 1 KeyOut4 = 1;
115 1 if (KeyIn1 == 0)
116 1 {
117 2 delay(KEY_DELAY);
C51 COMPILER V7.08 MAIN 12/21/2010 08:24:33 PAGE 3
118 2 if (KeyIn1 == 0)
119 2 val = 4;
120 2 }
121 1 if (KeyIn2 == 0)
122 1 {
123 2 delay(KEY_DELAY);
124 2 if (KeyIn2 == 0)
125 2 val = 5;
126 2 }
127 1 if (KeyIn3 == 0)
128 1 {
129 2 delay(KEY_DELAY);
130 2 if (KeyIn3 == 0)
131 2 val = 6;
132 2 }
133 1 if (KeyIn4 == 0)
134 1 {
135 2 delay(KEY_DELAY);
136 2 if (KeyIn4 == 0)
137 2 val = FSUB;
138 2 }
139 1 while ((KeyIn1 == 0)||(KeyIn2 == 0)||(KeyIn3 == 0)||(KeyIn4 == 0));
140 1
141 1 KeyOut1 = 1;
142 1 KeyOut2 = 1;
143 1 KeyOut3 = 0;
144 1 KeyOut4 = 1;
145 1 if (KeyIn1 == 0)
146 1 {
147 2 delay(KEY_DELAY);
148 2 if (KeyIn1 == 0)
149 2 val = 7;
150 2 }
151 1 if (KeyIn2 == 0)
152 1 {
153 2 delay(KEY_DELAY);
154 2 if (KeyIn2 == 0)
155 2 val = 8;
156 2 }
157 1 if (KeyIn3 == 0)
158 1 {
159 2 delay(KEY_DELAY);
160 2 if (KeyIn3 == 0)
161 2 val = 9;
162 2 }
163 1 if (KeyIn4 == 0)
164 1 {
165 2 delay(KEY_DELAY);
166 2 if (KeyIn4 == 0)
167 2 val = FMUL;
168 2 }
169 1 while ((KeyIn1 == 0)||(KeyIn2 == 0)||(KeyIn3 == 0)||(KeyIn4 == 0));
170 1
171 1 KeyOut1 = 1;
172 1 KeyOut2 = 1;
173 1 KeyOut3 = 1;
174 1 KeyOut4 = 0;
175 1 if (KeyIn1 == 0)
176 1 {
177 2 delay(KEY_DELAY);
178 2 if (KeyIn1 == 0)
179 2 val = 0;
C51 COMPILER V7.08 MAIN 12/21/2010 08:24:33 PAGE 4
180 2 }
181 1 if (KeyIn2 == 0)
182 1 {
183 2 delay(KEY_DELAY);
184 2 if (KeyIn2 == 0)
185 2 val = FRES;
186 2 }
187 1 if (KeyIn3 == 0)
188 1 {
189 2 delay(KEY_DELAY);
190 2 if (KeyIn3 == 0)
191 2 val = FEQU;
192 2 }
193 1 if (KeyIn4 == 0)
194 1 {
195 2 delay(KEY_DELAY);
196 2 if (KeyIn4 == 0)
197 2 val = FDIV;
198 2 }
199 1 while ((KeyIn1 == 0)||(KeyIn2 == 0)||(KeyIn3 == 0)||(KeyIn4 == 0));
200 1
201 1 if (val > 0)
202 1 buzzer_sound();
203 1
204 1 return val;
205 1 }
206
207 /*
208 * 验证数据有效性
209 */
210 bit check_num(float f_num)
211 {
212 1 if (f_num >= 100000)
213 1 return 1;
214 1
215 1 return 0;
216 1 }
217
218 /*
219 * 制作数码管错误标志
220 */
221 void make_led_error(void)
222 {
223 1 int8 i;
224 1
225 1 for (i=0; i<5; i++)
226 1 Led_buf[i] = Ledcode[10];
227 1 Led_buf[5] = Ledcode[12];
228 1 }
229
230 /*
231 * 制作数码管整数数据
232 */
233 void make_led_inumber(int32 i_num)
234 {
235 1 bit s_flag=0;
236 1 int16 sit;
237 1 int8 i;
238 1
239 1 if (i_num < 0)
240 1 {
241 2 s_flag = 1;
C51 COMPILER V7.08 MAIN 12/21/2010 08:24:33 PAGE 5
242 2 i_num = -i_num;
243 2 }
244 1
245 1 ET0 = 0;
246 1 for (i=4, sit=10000; i>=1; i--, sit/=10)
247 1 {
248 2 if (i_num >= sit)
249 2 break;
250 2 Led_buf[i] = Ledcode[10];
251 2 i_num -= i_num/sit*sit;
252 2 }
253 1 for (;i>=1; i--, sit/=10)
254 1 {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?