仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include "scanf.h"
- #include "delay.h"
- #include <reg52.h>
- #include "led.h"
- #define uint unsigned int
- #define uchar unsigned char
- void key0()
- {
- liushui6();
- P0=0xff;
- }
- void key1()
- {
- liushui5();
- P0=0xff;
- }
- void key2()
- {
- led_turn();
- P0=0xff;
- }
- void key3()
- {
- liushui4();
- P0=0xff;
- }
- void key4()
- {
- liushui3();
- P0=0xff;
- }
- void key5()
- {
- liushui2();
- P0=0xff;
- }
- void key6()
- {
- liushui1();
- P0=0xff;
- }
- void key7()
- {
- P0=0x00;
- delay_ms(800);
- P0=0xff;
- }
- void scanf(void)
- {
- while(1)
- {
- while(P1==0xff);
- delay_ms(10);
- while(P1==0xff);
- switch(P1)
- {
- case 0xfe:key0();break;
- case 0xfd:key1();break;
- case 0xfb:key2();break;
- case 0xf7:key3();break;
- case 0xef:key4();break;
- case 0xdf:key5();break;
- case 0xbf:key6();break;
- case 0x7f:key7();break;
- default: break;
- }
- while(P1!=0xff);//等待键释放
- }
- }
复制代码
所有资料51hei提供下载:
实验二.rar
(86.25 KB, 下载次数: 15)
|