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