|
是用51hei单片机开发板 电路图详见:http://www.51hei.com/f/51hei-5.pdf 的数码管部分, 用2个74hc573 锁存,p0口作为数据口 ,注意图中要改一下p3.6和p3.7分别是段和位的锁存端口.P2口上面是按键 p1口上面是8个led灯.- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code DIS_SEG7[16]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- uchar code DIS_BIT[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- sbit D=P3^6;
- sbit V=P3^7;
- //==============
- void delay(uint k)
- {
- uint data i,j;
- for(i=0;i<k;i++){
- for(j=0;j<121;j++)
- {;}}
- }
- //===================
- void main(void)
- {
- uchar cnt;
- while(1)
- {
- for(cnt=0;cnt<8;cnt++)
- {D=1;P0=DIS_SEG7[cnt+1];D=0;P0=0xff;V=1;P0=DIS_BIT[cnt];V=0;
- delay(1);}
- }
- }
复制代码
|
|