|
//我想用两个按键控制2个数码管单独显示数字,但是这个程序按k1,第一个数码管亮第二个灭;
//按k2第二个数码管亮了,第一个又灭了,有什么办法可以让这两个数码管同时亮着。请指教,谢谢了!
- #include <REG52.H>
- #define uchar unsigned char
- #define uint unsigned int
- sbit k1=P3^4;
- sbit k2=P3^5;
- sbit duan=P2^6;
- sbit wei=P2^7;
- uint m=0,n=0;
- uchar code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- void delay(uint xms)
- {
- uint i,j;
- for(i=xms;i>0;i--)
- for(j=112;j>0;j--);
- }
- void smgk1()
- {
- uint i;
- i=m%10;
-
- P0=tab[i];
- duan=1;
- duan=0;
- P0=0xfe;
- wei=1;
- wei=0;
- delay(500);
- }
- void smgk2()
- {
- uint i;
- i=n%10;
-
- P0=tab[i];
- duan=1;
- duan=0;
- P0=0xfd;
- wei=1;
- wei=0;
- delay(500);
- }
- void main()
- {
- while(1)
- {
- if(k1==0|k2==0)
- {
- delay(10);
- if(k1==0)
- {
- while(k1!=0);
- smgk1();
- m++;
- }
- if(k2==0)
- {
- while(k2!=0);
- smgk2();
- n++;
- }
- }
- }
- }
复制代码 |
|