是用51hei单片机开发板 电路图详见:http://www.51hei.com/f/51hei-5.pdf 的数码管部分, 用2个74hc573 锁存,p0口作为数据口 ,注意图中要改一下p3.6和p3.7分别是段和位的锁存端口.P2口上面是按键- #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};
- uchar code ACT[4]={0xfe,0xfd,0xfb,0xf7};
- sbit D=P3^6;
- sbit V=P3^7;
- //==============
- uint data cnt;
- bit bdata bitflag;
- //==========
- void init(void)
- {
- bitflag=1;
- EX0=1;
- IT0=1;
- EA=1;
- }
- //================
- void delay(uint k)
- {
- uint data i,j;
- for(i=0;i<k;i++){
- for(j=0;j<121;j++)
- {;}}
- }
- //===========
- void main(void)
- {uchar i;
- init();
- while(1)
- {
- if(bitflag)cnt++;
- if(cnt>999)cnt=0;
- for(i=0;i<100;i++)
- {
- D=1;P0=SEG7[cnt/100];D=0;P0=0xff;V=1;P0=ACT[0];V=0;delay(2);
- D=1;P0=SEG7[(cnt%100)/10];D=0;P0=0xff;V=1;P0=ACT[1];V=0;delay(2);
- D=1;P0=SEG7[cnt%10];D=0;P0=0xff;V=1;P0=ACT[2];V=0;delay(2);
- }
- }
- }
- //=================
- void extern_int0(void) interrupt 0 using 0
- {
- bitflag=!bitflag;
- }
复制代码
|