📄 text1.lst
字号:
261 1 delay(100);
262 1 lcd1602_wrcmd(0x01); //清屏
263 1 delay(100);
264 1 }
265
266
267 /************键盘扫描*************/
268 uchar keyscan(void)
269 {
270 1 uchar scancode,tmpcode;
271 1 key_bus = 0xf0;
272 1 if ((key_bus&0xf0)!=0xf0)
273 1 {
274 2 delay(125);
275 2 if ((key_bus&0xf0)!=0xf0)
276 2 {
277 3 scancode = 0xfe;
278 3 while((scancode&0x10)!=0)
279 3 {
280 4 key_bus = scancode;
281 4 if ((key_bus&0xf0)!=0xf0)
282 4 {
283 5 tmpcode = (key_bus&0xf0)|0x0f;
284 5 return((~scancode)+(~tmpcode));
285 5 }
286 4 else scancode = (scancode<<1)|0x01;
287 4 }
288 3 }
289 2 }
290 1 return(0);
291 1 }
292
293
294 void enter0()
295 {
296 1 uchar i;
297 1 state=0;
298 1 lcd1602_clear();
299 1 lcd1602_wrcmd(0x80);
300 1 for(i=0;i<15;i++)
301 1 lcd1602_wrdata(table0[i]);
302 1 }
303
C51 COMPILER V7.20 TEXT1 07/17/2007 07:26:06 PAGE 6
304
305 void enter1()
306 {
307 1 uchar i;
308 1 state=1;
309 1 lcd1602_clear();
310 1 lcd1602_wrcmd(0x80);
311 1 for(i=0;i<14;i++)
312 1 lcd1602_wrdata(table1[i]);
313 1 }
314
315 void enter3()
316 {
317 1 uchar i;
318 1 state=3;
319 1 lcd1602_clear();
320 1 lcd1602_wrcmd(0x80);
321 1 for(i=0;i<3;i++)
322 1 lcd1602_wrdata(table3[i]);
323 1 }
324
325 void measure()
326 {
327 1 uchar i;
328 1 mea=adc_549convert();
329 1 lcd1602_wrcmd(0xc0);
330 1 for(i=0;i<8;i++)
331 1 lcd1602_wrdata(table2[i]);
332 1 }
333
334 void measurebiao()
335 {
336 1 uchar i;
337 1 m[s]=adc_549convert();
338 1 lcd1602_wrcmd(0xc0);
339 1 for(i=0;i<8;i++)
340 1 lcd1602_wrdata(table2[i]);
341 1 lcd1602_wrcmd(0x0f);
342 1 lcd1602_wrcmd(0x83);
343 1 state=4;
344 1 }
345
346
347 void getnum(uchar u)
348 {
349 1 if(u==0x12)
350 1 {
351 2 in[s]=in[s]*10+0;
352 2 lcd1602_wrdata(asc[0]);
353 2 }
354 1 else if(u==0x21)
355 1 {
356 2 in[s]=in[s]*10+1;
357 2 lcd1602_wrdata(asc[1]);
358 2 }
359 1 else if(u==0x22)
360 1 {
361 2 in[s]=in[s]*10+2;
362 2 lcd1602_wrdata(asc[2]);
363 2 }
364 1 else if(u==0x24)
365 1 {
C51 COMPILER V7.20 TEXT1 07/17/2007 07:26:06 PAGE 7
366 2 in[s]=in[s]*10+3;
367 2 lcd1602_wrdata(asc[3]);
368 2 }
369 1 else if(u==0x41)
370 1 {
371 2 in[s]=in[s]*10+4;
372 2 lcd1602_wrdata(asc[4]);
373 2 }
374 1 else if(u==0x42)
375 1 {
376 2 in[s]=in[s]*10+5;
377 2 lcd1602_wrdata(asc[5]);
378 2 }
379 1 else if(u==0x44)
380 1 {
381 2 in[s]=in[s]*10+6;
382 2 lcd1602_wrdata(asc[6]);
383 2 }
384 1 else if(u==0x81)
385 1 {
386 2 in[s]=in[s]*10+7;
387 2 lcd1602_wrdata(asc[7]);
388 2 }
389 1 else if(u==0x82)
390 1 {
391 2 in[s]=in[s]*10+8;
392 2 lcd1602_wrdata(asc[8]);
393 2 }
394 1 else if(u==0x84)
395 1 {
396 2 in[s]=in[s]*10+9;
397 2 lcd1602_wrdata(asc[9]);
398 2 }
399 1 }
400
401
402 void cunchu()
403 {
404 1 uchar i,j;
405 1 j=s*3;
406 1 IICWrite(j,m[s]);
407 1 i=(uchar)(in[s]);
408 1 IICWrite(j+1,i);
409 1 i=(uchar)(in[s]>>8);
410 1 IICWrite(j+2,i);
411 1 }
412
413
414 void display()
415 {
416 1 uint i,ax,bx;
417 1 uchar cx,dx,j[2];
418 1 cx=IICRead(0);
419 1 dx=IICRead(3);
420 1 ax=IICRead(2);
421 1 ax=ax<<8+IICRead(1);
422 1 bx=IICRead(5);
423 1 bx=bx<<8;+IICRead(4);
424 1 i=(in[0]*m[1]-m[0]*in[1]+m[0]*mea-m[1]*mea)/(in[0]-in[1]);
425 1 j[0]=i/100;
426 1 i=i%100;
427 1 j[1]=i/10;
C51 COMPILER V7.20 TEXT1 07/17/2007 07:26:06 PAGE 8
428 1 i=i%10;
429 1 j[2]=i;
430 1 lcd1602_clear();
431 1 lcd1602_wrcmd(0x80);
432 1 for(i=0;i<8;i++)
433 1 lcd1602_wrdata(table4[i]);
434 1 lcd1602_wrdata(asc[j[0]]);
435 1 lcd1602_wrdata(table[0]);
436 1 lcd1602_wrdata(asc[j[1]]);
437 1 lcd1602_wrdata(asc[j[2]]);
438 1 }
439
440
441
442 main()
443 {
444 1 uchar key;
445 1 s=0;
446 1 delay(2);
447 1 lcd1602_bus=0xff;
448 1 lcd1602_init();
449 1 enter0();
450 1 while(1)
451 1 {
452 2 key=0;
453 2 while(key==0)
454 2 key=keyscan();
455 2 while(key_bus!=0xf0)
456 2 key_bus=0xf0;
457 2 if(state==0)
458 2 {
459 3 if(key==0x21)
460 3 enter1();
461 3 else if(key==0x22)
462 3 {
463 4 state=2;
464 4 display();
465 4 }
466 3 else if(key==0x24)
467 3 enter3();
468 3 }
469 2 else if(state==1)
470 2 {
471 3 if(key==0x18)
472 3 {
473 4 measure();
474 4 }
475 3 else if(key==0x88)
476 3 enter0();
477 3 }
478 2 else if(state==2)
479 2 {
480 3 if(key==0x88)
481 3 enter0();
482 3 }
483 2 else if(state==3)
484 2 {
485 3 if(key==0x18)
486 3 {
487 4 measurebiao();
488 4 in[s]=0;
489 4 }
C51 COMPILER V7.20 TEXT1 07/17/2007 07:26:06 PAGE 9
490 3 else if(key==0x88)
491 3 enter0();
492 3 }
493 2 else if(state==4)
494 2 {
495 3 getnum(key);
496 3 if(key==0x18)
497 3 {
498 4 cunchu();
499 4 lcd1602_wrcmd(0x0e);
500 4 enter3();
501 4 s++;
502 4 if(s==2)
503 4 s=0;
504 4 }
505 3 else if(key==0x88)
506 3 {
507 4 in[s]=0;
508 4 enter3();
509 4 measurebiao();
510 4 }
511 3 }
512 2 }
513 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1716 ----
CONSTANT SIZE = 65 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 10 6
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -