??? 03/13/07 13:35 Read: times |
#134852 - formatting helps Responding to: ???'s previous message |
This is no answer, just your program enclosed into <pre> and </pre> tags:
#include char Pencacah20; char Secon; char Minute; char Hour; char Segmen[6];// sbit at 0xA0 Hour_Button ; sbit at 0xA1 TombolMinute ; sbit at 0xA2 Secon_Button ; sbit at 0xA3 INC_Hour_Button; sbit at 0xA4 INC_Minute_Button; sbit at 0xA5 INC_Secon_Button; //****** array number 0-9 ******* void Segmen2Digit (unsigned char c, unsigned char pos){ code char Segmen_Com[]={0x01,0xC7,0x22,0x82,0xC4,0x88,0x08,0xC3,0x00,0x80}; Segmen[pos++] = Segmen_Com[c/10]; Segmen[pos] =Segmen_Com[c%10]; } void Change_View (void){ Segmen2Digit(Hour,0); Segmen2Digit(Minute,2); Segmen2Digit(Secon,4);// } //******Delay time 1 digit number******* void WaitMomen() {//wait 1m secon TH1=(-1500/256)-1; TL1=(-1500%256); TF1=0; //Timer Flag 1 =0 TR1=1; while (!TF1); } //****Main program****************************************** void main (void) { Pencacah20=20; Hour=Minute=Secon=0; Change_View(); TH0=(-50000/256)-1; TL0=(-50000%256); TMOD=0x11; ET0=1; EA=1; TR0=1; while(1) { P1=Segmen[0]; P0=0xDF; WaitMomen(); P1=Segmen[1]; P0=0xEF; WaitMomen(); P1=Segmen[2]; P0=0xF7; WaitMomen(); P1=Segmen[3]; P0=0xFB; WaitMomen(); P1=Segmen[4]; P0=0xFD; WaitMomen(); P1=Segmen[5]; P0=0xFE; WaitMomen(); } } //1111 1111 //**********change Hour digit************* void ChangeHour (void){ Hour +=1; if (Hour==24){ Hour = 0 ; Change_View(); } } void ChangeMinute(void){ Minute +=1; if (Minute==60){ Minute = 0 ; ChangeHour(); } Change_View(); } void ChangeSecon(void) { Secon +=1; if (Secon==60) { Secon=0; ChangeMinute(); } Change_View(); } void Increment_Hour(void) { Hour -=1; if(Hour==0) { Hour=24; Change_View(); } } void Increment_Minute(void){ Minute -=1; if (Minute==0){ Minute =59 ; Increment_Hour(); } Change_View(); } void Increment_Secon(void) { Secon -=1; if (Secon==0) { Secon=0; Increment_Minute(); } Change_View(); } void Check_Button (void) { if (!Hour_Button) ChangeHour(); else if (!TombolMinute) ChangeMinute(); else if(!Secon_Button) ChangeSecon(); else if(!INC_Hour_Button) Increment_Hour(); else if(!INC_Minute_Button) Increment_Minute(); } void TimerInterrupst(void) interrupt 1 using 1 { TH0=(-45000/256) -1; TL0=(-45000%256); Pencacah20 -=1; if (!Pencacah20) { Pencacah20=20; Check_Button(); ChangeSecon(); } } See also http://www.8052.com/faqs.phtml?FAQ=120199 and the JW |
Topic | Author | Date |
CLOCK WITH 7SEGMENT DISPLAY | 01/01/70 00:00 | |
formatting helps | 01/01/70 00:00 | |
Didn't search first | 01/01/70 00:00 |