|
是用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
- //==============
- sbit D=P3^6;
- sbit V=P3^7;
- void delay(uint k)
- {
- uint i,j;
- for(i=0;i<k;i++){
- for(j=0;j<121;j++)
- {;}}
- }
- //==============
- void main(void)
- {
- uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- uchar *pt,i;
- pt=SEG7;
- for(i=0;i<10;i++)
- {
- D=1;P0=SEG7[i];D=0;P0=0xff;V=1;P0=0xfe;V=0;delay(500);}
- //========
- D=1;P0=0x00;D=0;
- delay(2000);
- //=========
- for(i=0;i<10;i++)
- {
- D=1;P0=*(pt+i);D=0;P0=0xff;V=1;P0=0xfe;V=0;delay(500);}
- //====
- D=1;P0=0x00;D=0;
- //============
- while(1);
- }
复制代码
|
|