📄 calculator.lst
字号:
177 5
178 5 Frist=0;Second=0;Result=0; //清零
C51 COMPILER V7.50 CALCULATOR 04/09/2007 18:39:43 PAGE 4
179 5 }
180 4 }break; //end case EQUAL
181 3 case ADD: //如果是加减乘除键按下
182 3 case DEC:
183 3 case MUL:
184 3 case DIV: if(Flag_operand_A_NoEmpty==1) //如果前面没有操作数,就不理会
185 3 {
186 4 //如果是第一次 运算符按下
187 4 if(Flag_operator_FristTime==1)
188 4 {
189 5 operator=Key_temp; //保存按键值
190 5 Flag_operator_FristTime=0; //有运算符按下了
191 5 Flag_Number_FristTime=1; //有操作数按下了
192 5 Bit_Number=0; //位计算清零
193 5 Flag_operand_A_NoEmpty=1; //操作数A 不为空
194 5 LCD_write_char(9,1,operator);
195 5 }
196 4 else //如果不是第一次按下运算符,则运算一次
197 4 { if(Flag_operand_B_NoEmpty==1) //如果操作数B 不为空
198 5 {
199 6 switch(operator) //根据前一次的运算符进行计算
200 6 {
201 7 case ADD: Result=Frist+Second;break; //加
202 7 case DEC: if(Frist>=Second) //减
203 7 {
204 8 Result=Frist-Second;
205 8 }
206 7 else
207 7 {
208 8 Key_temp=' '; //运算符清零
209 8 /* operator=operator_Emputy; //运算符初始化
210 8 Flag_operand_B_NoEmpty=0; //操作数B 为空
211 8 Flag_operand_A_NoEmpty=0; //操作数A 为空
212 8 Flag_operator_FristTime=0;//无运算符按下
213 8 Flag_Number_FristTime=0; //无操作数按下
214 8 operand_A[0]=0;operand_A[1]=0;operand_A[2]=0;operand_A[3]=0;operand_A[4]=0;
215 8 operand_B[0]=0;operand_B[1]=0;operand_B[2]=0;operand_B[3]=0;operand_B[4]=0;
216 8 Bit_Number=0; */
217 8 Clear_All_Flag_Init();
218 8 Frist=0;Second=0;Result=0;
219 8 }
220 7 break;
221 7 case MUL: Result=Frist*Second;break; //乘
222 7 case DIV: Result=Frist/Second;break; //除
223 7 default:break;
224 7 }
225 6
226 6 Bit_Number=0; //位计数清零
227 6 Frist=Result; //结果
228 6 Second=0;operand_B[0]=0;operand_B[1]=0;operand_B[2]=0;operand_B[3]=0;operand_B[4]=0;
229 6 operator=Key_temp; //显示按下的运算符
230 6 LCD_write_char(9,1,operator);
231 6 Flag_operand_B_NoEmpty=0; //操作数B 为空
232 6 //Flag_operand_A_NoEmpty=1; //操作数A 不为空
233 6 // Flag_Number_FristTime=1; //有操作数按下
234 6 if(operand_B[4]>=6)
235 6 {
236 7 The_Number_Too_Large();
237 7 }
238 6 else
239 6 {
240 7 if(Frist>0)
C51 COMPILER V7.50 CALCULATOR 04/09/2007 18:39:43 PAGE 5
241 7 { Display_Ram[4]=(Frist%10)+0x30;
242 8 if(Frist>=10)
243 8 {
244 9 Display_Ram[3]=(Frist%100)/10+0x30;
245 9 if(Frist>=100)
246 9 {
247 10 Display_Ram[2]=(Frist%1000)/100+0x30;
248 10 if(Frist>=1000)
249 10 {
250 11 Display_Ram[1]=(Frist%10000)/1000+0x30;
251 11 if(Frist>=10000)
252 11 {
253 12 Display_Ram[0]=(Frist/10000)+0x30;
254 12 }
255 11 else
256 11 {
257 12 Display_Ram[0]=' ';
258 12 }
259 11 }
260 10 else
261 10 {
262 11 Display_Ram[0]=' ';Display_Ram[1]=' ';
263 11 }
264 10 }
265 9 else
266 9 {
267 10 Display_Ram[0]=' ';Display_Ram[1]=' ';Display_Ram[2]=' ';
268 10 }
269 9 }
270 8 else
271 8 {
272 9 Display_Ram[0]=' ';Display_Ram[1]=' ';Display_Ram[2]=' ';Display_Ram[3]=' ';
273 9 }
274 8 }
275 7 else{
276 8 Display_Ram[0]=' ';Display_Ram[1]=' ';Display_Ram[2]=' ';Display_Ram[3]=' ';Display_Ram[4]='0
-';
277 8
278 8 }
279 7 p_Display_Ram=Display_Ram; //指向显示缓冲单元
280 7 LCD_disp_string(11,1,p_Display_Ram);
281 7 }
282 6 }// end if Flag_operand_B_NoEmpty
283 5 }//end else if lag_operator_FristTime
284 4 }// end if Flag_operand_A_NoEmpty
285 3 break;
286 3 default: if(Bit_Number==0&&Key_temp==0) //如果是数字键按下,而且是第一次0按键按下 清零
287 3 {
288 4 //clear
289 4 Clear_All_Flag_Init();
290 4 /* operator=operator_Emputy; //运算符初始化
291 4 Flag_operand_B_NoEmpty=0; //操作数B 为空
292 4 Flag_operand_A_NoEmpty=0; //操作数A 为空
293 4 Flag_operator_FristTime=0; //无运算符按下
294 4 Flag_Number_FristTime=0; //无操作数按下
295 4 operand_A[0]=0;operand_A[1]=0;operand_A[2]=0;operand_A[3]=0;operand_A[4]=0;
296 4 operand_B[0]=0;operand_B[1]=0;operand_B[2]=0;operand_B[3]=0;operand_B[4]=0;
297 4 Bit_Number=0; */ //位计数清零
298 4 //display(); clear line 2
299 4 p_string_code=string_clear_line2; //清屏 全部写入空格
300 4 LCD_disp_string(0,1,p_string_code);
301 4 LCD_write_char(15,1,'0'); // clear 清零
C51 COMPILER V7.50 CALCULATOR 04/09/2007 18:39:43 PAGE 6
302 4
303 4 }
304 3 else{ //如果是数字键按下
305 4 if(Flag_Number_FristTime==0) //如果是第一次的操作数
306 4 {
307 5 if(Bit_Number<5) //如果按下的操作数位数小于等于 5
308 5 {
309 6 //operand_A[Bit_Number++]=Key_temp;
310 6 switch(Bit_Number) //根据位数处理按键
311 6 {
312 7 case 0: operand_A[0]=Key_temp;break;
313 7 case 1: operand_A[1]=operand_A[0];operand_A[0]=Key_temp;break;
314 7 case 2: operand_A[2]=operand_A[1];operand_A[1]=operand_A[0];operand_A[0]=Key_temp;
-break;
315 7 case 3: operand_A[3]=operand_A[2];operand_A[2]=operand_A[1];operand_A[1]=operand_A[0];operand_A[0]=K
-ey_temp;break;
316 7 case 4: operand_A[4]=operand_A[3];operand_A[3]=operand_A[2];operand_A[2]=operand_A[1];operand_A[1]=o
-perand_A[0];operand_A[0]=Key_temp;break;
317 7 default: Bit_Number=0;
318 7 }
319 6 Bit_Number++; //位计数加1
320 6 Frist=operand_A[0]+operand_A[1]*10+operand_A[2]*100+operand_A[3]*1000+operand_A[4]*1000
-0;
321 6 //运算
322 6 if(operand_A[4]>=6)
323 6 {
324 7 The_Number_Too_Large();
325 7 }
326 6 else
327 6 {
328 7 Flag_operand_A_NoEmpty=1; //操作数A 不为空
329 7 Flag_operator_FristTime=1; //没有运算符按下
330 7 //display(); clear line 2
331 7 p_string_code=string_clear_line2; //清空LCD
332 7 LCD_disp_string(0,1,p_string_code);
333 7 if(Frist>0)
334 7 { Display_Ram[4]=(Frist%10)+0x30;
335 8 if(Frist>=10)
336 8 {
337 9 Display_Ram[3]=(Frist%100)/10+0x30;
338 9 if(Frist>=100)
339 9 {
340 10 Display_Ram[2]=(Frist%1000)/100+0x30;
341 10 if(Frist>=1000)
342 10 {
343 11 Display_Ram[1]=(Frist%10000)/1000+0x30;
344 11 if(Frist>=10000)
345 11 {
346 12 Display_Ram[0]=(Frist/10000)+0x30;
347 12 }
348 11 else
349 11 {
350 12 Display_Ram[0]=' ';
351 12 }
352 11 }
353 10 else
354 10 {
355 11 Display_Ram[0]=' ';Display_Ram[1]=' ';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -