proteus电路图
单片机源程序如下:
- #include<reg51.h>//独立按键 增减数字 超过0~9 显示F;
- #include<intrins.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define seg P0
- #define duan P2
- sbit s1=P2^1;
- sbit s2=P2^2;
- void delay(uint t)
- {
- while(t--);
- }
- void main()
- {
- uchar i=0,j=0,k=0,code shuzi[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//共阴数码管
- duan=0xfe;
- P0=shuzi[0];
- while(1)
- {
- if(s1==0)
- {
- delay(15);
- if(s1==0)
- i++;
- delay(50000);
- if(i>=0&&i<=9)
- {
- P0=shuzi[i];
- delay(5000);
- }
- else
- { P0=0X71;
- i=10;
- }
- }
- if(s2==0)
- {
- delay(15);
- if(s2==0)
- i--;
- delay(50000);
- if(i>=0&&i<=9)
- {
- P0=shuzi[i];
- delay(5000);
- }
- else
- {
- P0=0x71;
- i=-1;
- }
- }
-
- }
- }
复制代码
|