Home > other >  51 eight digital tube digital, can adjust time
51 eight digital tube digital, can adjust time

Time:09-25

Beginners 51, through online to find change program, digital work way of dynamic scanning, no use decoder 38, program the following
#include Sbit HourAdjust P1=^ 0;//adjust key sbit MinuteAdjust=P1 ^ 1;//points to adjust key sbit SecondAdjust=P1 ^ 2;///s key sbit Adjust=P1 ^ 3;//adjust key bit SecondFlag=0;//second sign bit FlashFlag=0;/flash sign bit/SEC Second10Flag=0;//10 seconds mark bit HourAdjustFlag=0;//adjust the sign bit MinuteAdjustFlag=0;//points to adjust sign 0 bit SecondAdjustFlag=0;///s logo unsigned char Led1, Led2, Led3, Led4, Led5, Led6; Int TimeCount Second10Count; Unsigned char code LedTab []={x5b x3f 0, 0 x06, 0, 0, x4f x66 0, 0 x6d, 0 x7d, 0 x07, 0 x7f, 0 x6f, 0 x00}; Void Delay100us (int Times); Void the timer interrupt 3 using 2 () {TR1=0; TL1=0 x13; TH1=0 x2c;//to assign a value P0=0 x00;//P2=0 xfe show hours; P0=LedTab [Led1]; Delay100us (1); P0=0 x00; The P2=0 XFD; If (FlashFlag)//SEC (1 second show, 1 second) P0=LedTab [Led2] | 0 x80; The else P0=LedTab [Led2] & amp; 0 x7f; Delay100us (1); P0=0 x00; P2=0 XFB//show points; P0=LedTab [Led3]; Delay100us (1); P0=0 x00; The P2=0 xf7; If (FlashFlag)//seconds seconds before the decimal point P0=LedTab [Led4] | 0 x80; The else P0=LedTab [Led4] & amp; 0 x7f; Delay100us (1); P0=0 x00;//display second P2=0 xef; P0=LedTab [Led5]; Delay100us (1); P0=0 x00; The P2=0 XDF; P0=LedTab [Led6]; Delay100us (1); TR1=1; If (TimeCount & lt; 150)//second counter TimeCount++; The else {TimeCount=0 x00; SecondFlag=1;//setting seconds mark if (Second10Flag)//counter 10 seconds if (Second10Count & lt; 20) Second10Count + +; The else {Second10Count=0 x00;//10 seconds counter qing 0 Second10Flag=0;//remove 10 s sign HourAdjustFlag=0;//remove adjustment flag bit MinuteAdjustFlag=0; SecondAdjustFlag=0; }}}//============================================================================the main (void) {int Second=30;//initialization time int Minute=00; Int Hour=12; Led1=0 x00; Led2=0 x00; Led3=0 x00; Led4=0 x00; Led5=0 x00; Led6=0 x00; SecondFlag=0; TimeCount=0 x00; PCON&=0 x7f; TMOD=0 x10f; TL1=0 x13; TH1=0 x2c; EA=1;//open the interrupt TF1=0; ET1=1;//timer interrupt TR1=1;//start the time while (1) {//adjust time program if (SecondFlag) {if (Second % 2==0) FlashFlag=1; The else FlashFlag=0; If (Second & lt; 59) Second++; The else {the if (Minute & lt; 59) Minute++; The else {the if (Hour & lt; 23) Hour++; The else Hour=0; Minute=0; } Second=0; } SecondFlag=0; }//time adjustment program if (HourAdjustFlag)//process the if (Second10Flag) if (FlashFlag)//second show {Led1=0 x0a;//hidden Led2=0 x0a; } else {Led1=Hour/10;//show Led2=10 Hour %; } else {Led1=Hour/10; Led2=10 Hour %; } else {Led1=Hour/10; Led2=10 Hour %; } the if (MinuteAdjustFlag)//adjustment of block if (Second10Flag) if (FlashFlag)//minutes {Led3=0 x0a; Led4=0 x0a; } else {Led3=Minute/10; Led4=10 Minute %; } else {Led3=Minute/10; Led4=10 Minute %; } else {Led3=Minute/10; Led4=10 Minute %; } the if (SecondAdjustFlag)//adjust the second procedure, control seconds show the if (Second10Flag) if (FlashFlag) {Led5=0 x0a; Led6=0 x0a; } else {Led5=Second/10; Led6=10 Second %; } else {Led5=Second/10; Led6=10 Second %; } else {Led5=Second/10; Led6=10 Second %; } the if (! HourAdjust)//adjustment button press {while (! HourAdjust);//wait for loosen HourAdjustFlag=1;//setting logo MinuteAdjustFlag=0;//remove points mark SecondAdjustFlag=0;//remove second sign Second10Flag=1;//setting 10 seconds mark} if (! MinuteAdjust)//points to adjust key press {while (! MinuteAdjust); MinuteAdjustFlag=1; HourAdjustFlag=0; SecondAdjustFlag=0; Second10Flag=1; } the if (! SecondAdjust)///s key press {while (! SecondAdjust); SecondAdjustFlag=1; HourAdjustFlag=0; MinuteAdjustFlag=0; Second10Flag=1; } the if (! Adjust)//Adjust key press {while (! Adjust); If (HourAdjustFlag)//adjustment, add 1 if (Hour & lt; 23) {Hour++; Second10Count=0; } the else Hour=0; If (MinuteAdjustFlag)//adjusted score, add 1 if (Minute & lt; 59) {Minute++; Second10Count=0; } the else//adjust seconds, reset Minute=0; If (SecondAdjustFlag) Second=0; {}}} void Delay100us (int Times) Times=Times * 100; While (Times --); } void init (void) {RCAP2H=0 x1f; RCAP2L=0 x00; ET2=1; TR2=1; EA=1; }

CodePudding user response:

See for a long time nobody reply you, this for your reference, don't understand to ask, suspended function can call everywhere, on the need to reset a certain value, can also be set BIT variable control. https://blog.csdn.net/xianfajushi/article/details/89448933
  • Related