按键调节数码管数字显示
2016-12-14 / 电子技术 / 1974 次围观 / 0 次吐槽 /#include<reg51.h> #define INT8U unsigned char #define INT16U unsigned int sbit K1=P3^4; sbit K2=P3^5; sbit K3=P3^6; sbit K4=P3^7; INT8U code SEG_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; INT16U Count =2900; INT16U Temp; INT8U array[]={0,0,0,0}; INT8U Adjust=0; INT8U Pre_key=0xf0; void delay_ms(INT16U x){ INT8U t; while(x--) for(t=0;t<120;t++); } void INT_TO_4Digit(INT16U n){ array[0]=0; while(n>=1000){array[0]++;n-=1000;} array[1]=0; while(n>=100){array[1]++;n-=100;} array[2]=0; while(n>=10){array[2]++;n-=10;} array[3]=n; } void key_handle(){ P3 |= 0xF0; if(Pre_key==(P3 & 0xF0)) return; Pre_key = P3 & 0xf0; if(!K1){ delay_ms(10); if(!K1){ if(Temp==0) Temp=Count; Count++; Adjust=1; } } if(!K2){ delay_ms(10); if(!K2){ if(Temp==0) Temp=Count; Count--; Adjust=1; } } if(!K3){ delay_ms(10); if(!K3){ Adjust=0;Temp=0; } } if(!K4){ delay_ms(10); if(!K4){ if(Temp) Count=Temp; Temp=0; Adjust=0; } } } void main(){ INT8U i; INT16U t; while(1){ for(t=0;t<35;t++){ INT_TO_4Digit(Count); for(i=0;i<4;i++){ P0=0xff; P3=(P3 & 0xf0)|(1<<i); P0=SEG_CODE[array[i]]; delay_ms(2); } key_handle(); } if(Adjust){ P0= 0Xff; for(t=0;t<15;t++){ delay_ms(10); key_handle(); } } } }
- 上一篇:集成式数码管动态扫描显示
- 下一篇:集成式数码管动态显示电路
Powered By Cheug's Blog
Copyright Cheug Rights Reserved.