|
是用51hei單片機(jī)開(kāi)發(fā)板 電路圖詳見(jiàn):http://www.zg4o1577.cn/f/51hei-5.pdf 用2個(gè)74hc573 鎖存,p0口作為數(shù)據(jù)口 ,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;
- //===================
- uchar a=0,b=0,c;
- //===================
- uchar key_S1(void);
- uchar key_S2(void);
- void delay(uint k);
- //=====================
- void main(void)
- { uchar i;
- while(1)
- {
- b=key_S1();
- a=key_S2();
- if(a>b)c=0x76;
- if(a<b)c=0x38;
- if(a==b)c=0x09;
- for(i=0;i<50;i++)
- {
- 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;
- P0=c;
- 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)
- {static uchar x;
- P2=0xff;
- if(P2!=0xff)
- {delay(10);
- if(P2==0xdf)
- {
- x=x+1;
- }
- }
- if(x>9)x=0;
- return x;
- }
- //=======================
- uchar key_S2(void)
- {static uchar y;
- P2=0xff;
- if(P2!=0xff)
- {delay(10);
- if(P2==0xbf)
- {
- y=y+1;
- }
- }
- if(y>9)y=0;
- return y;
- }
復(fù)制代碼
|
|