是用51hei单片机开发板 电路图详见:http://www.51hei.com/f/51hei-5.pdf 的数码管部分, 用2个74hc573 锁存,p0口作为数据口 ,p3.6和p3.7分别是段和位的锁存端口.
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- sbit D=P3^6;
- sbit V=P3^7;
- sbit P2_5=P2^5;
- sbit P2_6=P2^6;
- //============
- uchar data a=0,b=0,out;
- //===========
- uchar key_S1(void);
- uchar key_S2(void);
- void delay(uint k);
- //============
- void main(void)
- {
- while(1)
- {
- b=key_S1();
- a=key_S2();
- if((a==8)&&(b==5))out=1;
- else out=0;
- D=1;
- P0=SEG7[a];
- D=0;
- P0=0xff;
- V=1;
- P0=0xfe;
- V=0;
- delay(2);
- D=1;
- P0=SEG7[b];
- D=0;
- P0=0xff;
- V=1;
- P0=0xfd;
- V=0;
- delay(2);
- D=1;
- if(out==1)P0=0x73;
- else P0=0x00;
- D=0;
- P0=0xff;
- V=1;
- P0=0xfb;
- V=0;
- delay(2);
- }
- }
- //===========
- void delay(uint k)
- {
- uint i,j;
- for(i=0;i<k;i++){
- for(j=0;j<121;j++)
- {;}}
- }
- //============
- uchar key_S1(void)
- {uchar data x;
- P2=0xff;
- if(!P2_5)x=5;
- else x=0;
- return x;
- }
- //===========
- uchar key_S2(void)
- {uchar data y;
- P2=0xff;
- if(!P2_6)y=8;
- else y=0;
- return y;
- }
复制代码
|