- #include "reg52.h"
- sbit k3=P3^2;
- sbit k4=P3^3;
- unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned char i=0,j=0,k=0;
- unsigned char num1,num2;//消抖计数变量
- /*
- void delay(unsigned int i)
- {
- while(i--);
- }
- */
- void digui()
- {
- j++;//延时计数
- if(j>=250)
- {
- j=0;
- P0=0x00;//消隐
- if(k==0)
- {
- P2=0x02; //送位码
- P0=table[i%10];//送段码
- k=1;
- }
- else if(k==1)
- {
- P2=0x04;
- P0=table[i/10%10];
- k=2;
- }
- else if(k==2)
- {
- P2=0x08;
- P0=table[i/100%10];
- k=0;
- }
- }
- }
- void main()
- {
- while(1)
- {
- if(k3==0)//按下
- {
- num1++;//消抖计数
- if(num1>100)
- num1=101;//防止溢出
- if(num1==100)
- {
- if(i<100)
- i++;
- }
- }
- else num1=0;//松手清0
- if(k4==0)
- {
- num2++;
- if(num2>100)
- num2=101;
- if(num2==100)
- {
- if(i>0)
- i--;
- }
- }
- else num2=0;
- digui();//数码管显示程序
- }
- }
复制代码
|