单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- #define uchar
- sbit wei=P2^7;
- sbit duan=P2^6;
- uchar code A[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned int ge=0;
- unsigned int shi=0;
- unsigned int bai=0;
- unsigned int qian=0;
- int k;
- void delay(unsigned int i)
- {
- unsigned int j;
- for(j=100;j>0;j--)
- for(;i>0;i--);
- }
- void main()
- {
- while(1)
- {
- ge++;
- wei=1;
- P0=0xf7;
- wei=0; //位选
- duan=1;
- P0=A[ge];
- duan=0; //段选
- delay(30);
- if(ge==9)
- {
- ge=0;
- shi++;
- wei=1;
- P0=0xfb;//shi
- wei=0;
- duan=1;
- P0=A[shi];
- duan=0;
- delay(10);
- }
- if(shi==9)
- {
- shi=0;
- bai++;
- wei=1;
- P0=0xfd;//shi
- wei=0;
- duan=1;
- P0=A[bai];
- duan=0;
- delay(10);
- }
- if(bai==9)
- {
- bai=0;
- qian++;
- wei=1;
- P0=0xfe;//shi
- wei=0;
- duan=1;
- P0=A[bai];
- duan=0;
- delay(10);
- }
- if(qian==9||bai==9||shi==9||ge==9)
- {
- wei=1;
- P0=0xff;
- wei=0;
- delay(10000);
- }
- }
- }
复制代码
|