Thông báo

Collapse
No announcement yet.

Đo nhiệt độ+ Đồng hồ số hiển thị LED 7 đoạn !

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • Đo nhiệt độ+ Đồng hồ số hiển thị LED 7 đoạn !

    Xem chừng là diễn box 8051 đang sôi động với đồng hồ số và đo nhiệt độ các loại, hôm nay rảnh ngồi send cho ae nào quan tâm tới vấn đề này. Một cái project mình làm đầy đủ cả, bạn nào thích thì load về lắp chơi nhé.

    Screen Layout:



    Screen Protues:


    Demo Video:

    ////////////////////////////
    http://youtu.be/3xgErHkoIIo
    /////////////////////////

    Screen Capture: Attach
    File Download: Attach

    Code fix một số chỗ cho những ai cảm thấy code cũ có vấn đề
    PHP Code:
    /***********************************************************
    FileName: Hai-Clock-7segment.c
    MCU: 8051
    Xtal: 12Mhz
    App: Digital Clock    
    Author:     manhcuong.k08@gmail.com
    Creat Date: 4/5/2011
    Finish Date: 
    ************************************************************/
    #include <at89x52.h>
    /**********************define var,port*********************/
    #define data_port P2
    #define sel_port P0
    sbit _RW P3^6;            //
    sbit _RD P3^7;          // 
    sbit _INT P1^7;
    sbit MODE P3^3;    //external interrupt 1
    sbit DEC P3^4;    //DEC value
    sbit INC P3^5;    //increment value
    sbit SDA P3^0;    //I2c data line
    sbit SCL P3^1;    //I2c clock line

    //===================time variable============================//
    struct FREE_USER{
                         
    unsigned char SEC;
                         
    unsigned char MIN;
                         
    unsigned char HOUR;
                         
    unsigned char DAY;
                         
    unsigned char DATE;
                         
    unsigned char MONTH;
                         
    unsigned char YEAR;
                         } 
    _TIME ;
    //============================================================//
    //            Byte control Real Time Cloclk DS1307              //
    //                                                              //
    //============================================================//
    #define CONTROL_WRITE 0xd0
    #define CONTROL_READ 0xd1

    /*********************sub program**************************/

    //==========================================================//
    //                                                            //
    //                RTC class                                    //
    //==========================================================//
    unsigned char  RTC_READ(unsigned char ADRESS);
    void RTC_WRITE(unsigned char ADRESS,unsigned char DAT);
    void I2C_START();
    void I2C_STOP();
    void I2C_WRITE(unsigned char byte);
    unsigned char I2C_READ();
    void RTC_INI();
    //==========================================================//
    //                                                            //
    //                other                                        //
    //==========================================================//
    void DISPLAY_1__(unsigned char ARRAY[],unsigned char STATUS,bit istempsensor);
    void DISPLAY_2__(unsigned char ARRAY[]);
    void delay(int time);
    void GET_TIME();
    void TIMER0_ini();
    void TIMER1_ini();                
    void CHECK_DAY(bit get);
    void CONVERT();
    void GET_T();
    void DISPLAY_3__(unsigned char ARRAY[]);
    unsigned char code     seg_code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
    unsigned char code HELLO[] = {
                                    
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                    
    0x00,0x76,0x79,0x38,0x38,0x3f,0x00,0x00,
                                    
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
    unsigned char code MORNING[] = {
                                    
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                    
    0x39,0x74,0x77,0x5C,0x00,0x7C,0x1C,0x5C,0x10,
                                    
    0x00,0x6D,0x77,0x54,0x6F,
                                    
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
    unsigned char code AFTERNOON[] = {
                                    
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                    
    0x39,0x74,0x77,0x5C,0x00,0x7C,0x1C,0x5C,0x10,
                                    
    0x00,0x58,0x74,0x10,0x79,0x1c,
                                    
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
    //day on week==============================================
    unsigned char code SUN[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x39,0x74,0x1c,0x00,0x54,0x74,0x77,0x31,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };
    unsigned char code MON[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x07,0x76,0x3e,0x00,0x5b,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };    
    unsigned char code TUE[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x07,0x76,0x3e,0x00,0x4f,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };    
    unsigned char code WED[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x07,0x76,0x3e,0x00,0x66,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };    
    unsigned char code THU[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x07,0x76,0x3e,0x00,0x6d,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };    
    unsigned char code FRI[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x07,0x76,0x3e,0x00,0x7d,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };    
    unsigned char code SAT[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x07,0x76,0x3e,0x00,0x07,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };

    unsigned char TIME_DISPLAY[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };    
    unsigned char DATE_DISPLAY[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };    
    unsigned char DAY_DISPLAY[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };    
    unsigned char code T_SENSOR[] = {
                                        
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x63,0x39,0x00,0x00,
                                        
    0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                        
    };    
    unsigned char T_value[2];    
    #define SHIFT 0x00
    #define STOP 0x01
    #define CLEAR 0x02
    #define TIME_STATUS 1080

    int GLOBAL_DISPLAY=0;
    unsigned char IN_VISIBLE;
    unsigned char CONTROL_INVISIBLE=0;
    unsigned char SHIFT_CURCOR;
    unsigned char counter_status;
    /********************************************************/
    /*            Main Program                                */
    /********************************************************/
    void main()
    {

        
    /********Time Default**************
        _TIME.SEC = 0x00 ;
        _TIME.MIN = 0x00 ;
        _TIME.HOUR = 0x12 ;
        _TIME.DAY  = 0x04 ;
        _TIME.DATE = 0x10;
        _TIME.MONTH = 0x04;
        _TIME.YEAR     = 0x11;
        RTC_INI();
        ////////////////////////////////////*/
        
    _RD 1;
        
    _RW 1;
        
    TIMER0_ini();
        
    TIMER1_ini();
        
    //enable global interrupt
        
    EX1 1;    //enable external interrupt 1
        
    IT1 1;    //
        
    EX0 1;    //enable external interrupt 1
        
    IT0 1;    //
        
    EA 1;
        
    TR0 1;    //timer0 run
        
    PT1 =1;
        
    PX0 1;
        
        while(
    1)
        {        
        
    //    GET_TIME();DISPLAY_1__(TIME_DISPLAY,STOP);
            
    switch(GLOBAL_DISPLAY)
            {
                 case 
    0:    DISPLAY_1__(HELLO,SHIFT,0);while(GLOBAL_DISPLAY<100)DISPLAY_1__(HELLO,STOP,0);DISPLAY_1__(HELLO,CLEAR,0);break;
                case 
    140:  DISPLAY_1__(TIME_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<600)DISPLAY_1__(TIME_DISPLAY,STOP,0);DISPLAY_1__(TIME_DISPLAY,CLEAR,0);break;
                case 
    620:  if((_TIME.HOUR>=0)&&(_TIME.HOUR<12))DISPLAY_3__(MORNING);else if(_TIME.HOUR>=12)DISPLAY_3__(AFTERNOON);break;
                case 
    700:  CHECK_DAY(1);DISPLAY_1__(DAY_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<800){CHECK_DAY(1);DISPLAY_1__(DAY_DISPLAY,STOP,0);}DISPLAY_1__(DAY_DISPLAY,CLEAR,0);break;
                case 
    820:  DISPLAY_1__(DATE_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<920)DISPLAY_1__(DATE_DISPLAY,STOP,0);DISPLAY_1__(DATE_DISPLAY,CLEAR,0);break;
                case 
    950:  GET_T();DISPLAY_1__(T_SENSOR,SHIFT,1);while(GLOBAL_DISPLAY<1050)DISPLAY_1__(T_SENSOR,STOP,1);DISPLAY_1__(T_SENSOR,CLEAR,1);break;
                default:     {;}break;
            }    
        }
    }
     
    //==========================================================//
    //                                                            //
    //                DISPLAY_3__                                     //
    //==========================================================//
    void DISPLAY_3__(unsigned char ARRAY[])
    {
         
    unsigned char counter_char=0,index,time_shift,counter;
         
    unsigned char __SELECT__ ;
         while(ARRAY[
    counter_char]!=0xff)
                     
    counter_char++;
         for(
    index=0;index<counter_char-8;index++)
                {
                    for(
    time_shift=0;time_shift<20;time_shift++)
                    {    
                        
    __SELECT__ 0x7f;
                        for(
    counter=0;counter<8;counter++)
                        {
                            
    data_port = ARRAY[counter+index];
                            
    sel_port __SELECT__;
                            
    delay(7);
                            
    sel_port 0xff;     //disable all led
                            
    data_port 0x00;    //disable all led
                            
    __SELECT__ >>= 1;
                            
    __SELECT__ |= 0x80;
                        }
                    }
                }
    }
     
    //==========================================================//
    //                                                            //
    //                DISPLAY_2__                                     //
    //==========================================================//
    void DISPLAY_2__(unsigned char ARRAY[])
    {
            
    unsigned char counter;
             
    unsigned char __SELECT__=0x7f ;
                               for(
    counter=0;counter<8;counter++)
                                    {
                                        
    sel_port __SELECT__;
                                        
    sel_port |= IN_VISIBLE;
                                        
    data_port = ARRAY[counter+8];
                                        
    delay(7);
                                        
    sel_port 0xff;     //disable all led
                                        
    data_port 0x00;    //disable all led
                                        
    __SELECT__ >>= 1;
                                        
    __SELECT__ |= 0x80;
                                    }
    }
     
    //==========================================================//
    //                                                            //
    //                DISPLAY_1__                                     //
    //==========================================================//    
    void DISPLAY_1__(unsigned char ARRAY[],unsigned char _STATUS_,bit istempsensor)
    {
         
    unsigned char counter_char=0,index,time_shift,counter;
         
    unsigned char __SELECT__ ;
         while(ARRAY[
    counter_char]!=0xff)
                     
    counter_char++;
         switch(
    _STATUS_)
         {
            
            case 
    SHIFT: {
                            for(
    index=0;index<counter_char-16;index++)
                            {
                                 for(
    time_shift=0;time_shift<20;time_shift++)
                                {
                                    
    __SELECT__ 0x7f;
                                     for(
    counter=0;counter<8;counter++)
                                    {
                                        if(
    istempsensor)
                                        {
                                             if(
    counter+index==0x0a)
                                            
    data_port T_value[0];
                                            else if(
    counter+index==0x0b)
                                            
    data_port T_value[1];
                                            else
                                            
    data_port = ARRAY[counter+index];
                                        }
                                        else 
                                        
    data_port = ARRAY[counter+index];
                                        
    sel_port __SELECT__;
                                        
    delay(7);
                                        
    sel_port 0xff;     //disable all led
                                        
    data_port 0x00;    //disable all led
                                        
    __SELECT__ >>= 1;
                                        
    __SELECT__ |= 0x80;
                                    }
                                }
                            }
                        break;
                        }
            case 
    STOP:    {
                            
    __SELECT__ 0x7f;
                               for(
    counter=0;counter<8;counter++)
                                    {
                                        if(
    istempsensor)
                                        {
                                             if(
    counter+8==0x0a)
                                            
    data_port T_value[0];
                                            else if(
    counter+8==0x0b)
                                            
    data_port T_value[1];
                                            else
                                            
    data_port = ARRAY[counter+8];
                                        }
                                        else
                                         
    data_port = ARRAY[counter+8];
                                        
    sel_port __SELECT__;
                                        
    delay(7);
                                        
    sel_port 0xff;     //disable all led
                                        
    data_port 0x00;    //disable all led
                                        
    __SELECT__ >>= 1;
                                        
    __SELECT__ |= 0x80;
                                    }
                                break;
                                }
            case 
    CLEAR: {
                            for(
    index=8;index<counter_char-8;index++)
                            {
                                 for(
    time_shift=0;time_shift<20;time_shift++)
                                {
                                    
    __SELECT__ 0x7f;
                                     for(
    counter=0;counter<8;counter++)
                                    {
                                        if(
    istempsensor)
                                        {
                                             if(
    counter+index==0x0a)
                                            
    data_port T_value[0];
                                            else if(
    counter+index==0x0b)
                                            
    data_port T_value[1];
                                            else
                                            
    data_port = ARRAY[counter+index];
                                        }
                                        else
                                         
    data_port = ARRAY[counter+index];
                                        
    sel_port __SELECT__;
                                        
    delay(7);
                                        
    sel_port 0xff;     //disable all led
                                        
    data_port 0x00;    //disable all led
                                        
    __SELECT__ >>= 1;
                                        
    __SELECT__ |= 0x80;
                                    }
                                }
                            }
                        break;
                        }
                            
         }

    }
     
    //==========================================================//
    //                                                            //
    //                delay                                     //
    //==========================================================//         
    void delay(int time)
    {
        
    int i,j;
        for(
    i=0;i<time;i++)
             for(
    j=0;j<time;j++)
            {;}
    }
    //==========================================================//
    //                                                            //
    //                I2c_START                                     //
    //==========================================================//
    void I2C_START()
    {
         
    SDA 1;
        
    SCL 1;
        
    SDA 0;
        
    SCL 0;
        
    SDA 1;
    }
    //==========================================================//
    //                                                            //
    //                I2c_STOP                                     //
    //==========================================================//
    void I2C_STOP()
    {
        
    SDA 0;
        
    SCL 1;
        
    SDA 1;
    }
    //==========================================================//
    //                                                            //
    //                I2c_WRITE                                     //
    //==========================================================//
    void I2C_WRITE(unsigned char byte)
    {
        
    unsigned char counter;
        for(
    counter 0;counter<8;counter++)
        {
             if(
    byte&0x80)
                
    SDA=1;
            else
                
    SDA=0;
            
    SCL 1;
            
    SCL 0;
            
    byte<<=1;
        }
            
    SDA 1;
            
    SCL 1;
            
    SCL 0;
            
    }
    //==========================================================//
    //                                                            //
    //                I2c_READ                                     //
    //==========================================================//
    unsigned char I2C_READ()
    {
        
    unsigned char return_value=0x00,counter=8;
            while(
    counter>0)
            {
                 
    SCL=1;
                
    return_value<<=1;
                
    return_value|=SDA;
                
    SCL=0;
                
    counter--;    
            }

            
    SDA 1
            
    SCL 1;
            
    SCL 0;
            
    SDA 1
            return 
    return_value;
            
    }
    //==========================================================//
    //                                                            //
    //                RTC_WRITE                                     //
    //==========================================================//
    void RTC_WRITE(unsigned char ADDRESS,unsigned char DAT)
    {
        
    I2C_START();                    //i2c start
        
    I2C_WRITE(CONTROL_WRITE);       //send control byte
        
    I2C_WRITE(ADDRESS);            //send address byte
        
    I2C_WRITE(DAT);                    //send data byte
        
    I2C_STOP();                      //i2c stop

    }
    //==========================================================//
    //                                                            //
    //                RTC_READ                                     //
    //==========================================================//
    unsigned char RTC_READ(unsigned char ADDRESS)
    {
        
    unsigned char return_value=0x00;
        
    I2C_START();
        
    I2C_WRITE(CONTROL_WRITE); //send byte control write
        
    I2C_WRITE(ADDRESS); // send byte address
        
    I2C_START(); // restart
        
    I2C_WRITE(CONTROL_READ); // send byte control read
        
    return_value I2C_READ(); //read from RTC
        
    I2C_STOP();
        return 
    return_value;
    }
    //==========================================================//
    //                                                            //
    //                RTC_INI                                     //
    //==========================================================//
    void RTC_INI()    
    {          
    //ADDRESS,DATA//
        
    RTC_WRITE(0x00,_TIME.SEC);
        
    RTC_WRITE(0x01,_TIME.MIN);
        
    RTC_WRITE(0x02,_TIME.HOUR);
        
    RTC_WRITE(0x03,_TIME.DAY);
        
    RTC_WRITE(0x04,_TIME.DATE);
        
    RTC_WRITE(0x05,_TIME.MONTH);
        
    RTC_WRITE(0x06,_TIME.YEAR);
        
    RTC_WRITE(0x07,0x10);//OUT = 1,SOUT = 1;
    }
    //==========================================================//
    //                                                            //
    //                GET_TIME                                    //
    //==========================================================//
    void GET_TIME()
    {
         
        
    _TIME.SEC RTC_READ(0x00);    //GET SECOND
        
    _TIME.MIN RTC_READ(0x01);    //GET MIN
        
    _TIME.HOUR RTC_READ(0x02)&0x3f;    //GET HOUR
        
    _TIME.DAY RTC_READ(0x03);    //GET DAY
        
    _TIME.DATE RTC_READ(0x04);    //GET DATE
        
    _TIME.MONTH RTC_READ(0x05);    //GET MONTH
        
    _TIME.YEAR RTC_READ(0x06);    //GET YEAR
        
    CONVERT();
    }
                                                                       
    //==========================================================//
    //                                                            //
    //                Timer0_ini                                    //
    //==========================================================//
    void TIMER0_ini()
    {
        
    TMOD 0x01    ;//timer 0 16bit reload
        
    TH0 0x00;
        
    TL0 0x00;
        
    TF0 0;
        
    TR0 0;
        
    ET0 1;    //enable timer0 interrupt
        
    }
    //==========================================================//
    //                                                            //
    //                CONVERT                                    //
    //==========================================================//
    void CONVERT()
    {
    unsigned char temp,index=15;
     
    //GET SECCOND
        
    temp _TIME.SEC;
        
    temp&=0x0f;        //get the unit
        
    TIME_DISPLAY[index]=seg_code[temp];
        
    index--;
        
    temp _TIME.SEC;
        
    temp&=0xf0;        //get the tens
        
    temp>>=4;
        
    TIME_DISPLAY[index]=seg_code[temp];
        
    index--;
    //SPACER
        
    TIME_DISPLAY[index]=0x40;    //
        
    index--;
     
    //GET MIN
        
    temp _TIME.MIN;
        
    temp&=0x0f;        //get the unit
        
    TIME_DISPLAY[index]=seg_code[temp];
        
    index--;
        
    temp _TIME.MIN;
        
    temp&=0xf0;        //get the tens
        
    temp>>=4;
        
    TIME_DISPLAY[index]=seg_code[temp];
        
    index--;
    //SPACER
        
    TIME_DISPLAY[index]=0x40;    //
        
    index--;
     
    //GET HOUR
        
    temp _TIME.HOUR;
        
    temp&=0x0f;        //get the unit
        
    TIME_DISPLAY[index]=seg_code[temp];
        
    index--;
        
    temp _TIME.HOUR;
        
    temp&=0xf0;        //get the tens
        
    temp>>=4;
        
    TIME_DISPLAY[index]=seg_code[temp];

        
    index=15;
    //GET YEAR
        
    temp _TIME.YEAR;
        
    temp&=0x0f;        //get the unit
        
    DATE_DISPLAY[index]=seg_code[temp];
        
    index--;
        
    temp _TIME.YEAR;
        
    temp&=0xf0;        //get the tens
        
    temp>>=4;
        
    DATE_DISPLAY[index]=seg_code[temp];
        
    index--;
    //SPACER
        
    DATE_DISPLAY[index]=0x40;    //
        
    index--;
     
    //GET MONTH
        
    temp _TIME.MONTH;
        
    temp&=0x0f;        //get the unit
        
    DATE_DISPLAY[index]=seg_code[temp];
        
    index--;
        
    temp _TIME.MONTH;
        
    temp&=0xf0;        //get the tens
        
    temp>>=4;
        
    DATE_DISPLAY[index]=seg_code[temp];
        
    index--;
    //SPACER
        
    DATE_DISPLAY[index]=0x40;    //
        
    index--;
     
    //GET DATE
        
    temp _TIME.DATE;
        
    temp&=0x0f;        //get the unit
        
    DATE_DISPLAY[index]=seg_code[temp];
        
    index--;
        
    temp _TIME.DATE;
        
    temp&=0xf0;        //get the tens
        
    temp>>=4;
        
    DATE_DISPLAY[index]=seg_code[temp];
    }
    //==========================================================//
    //                                                            //
    //                Timer1_ini                            //
    //==========================================================//
    void TIMER1_ini()
    {
        
    TMOD |= 0x10;    //timer 1 16bit reload
        
    TH1 0x00;
        
    TL1 0x00;
        
    TF1 0;
        
    TR1 0;
        
    ET1 1;
        
    }
    //==========================================================//
    //                                                            //
    //                Timer0_interrupt                                    //
    //==========================================================//
    void TIMER0_interrupt() interrupt 1
    {
        
    TR0 0;
        
    TF0 0;
        
    TH0 0;
        
    TL0 0;
        
    GLOBAL_DISPLAY++;
        if(
    GLOBAL_DISPLAY==TIME_STATUS)
                
    GLOBAL_DISPLAY=0;
        
    TR0 1;
        
    }
    //==========================================================//
    //                                                            //
    //                Timer1_interrupt                            //
    //==========================================================//
    void TIMER1_interrupt()    interrupt 3
    {
        
    TR1 0;    //stop timer1
        
    TF1 0;    //clear TF1
        
    TH1 0;
        
    TL1 1;
        
    CONTROL_INVISIBLE++;
        if(
    CONTROL_INVISIBLE==5)
        {
            
    IN_VISIBLE 0x00;
        }
        else if(
    CONTROL_INVISIBLE==10)
        {
            
    IN_VISIBLE SHIFT_CURCOR;
            
    CONTROL_INVISIBLE=0;
         }
        else {;}
        
    TR1 1;
        
    }
    //==========================================================//
    //                                                            //
    //                External Interrupt 1                        //
    //==========================================================//
    void EX1_interrupt()interrupt 2
    {
        
    unsigned char unit,tens;
        
    EX1 0//    disable ex interrupt 1
        
    EX0 0//    disable ex interrupt 0
        
    counter_status=0x00;
        
    TR1 1;    //enable TIMER1
        
    IN_VISIBLE 0xc0;
        
    SHIFT_CURCOR =       IN_VISIBLE;
        
    CONTROL_INVISIBLE=0;
    //    GET_TIME();
        
    while(MODE==0)DISPLAY_2__(TIME_DISPLAY);
        while(
    counter_status!=0x07)
        {
            
             switch(
    counter_status)
            {
                 case 
    0x00:    {
                                while(
    MODE)
                                {
                                     if(
    INC==0)
                                    {
                                         while(
    INC==0)DISPLAY_2__(TIME_DISPLAY);
                                        
    unit _TIME.HOUR;
                                        
    unit &=0x0f;
                                        
    tens _TIME.HOUR;
                                        
    tens >>= 4;
                                        if(
    tens!=2)
                                        {
                                                
    unit++;
                                                if(
    unit==10)
                                                {
                                                    
    tens++;
                                                    
    unit=0;
                                                }
                                        }
                                        else
                                        {
                                             
    unit++;
                                            if(
    unit==4)
                                            {
                                                
    tens=0;
                                                
    unit 0;
                                            }
                                            
                                        }
                                        
    _TIME.HOUR tens;
                                        
    _TIME.HOUR <<=4;
                                        
    _TIME.HOUR |= unit;
                                        
    CONVERT();
                                    }
                                    if(
    DEC==0)
                                    {
                                        while(
    DEC==0)DISPLAY_2__(TIME_DISPLAY);
                                        
    unit _TIME.HOUR;
                                        
    unit &=0x0f;
                                        
    tens _TIME.HOUR;
                                        
    tens >>= 4;
                                        if(
    tens!=0)
                                        {
                                                
    unit--;
                                                if(
    unit==0xff)
                                                {
                                                    
    tens--;
                                                    
    unit 0x09;
                                                }
                                        }
                                        else
                                        {
                                             
    unit--;
                                            if(
    unit==0xff)
                                            {
                                                
    tens 0x02;
                                                
    unit 0x03;
                                            }
                                            
                                        }
                                        
    _TIME.HOUR tens;
                                        
    _TIME.HOUR <<=4;
                                        
    _TIME.HOUR |= unit;
                                        
    CONVERT();
                                    }
                                    
    DISPLAY_2__(TIME_DISPLAY);
                                }
                                while(
    MODE==0){DISPLAY_2__(TIME_DISPLAY);}
                                while(
    IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
                                
    IN_VISIBLE>>=3;
                                
    SHIFT_CURCOR IN_VISIBLE;

                                
    counter_status++;
                                break;
                            }
                case 
    0x01:    {
                                while(
    MODE)
                                {
                                     if(
    INC==0)
                                    {
                                         while(
    INC==0)DISPLAY_2__(TIME_DISPLAY);
                                        
    unit _TIME.MIN;
                                        
    unit &=0x0f;
                                        
    tens _TIME.MIN;
                                        
    tens >>= 4;
                                        
    unit++;
                                        if(
    unit==10)
                                        {
                                            
    tens++;
                                            
    unit=0;
                                        }
                                        if(
    tens==6)
                                             
    tens=0;
                                        
    _TIME.MIN tens;
                                        
    _TIME.MIN <<=4;
                                        
    _TIME.MIN |= unit;
                                        
    CONVERT();
                                    }
                                    if(
    DEC==0)
                                    {
                                        while(
    DEC==0)DISPLAY_2__(TIME_DISPLAY);
                                        
    unit _TIME.MIN;
                                        
    unit &=0x0f;
                                        
    tens _TIME.MIN;
                                        
    tens >>= 4;
                                        
    unit--;
                                        if(
    unit==0xff)
                                        {
                                            
    tens--;
                                            
    unit=9;
                                        }
                                        if(
    tens==0xff)
                                             
    tens=5;
                                        
    _TIME.MIN tens;
                                        
    _TIME.MIN <<=4;
                                        
    _TIME.MIN |= unit;
                                        
    CONVERT();
                                    }
                                    
    DISPLAY_2__(TIME_DISPLAY);
                                }
                                while(
    MODE==0){DISPLAY_2__(TIME_DISPLAY);}
                                while(
    IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
                                
    IN_VISIBLE>>=3;
                                
    SHIFT_CURCOR IN_VISIBLE;
                                
    counter_status++;
                                break;
                            }
                case 
    0x02:    {
                                while(
    MODE)
                                {
                                     if(
    INC==0)
                                    {
                                         while(
    INC==0)DISPLAY_2__(TIME_DISPLAY);
                                        
    unit _TIME.SEC;
                                        
    unit &=0x0f;
                                        
    tens _TIME.SEC;
                                        
    tens >>= 4;
                                        
    unit++;
                                        if(
    unit==10)
                                        {
                                            
    tens++;
                                            
    unit=0;
                                        }
                                        if(
    tens==6)
                                             
    tens=0;
                                        
    _TIME.SEC tens;
                                        
    _TIME.SEC <<=4;
                                        
    _TIME.SEC|= unit;
                                        
    CONVERT();
                                    }
                                    if(
    DEC==0)
                                    {
                                        while(
    DEC==0)DISPLAY_2__(TIME_DISPLAY);
                                        
    unit _TIME.SEC;
                                        
    unit &=0x0f;
                                        
    tens _TIME.SEC;
                                        
    tens >>= 4;
                                        
    unit--;
                                        if(
    unit==0xff)
                                        {
                                            
    tens--;
                                            
    unit=9;
                                        }
                                        if(
    tens==0xff)
                                             
    tens=5;
                                        
    _TIME.SEC tens;
                                        
    _TIME.SEC <<=4;
                                        
    _TIME.SEC|= unit;
                                        
    CONVERT();
                                    }
                                  
    DISPLAY_2__(TIME_DISPLAY);
                                }
                                while(
    MODE==0){DISPLAY_2__(TIME_DISPLAY);}
                                while(
    IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
                                
    IN_VISIBLE=0xc0;
                                
    SHIFT_CURCOR IN_VISIBLE;
                                
    counter_status++;
                                break;
                            }
                case 
    0x03:    {
                                while(
    MODE)
                                {
                                     if(
    INC==0)
                                    {
                                         while(
    INC==0)DISPLAY_2__(DATE_DISPLAY);
                                        
    unit _TIME.DATE;
                                        
    unit &=0x0f;
                                        
    tens _TIME.DATE;
                                        
    tens >>= 4;
                                        if(
    _TIME.MONTH%2==1)
                                        {
                                             if(
    tens<3)
                                            {
                                                
    unit++;
                                                if(
    unit==10)
                                                {
                                                    
    tens++;
                                                    
    unit=0;
                                                }
                                            }
                                            else
                                            {
                                                 
    unit++;
                                                if(
    unit==2)
                                                {
                                                    
    tens=0;
                                                    
    unit=0;
                                                }
                                            }
                                        }
                                        else if(
    _TIME.MONTH%2==0)
                                        {
                                             if(
    tens<3)
                                            {
                                                
    unit++;
                                                if(
    unit==10)
                                                {
                                                    
    tens++;
                                                    
    unit=0;
                                                }
                                            }
                                            else
                                            {
                                                 
    unit++;
                                                if(
    unit==1)
                                                {
                                                    
    tens=0;
                                                    
    unit=0;
                                                }
                                            }
                                        }
                                        
    _TIME.DATE tens;
                                        
    _TIME.DATE <<=4;
                                        
    _TIME.DATE |= unit;
                                        
    CONVERT();
                                    }
                                    if(
    DEC==0)
                                    {
                                        while(
    DEC==0)DISPLAY_2__(DATE_DISPLAY);
                                        
    unit _TIME.DATE;
                                        
    unit &=0x0f;
                                        
    tens _TIME.DATE;
                                        
    tens >>= 4;
                                        if(
    _TIME.MONTH%2==1)
                                        {
                                             
    unit--;
                                            if(
    unit==0xff)
                                            {
                                                
    tens--;
                                                
    unit=9;
                                            }
                                            if(
    tens==0xff)
                                            {
                                                 
    tens=3;
                                                
    unit=1;
        
                                            }
                                        }
                                        else if(
    _TIME.MONTH%2==0)
                                        {
                                             
    unit--;
                                            if(
    unit==0xff)
                                            {
                                                
    tens--;
                                                
    unit=9;
                                            }
                                            if(
    tens==0xff)
                                            {
                                                 
    tens=3;
                                                
    unit=0;
        
                                            }
                                        }
                                        
    _TIME.DATE tens;
                                        
    _TIME.DATE <<=4;
                                        
    _TIME.DATE |= unit;
                                        
    CONVERT();
                                    }
                                    
    DISPLAY_2__(DATE_DISPLAY);
        
                                }
                                while(
    MODE==0){DISPLAY_2__(DATE_DISPLAY); }
                                while(
    IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
                                
    IN_VISIBLE>>=3;
                                
    SHIFT_CURCOR IN_VISIBLE;
                                
    counter_status++;
                                break;
                            }

                case 
    0x04:    {
                                while(
    MODE)
                                {
                                     if(
    INC==0)
                                    {
                                         while(
    INC==0)DISPLAY_2__(DATE_DISPLAY);
                                        
    unit _TIME.MONTH;
                                        
    unit &=0x0f;
                                        
    tens _TIME.MONTH;
                                        
    tens >>= 4;
                                        if(
    tens!=1)
                                        {
                                            
    unit++;
                                            if(
    unit==10)
                                            {
                                                
    tens++;
                                                
    unit=0;
                                            }
                                        }
                                        else
                                        {
                                             
    unit++;
                                            if(
    unit==3)
                                            {
                                                
    tens=0;
                                                
    unit=0;
                                            }
                                        }
                                        
    _TIME.MONTH tens;
                                        
    _TIME.MONTH <<=4;
                                        
    _TIME.MONTH |= unit;
                                        
    CONVERT();
                                    }
                                    if(
    DEC==0)
                                    {
                                        while(
    DEC==0)DISPLAY_2__(DATE_DISPLAY);
                                        
    unit _TIME.MONTH;
                                        
    unit &=0x0f;
                                        
    tens _TIME.MONTH;
                                        
    tens >>= 4;
                                        
    unit--;
                                        if(
    unit==0xff)
                                        {
                                            
    tens--;
                                            
    unit=9;
                                        }
                                        if(
    tens==0xff)
                                        {
                                             
    tens=1;
                                            
    unit=2;

                                        }
                                        
    _TIME.MONTH tens;
                                        
    _TIME.MONTH <<=4;
                                        
    _TIME.MONTH |= unit;
                                        
    CONVERT();
                                    }
                                    
    DISPLAY_2__(DATE_DISPLAY);
        
                                }
                                while(
    MODE==0){DISPLAY_2__(DATE_DISPLAY);}
                                while(
    IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
                                
    IN_VISIBLE>>=3;
                                
    SHIFT_CURCOR IN_VISIBLE;
                                
    counter_status++;
                                break;
                            }
                            
                case 
    0x05:    {
                                while(
    MODE)
                                {
                                     if(
    INC==0)
                                    {
                                         while(
    INC==0)DISPLAY_2__(DATE_DISPLAY);
                                        
    unit _TIME.YEAR;
                                        
    unit &=0x0f;
                                        
    tens _TIME.YEAR;
                                        
    tens >>= 4;
                                        
    unit++;
                                        if(
    unit==10)
                                        {
                                            
    tens++;
                                            
    unit=0;
                                        }
                                        if(
    tens==9)
                                             
    tens=0;
                                        
    _TIME.YEAR tens;
                                        
    _TIME.YEAR <<=4;
                                        
    _TIME.YEAR |= unit;
                                        
    CONVERT();
                                    }
                                    if(
    DEC==0)
                                    {
                                        while(
    DEC==0)DISPLAY_2__(DATE_DISPLAY);
                                        
    unit _TIME.YEAR;
                                        
    unit &=0x0f;
                                        
    tens _TIME.YEAR;
                                        
    tens >>= 4;
                                        
    unit--;
                                        if(
    unit==0xff)
                                        {
                                            
    tens--;
                                            
    unit=9;
                                        }
                                        if(
    tens==0xff)
                                             
    tens=9;
                                        
    _TIME.YEAR tens;
                                        
    _TIME.YEAR <<=4;
                                        
    _TIME.YEAR |= unit;
                                        
    CONVERT();
                                    }
                                    
    DISPLAY_2__(DATE_DISPLAY);
        
                                }
                                while(
    MODE==0){DISPLAY_2__(DATE_DISPLAY);}
                                while(
    IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
                                
    IN_VISIBLE 0xff;
                                
    SHIFT_CURCOR IN_VISIBLE;
                                
    counter_status++;
                                break;
                                
                            }
                case 
    0x06:    {
                                while(
    MODE)
                                {
                                    
    CHECK_DAY(0);
                                     if(
    INC==0)
                                    {
                                         while(
    INC==0)DISPLAY_2__(DAY_DISPLAY);
                                        
    _TIME.DAY++;
                                        if(
    _TIME.DAY==8)
                                            
    _TIME.DAY=1;
                                        
    CHECK_DAY(0);
                                    }
                                    if(
    DEC==0)
                                    {
                                        while(
    DEC==0)DISPLAY_2__(DAY_DISPLAY);
                                        
    _TIME.DAY--;
                                        if(
    _TIME.DAY==0xff)
                                            
    _TIME.DAY=7;
                                        
    CHECK_DAY(0);
                                    }
                                    
    DISPLAY_2__(DAY_DISPLAY);
        
                                }
                                while(
    MODE==0){DISPLAY_2__(DAY_DISPLAY);}
                                while(
    IN_VISIBLE==0x00){DISPLAY_2__(DAY_DISPLAY);}
                                
    SHIFT_CURCOR IN_VISIBLE;
                                
    counter_status++;
                                break;
                                
                            }
                            
            }
            
    RTC_INI();
        }
        
    IE1 0;//clear external interrupt 1 flag
        
    TR1 0;
        
    EX0 1;
        
    EX1 1;
    }
    //==========================================================//
    //                                                            //
    //                CHECK_DAY                                    //
    //==========================================================//
    void CHECK_DAY(bit get)
    {
        
    unsigned char index,DAY;
        if(
    get)
        
    DAY RTC_READ(0x03);
        else
        
    DAY _TIME.DAY;
        switch(
    DAY)
        {
             case 
    0x01:     for(index=0;index<24;index++)DAY_DISPLAY[index]=SUN[index];break;
            case 
    0x02:     for(index=0;index<24;index++)DAY_DISPLAY[index]=MON[index];break;
            case 
    0x03:     for(index=0;index<24;index++)DAY_DISPLAY[index]=TUE[index];break;
            case 
    0x04:     for(index=0;index<24;index++)DAY_DISPLAY[index]=WED[index];break;
            case 
    0x05:     for(index=0;index<24;index++)DAY_DISPLAY[index]=THU[index];break;
            case 
    0x06:     for(index=0;index<24;index++)DAY_DISPLAY[index]=FRI[index];break;
            case 
    0x07:     for(index=0;index<24;index++)DAY_DISPLAY[index]=SAT[index];break;
        }
    }


    //===========================================================///
    void update_time() interrupt 0
    {
        
    EX0 0;
        
    GET_TIME();
        
    IE0 0;
        
    EX0 1;

    }
    //===========================================================//
    void GET_T()
    {
         
    unsigned char temp;
        
    _RW 0;
        
    _RW 1;
        while(
    _INT);
        
    RD 0;
        
    temp P1;
        
    temp&=0x7f;
        
    RD 1;
        
    T_value[0]=seg_code[temp/10];
        
    T_value[1]=seg_code[temp%10];    


    Attached Files
    Last edited by chumanh; 19-05-2011, 13:35. Lý do: Upload Video Demo

  • #2
    cảm ơn anh rất nhiều đúng thứ mà em đang cần.tìm trên mạng toàn viết bằng asm.nhưng asm thì em chịu không biết gì luôn

    Comment


    • #3
      ngon đấy chú,cảm ơn nha.
      yahoo: boulevard.electronic
      Học tập & nghiên cứu

      phần mềm mình upload lên để chia sẻ:

      Comment


      • #4
        Phần DS1307 chưa đc ổn bạn ak, cái này khi mô phỏng pải lấy giờ của hệ thống ,tức là giờ hiển thị trên proteus phải giống giờ trên tray máy tính thì khi làm thực mới ổn,,,mất điện nó vẫn chạy, còn nếu code trên thì nó hok có chạy,,,,,mình chưa học VDK nhiều nên hok bik vầy đúng hok,
        Bạn nào pro sửa lại cho a em nè......

        Comment


        • #5
          hihi, cậu ko thấy là mình có 2 code ak, code thứ nhất là để dùng cho việc cấp thời gian đầu tiên cho DS1307, còn code thứ 2 là sau khi đã nạp và khởi động code thứ nhất ,việc cập nhật thời gian mình có nhiều phương pháp lắm nhưng chỉ đưa ra phương án là sử dụng việc nạp lần đầu cho DS1307 và lần thứ 2 thì bỏ nó đi bằng cách :

          nạp code lần đầu:

          sửa chỗ này:
          PHP Code:

              
          /********Time Default**************/
              
          _TIME.SEC 0x00 ;
              
          _TIME.MIN 0x00 ;
              
          _TIME.HOUR 0x12 ;
              
          _TIME.DAY  0x04 ;
              
          _TIME.DATE 0x10;
              
          _TIME.MONTH 0x04;
              
          _TIME.YEAR     0x11;
              
          RTC_INI();
              
          ////////////////////////////////////*/ 
          code nạp lần 2 sửa lại như thế này:

          PHP Code:

              
          /********Time Default**************
              _TIME.SEC = 0x00 ;
              _TIME.MIN = 0x00 ;
              _TIME.HOUR = 0x12 ;
              _TIME.DAY  = 0x04 ;
              _TIME.DATE = 0x10;
              _TIME.MONTH = 0x04;
              _TIME.YEAR     = 0x11;
              RTC_INI();
              ////////////////////////////////////*/ 
          nó hok chạy là do ko cập nhật thời gian trong protues, mà mình sử dụng ngắt để lấy thời gian vì vậy nó ko có chạy là đúng rồi, nhưng cậu xem video demo đó, rất ok, tắt nguồn cắm lại vẫn lưu giờ bình thường. Thân!

          Comment


          • #6
            Nguyên văn bởi chumanh Xem bài viết
            Xem chừng là diễn box 8051 đang sôi động với đồng hồ số và đo nhiệt độ các loại, hôm nay rảnh ngồi send cho ae nào quan tâm tới vấn đề này. Một cái project mình làm đầy đủ cả, bạn nào thích thì load về lắp chơi nhé.

            Screen Layout:



            Screen Protues:


            Demo Video:

            ////////////////////////////
            http://youtu.be/3xgErHkoIIo
            /////////////////////////

            Screen Capture: Attach
            File Download: Attach

            Code fix một số chỗ cho những ai cảm thấy code cũ có vấn đề
            PHP Code:
            /***********************************************************
            FileName: Hai-Clock-7segment.c
            MCU: 8051
            Xtal: 12Mhz
            App: Digital Clock    
            Author:     manhcuong.k08@gmail.com
            Creat Date: 4/5/2011
            Finish Date: 
            ************************************************************/
            #include <at89x52.h>
            /**********************define var,port*********************/
            #define data_port P2
            #define sel_port P0
            sbit _RW P3^6;            //
            sbit _RD P3^7;          // 
            sbit _INT P1^7;
            sbit MODE P3^3;    //external interrupt 1
            sbit DEC P3^4;    //DEC value
            sbit INC P3^5;    //increment value
            sbit SDA P3^0;    //I2c data line
            sbit SCL P3^1;    //I2c clock line

            //===================time variable============================//
            struct FREE_USER{
                                 
            unsigned char SEC;
                                 
            unsigned char MIN;
                                 
            unsigned char HOUR;
                                 
            unsigned char DAY;
                                 
            unsigned char DATE;
                                 
            unsigned char MONTH;
                                 
            unsigned char YEAR;
                                 } 
            _TIME ;
            //============================================================//
            //            Byte control Real Time Cloclk DS1307              //
            //                                                              //
            //============================================================//
            #define CONTROL_WRITE 0xd0
            #define CONTROL_READ 0xd1

            /*********************sub program**************************/

            //==========================================================//
            //                                                            //
            //                RTC class                                    //
            //==========================================================//
            unsigned char  RTC_READ(unsigned char ADRESS);
            void RTC_WRITE(unsigned char ADRESS,unsigned char DAT);
            void I2C_START();
            void I2C_STOP();
            void I2C_WRITE(unsigned char byte);
            unsigned char I2C_READ();
            void RTC_INI();
            //==========================================================//
            //                                                            //
            //                other                                        //
            //==========================================================//
            void DISPLAY_1__(unsigned char ARRAY[],unsigned char STATUS,bit istempsensor);
            void DISPLAY_2__(unsigned char ARRAY[]);
            void delay(int time);
            void GET_TIME();
            void TIMER0_ini();
            void TIMER1_ini();                
            void CHECK_DAY(bit get);
            void CONVERT();
            void GET_T();
            void DISPLAY_3__(unsigned char ARRAY[]);
            unsigned char code     seg_code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
            unsigned char code HELLO[] = {
                                            
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                            
            0x00,0x76,0x79,0x38,0x38,0x3f,0x00,0x00,
                                            
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
            unsigned char code MORNING[] = {
                                            
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                            
            0x39,0x74,0x77,0x5C,0x00,0x7C,0x1C,0x5C,0x10,
                                            
            0x00,0x6D,0x77,0x54,0x6F,
                                            
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
            unsigned char code AFTERNOON[] = {
                                            
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                            
            0x39,0x74,0x77,0x5C,0x00,0x7C,0x1C,0x5C,0x10,
                                            
            0x00,0x58,0x74,0x10,0x79,0x1c,
                                            
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
            //day on week==============================================
            unsigned char code SUN[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x39,0x74,0x1c,0x00,0x54,0x74,0x77,0x31,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };
            unsigned char code MON[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x07,0x76,0x3e,0x00,0x5b,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };    
            unsigned char code TUE[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x07,0x76,0x3e,0x00,0x4f,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };    
            unsigned char code WED[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x07,0x76,0x3e,0x00,0x66,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };    
            unsigned char code THU[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x07,0x76,0x3e,0x00,0x6d,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };    
            unsigned char code FRI[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x07,0x76,0x3e,0x00,0x7d,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };    
            unsigned char code SAT[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x07,0x76,0x3e,0x00,0x07,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };

            unsigned char TIME_DISPLAY[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };    
            unsigned char DATE_DISPLAY[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };    
            unsigned char DAY_DISPLAY[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };    
            unsigned char code T_SENSOR[] = {
                                                
            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x63,0x39,0x00,0x00,
                                                
            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                
            };    
            unsigned char T_value[2];    
            #define SHIFT 0x00
            #define STOP 0x01
            #define CLEAR 0x02
            #define TIME_STATUS 1080

            int GLOBAL_DISPLAY=0;
            unsigned char IN_VISIBLE;
            unsigned char CONTROL_INVISIBLE=0;
            unsigned char SHIFT_CURCOR;
            unsigned char counter_status;
            /********************************************************/
            /*            Main Program                                */
            /********************************************************/
            void main()
            {

                
            /********Time Default**************
                _TIME.SEC = 0x00 ;
                _TIME.MIN = 0x00 ;
                _TIME.HOUR = 0x12 ;
                _TIME.DAY  = 0x04 ;
                _TIME.DATE = 0x10;
                _TIME.MONTH = 0x04;
                _TIME.YEAR     = 0x11;
                RTC_INI();
                ////////////////////////////////////*/
                
            _RD 1;
                
            _RW 1;
                
            TIMER0_ini();
                
            TIMER1_ini();
                
            //enable global interrupt
                
            EX1 1;    //enable external interrupt 1
                
            IT1 1;    //
                
            EX0 1;    //enable external interrupt 1
                
            IT0 1;    //
                
            EA 1;
                
            TR0 1;    //timer0 run
                
            PT1 =1;
                
            PX0 1;
                
                while(
            1)
                {        
                
            //    GET_TIME();DISPLAY_1__(TIME_DISPLAY,STOP);
                    
            switch(GLOBAL_DISPLAY)
                    {
                         case 
            0:    DISPLAY_1__(HELLO,SHIFT,0);while(GLOBAL_DISPLAY<100)DISPLAY_1__(HELLO,STOP,0);DISPLAY_1__(HELLO,CLEAR,0);break;
                        case 
            140:  DISPLAY_1__(TIME_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<600)DISPLAY_1__(TIME_DISPLAY,STOP,0);DISPLAY_1__(TIME_DISPLAY,CLEAR,0);break;
                        case 
            620:  if((_TIME.HOUR>=0)&&(_TIME.HOUR<12))DISPLAY_3__(MORNING);else if(_TIME.HOUR>=12)DISPLAY_3__(AFTERNOON);break;
                        case 
            700:  CHECK_DAY(1);DISPLAY_1__(DAY_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<800){CHECK_DAY(1);DISPLAY_1__(DAY_DISPLAY,STOP,0);}DISPLAY_1__(DAY_DISPLAY,CLEAR,0);break;
                        case 
            820:  DISPLAY_1__(DATE_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<920)DISPLAY_1__(DATE_DISPLAY,STOP,0);DISPLAY_1__(DATE_DISPLAY,CLEAR,0);break;
                        case 
            950:  GET_T();DISPLAY_1__(T_SENSOR,SHIFT,1);while(GLOBAL_DISPLAY<1050)DISPLAY_1__(T_SENSOR,STOP,1);DISPLAY_1__(T_SENSOR,CLEAR,1);break;
                        default:     {;}break;
                    }    
                }
            }
             
            //==========================================================//
            //                                                            //
            //                DISPLAY_3__                                     //
            //==========================================================//
            void DISPLAY_3__(unsigned char ARRAY[])
            {
                 
            unsigned char counter_char=0,index,time_shift,counter;
                 
            unsigned char __SELECT__ ;
                 while(ARRAY[
            counter_char]!=0xff)
                             
            counter_char++;
                 for(
            index=0;index<counter_char-8;index++)
                        {
                            for(
            time_shift=0;time_shift<20;time_shift++)
                            {    
                                
            __SELECT__ 0x7f;
                                for(
            counter=0;counter<8;counter++)
                                {
                                    
            data_port = ARRAY[counter+index];
                                    
            sel_port __SELECT__;
                                    
            delay(7);
                                    
            sel_port 0xff;     //disable all led
                                    
            data_port 0x00;    //disable all led
                                    
            __SELECT__ >>= 1;
                                    
            __SELECT__ |= 0x80;
                                }
                            }
                        }
            }
             
            //==========================================================//
            //                                                            //
            //                DISPLAY_2__                                     //
            //==========================================================//
            void DISPLAY_2__(unsigned char ARRAY[])
            {
                    
            unsigned char counter;
                     
            unsigned char __SELECT__=0x7f ;
                                       for(
            counter=0;counter<8;counter++)
                                            {
                                                
            sel_port __SELECT__;
                                                
            sel_port |= IN_VISIBLE;
                                                
            data_port = ARRAY[counter+8];
                                                
            delay(7);
                                                
            sel_port 0xff;     //disable all led
                                                
            data_port 0x00;    //disable all led
                                                
            __SELECT__ >>= 1;
                                                
            __SELECT__ |= 0x80;
                                            }
            }
             
            //==========================================================//
            //                                                            //
            //                DISPLAY_1__                                     //
            //==========================================================//    
            void DISPLAY_1__(unsigned char ARRAY[],unsigned char _STATUS_,bit istempsensor)
            {
                 
            unsigned char counter_char=0,index,time_shift,counter;
                 
            unsigned char __SELECT__ ;
                 while(ARRAY[
            counter_char]!=0xff)
                             
            counter_char++;
                 switch(
            _STATUS_)
                 {
                    
                    case 
            SHIFT: {
                                    for(
            index=0;index<counter_char-16;index++)
                                    {
                                         for(
            time_shift=0;time_shift<20;time_shift++)
                                        {
                                            
            __SELECT__ 0x7f;
                                             for(
            counter=0;counter<8;counter++)
                                            {
                                                if(
            istempsensor)
                                                {
                                                     if(
            counter+index==0x0a)
                                                    
            data_port T_value[0];
                                                    else if(
            counter+index==0x0b)
                                                    
            data_port T_value[1];
                                                    else
                                                    
            data_port = ARRAY[counter+index];
                                                }
                                                else 
                                                
            data_port = ARRAY[counter+index];
                                                
            sel_port __SELECT__;
                                                
            delay(7);
                                                
            sel_port 0xff;     //disable all led
                                                
            data_port 0x00;    //disable all led
                                                
            __SELECT__ >>= 1;
                                                
            __SELECT__ |= 0x80;
                                            }
                                        }
                                    }
                                break;
                                }
                    case 
            STOP:    {
                                    
            __SELECT__ 0x7f;
                                       for(
            counter=0;counter<8;counter++)
                                            {
                                                if(
            istempsensor)
                                                {
                                                     if(
            counter+8==0x0a)
                                                    
            data_port T_value[0];
                                                    else if(
            counter+8==0x0b)
                                                    
            data_port T_value[1];
                                                    else
                                                    
            data_port = ARRAY[counter+8];
                                                }
                                                else
                                                 
            data_port = ARRAY[counter+8];
                                                
            sel_port __SELECT__;
                                                
            delay(7);
                                                
            sel_port 0xff;     //disable all led
                                                
            data_port 0x00;    //disable all led
                                                
            __SELECT__ >>= 1;
                                                
            __SELECT__ |= 0x80;
                                            }
                                        break;
                                        }
                    case 
            CLEAR: {
                                    for(
            index=8;index<counter_char-8;index++)
                                    {
                                         for(
            time_shift=0;time_shift<20;time_shift++)
                                        {
                                            
            __SELECT__ 0x7f;
                                             for(
            counter=0;counter<8;counter++)
                                            {
                                                if(
            istempsensor)
                                                {
                                                     if(
            counter+index==0x0a)
                                                    
            data_port T_value[0];
                                                    else if(
            counter+index==0x0b)
                                                    
            data_port T_value[1];
                                                    else
                                                    
            data_port = ARRAY[counter+index];
                                                }
                                                else
                                                 
            data_port = ARRAY[counter+index];
                                                
            sel_port __SELECT__;
                                                
            delay(7);
                                                
            sel_port 0xff;     //disable all led
                                                
            data_port 0x00;    //disable all led
                                                
            __SELECT__ >>= 1;
                                                
            __SELECT__ |= 0x80;
                                            }
                                        }
                                    }
                                break;
                                }
                                    
                 }

            }
             
            //==========================================================//
            //                                                            //
            //                delay                                     //
            //==========================================================//         
            void delay(int time)
            {
                
            int i,j;
                for(
            i=0;i<time;i++)
                     for(
            j=0;j<time;j++)
                    {;}
            }
            //==========================================================//
            //                                                            //
            //                I2c_START                                     //
            //==========================================================//
            void I2C_START()
            {
                 
            SDA 1;
                
            SCL 1;
                
            SDA 0;
                
            SCL 0;
                
            SDA 1;
            }
            //==========================================================//
            //                                                            //
            //                I2c_STOP                                     //
            //==========================================================//
            void I2C_STOP()
            {
                
            SDA 0;
                
            SCL 1;
                
            SDA 1;
            }
            //==========================================================//
            //                                                            //
            //                I2c_WRITE                                     //
            //==========================================================//
            void I2C_WRITE(unsigned char byte)
            {
                
            unsigned char counter;
                for(
            counter 0;counter<8;counter++)
                {
                     if(
            byte&0x80)
                        
            SDA=1;
                    else
                        
            SDA=0;
                    
            SCL 1;
                    
            SCL 0;
                    
            byte<<=1;
                }
                    
            SDA 1;
                    
            SCL 1;
                    
            SCL 0;
                    
            }
            //==========================================================//
            //                                                            //
            //                I2c_READ                                     //
            //==========================================================//
            unsigned char I2C_READ()
            {
                
            unsigned char return_value=0x00,counter=8;
                    while(
            counter>0)
                    {
                         
            SCL=1;
                        
            return_value<<=1;
                        
            return_value|=SDA;
                        
            SCL=0;
                        
            counter--;    
                    }

                    
            SDA 1
                    
            SCL 1;
                    
            SCL 0;
                    
            SDA 1
                    return 
            return_value;
                    
            }
            //==========================================================//
            //                                                            //
            //                RTC_WRITE                                     //
            //==========================================================//
            void RTC_WRITE(unsigned char ADDRESS,unsigned char DAT)
            {
                
            I2C_START();                    //i2c start
                
            I2C_WRITE(CONTROL_WRITE);       //send control byte
                
            I2C_WRITE(ADDRESS);            //send address byte
                
            I2C_WRITE(DAT);                    //send data byte
                
            I2C_STOP();                      //i2c stop

            }
            //==========================================================//
            //                                                            //
            //                RTC_READ                                     //
            //==========================================================//
            unsigned char RTC_READ(unsigned char ADDRESS)
            {
                
            unsigned char return_value=0x00;
                
            I2C_START();
                
            I2C_WRITE(CONTROL_WRITE); //send byte control write
                
            I2C_WRITE(ADDRESS); // send byte address
                
            I2C_START(); // restart
                
            I2C_WRITE(CONTROL_READ); // send byte control read
                
            return_value I2C_READ(); //read from RTC
                
            I2C_STOP();
                return 
            return_value;
            }
            //==========================================================//
            //                                                            //
            //                RTC_INI                                     //
            //==========================================================//
            void RTC_INI()    
            {          
            //ADDRESS,DATA//
                
            RTC_WRITE(0x00,_TIME.SEC);
                
            RTC_WRITE(0x01,_TIME.MIN);
                
            RTC_WRITE(0x02,_TIME.HOUR);
                
            RTC_WRITE(0x03,_TIME.DAY);
                
            RTC_WRITE(0x04,_TIME.DATE);
                
            RTC_WRITE(0x05,_TIME.MONTH);
                
            RTC_WRITE(0x06,_TIME.YEAR);
                
            RTC_WRITE(0x07,0x10);//OUT = 1,SOUT = 1;
            }
            //==========================================================//
            //                                                            //
            //                GET_TIME                                    //
            //==========================================================//
            void GET_TIME()
            {
                 
                
            _TIME.SEC RTC_READ(0x00);    //GET SECOND
                
            _TIME.MIN RTC_READ(0x01);    //GET MIN
                
            _TIME.HOUR RTC_READ(0x02)&0x3f;    //GET HOUR
                
            _TIME.DAY RTC_READ(0x03);    //GET DAY
                
            _TIME.DATE RTC_READ(0x04);    //GET DATE
                
            _TIME.MONTH RTC_READ(0x05);    //GET MONTH
                
            _TIME.YEAR RTC_READ(0x06);    //GET YEAR
                
            CONVERT();
            }
                                                                               
            //==========================================================//
            //                                                            //
            //                Timer0_ini                                    //
            //==========================================================//
            void TIMER0_ini()
            {
                
            TMOD 0x01    ;//timer 0 16bit reload
                
            TH0 0x00;
                
            TL0 0x00;
                
            TF0 0;
                
            TR0 0;
                
            ET0 1;    //enable timer0 interrupt
                
            }
            //==========================================================//
            //                                                            //
            //                CONVERT                                    //
            //==========================================================//
            void CONVERT()
            {
            unsigned char temp,index=15;
             
            //GET SECCOND
                
            temp _TIME.SEC;
                
            temp&=0x0f;        //get the unit
                
            TIME_DISPLAY[index]=seg_code[temp];
                
            index--;
                
            temp _TIME.SEC;
                
            temp&=0xf0;        //get the tens
                
            temp>>=4;
                
            TIME_DISPLAY[index]=seg_code[temp];
                
            index--;
            //SPACER
                
            TIME_DISPLAY[index]=0x40;    //
                
            index--;
             
            //GET MIN
                
            temp _TIME.MIN;
                
            temp&=0x0f;        //get the unit
                
            TIME_DISPLAY[index]=seg_code[temp];
                
            index--;
                
            temp _TIME.MIN;
                
            temp&=0xf0;        //get the tens
                
            temp>>=4;
                
            TIME_DISPLAY[index]=seg_code[temp];
                
            index--;
            //SPACER
                
            TIME_DISPLAY[index]=0x40;    //
                
            index--;
             
            //GET HOUR
                
            temp _TIME.HOUR;
                
            temp&=0x0f;        //get the unit
                
            TIME_DISPLAY[index]=seg_code[temp];
                
            index--;
                
            temp _TIME.HOUR;
                
            temp&=0xf0;        //get the tens
                
            temp>>=4;
                
            TIME_DISPLAY[index]=seg_code[temp];

                
            index=15;
            //GET YEAR
                
            temp _TIME.YEAR;
                
            temp&=0x0f;        //get the unit
                
            DATE_DISPLAY[index]=seg_code[temp];
                
            index--;
                
            temp _TIME.YEAR;
                
            temp&=0xf0;        //get the tens
                
            temp>>=4;
                
            DATE_DISPLAY[index]=seg_code[temp];
                
            index--;
            //SPACER
                
            DATE_DISPLAY[index]=0x40;    //
                
            index--;
             
            //GET MONTH
                
            temp _TIME.MONTH;
                
            temp&=0x0f;        //get the unit
                
            DATE_DISPLAY[index]=seg_code[temp];
                
            index--;
                
            temp _TIME.MONTH;
                
            temp&=0xf0;        //get the tens
                
            temp>>=4;
                
            DATE_DISPLAY[index]=seg_code[temp];
                
            index--;
            //SPACER
                
            DATE_DISPLAY[index]=0x40;    //
                
            index--;
             
            //GET DATE
                
            temp _TIME.DATE;
                
            temp&=0x0f;        //get the unit
                
            DATE_DISPLAY[index]=seg_code[temp];
                
            index--;
                
            temp _TIME.DATE;
                
            temp&=0xf0;        //get the tens
                
            temp>>=4;
                
            DATE_DISPLAY[index]=seg_code[temp];
            }
            //==========================================================//
            //                                                            //
            //                Timer1_ini                            //
            //==========================================================//
            void TIMER1_ini()
            {
                
            TMOD |= 0x10;    //timer 1 16bit reload
                
            TH1 0x00;
                
            TL1 0x00;
                
            TF1 0;
                
            TR1 0;
                
            ET1 1;
                
            }
            //==========================================================//
            //                                                            //
            //                Timer0_interrupt                                    //
            //==========================================================//
            void TIMER0_interrupt() interrupt 1
            {
                
            TR0 0;
                
            TF0 0;
                
            TH0 0;
                
            TL0 0;
                
            GLOBAL_DISPLAY++;
                if(
            GLOBAL_DISPLAY==TIME_STATUS)
                        
            GLOBAL_DISPLAY=0;
                
            TR0 1;
                
            }
            //==========================================================//
            //                                                            //
            //                Timer1_interrupt                            //
            //==========================================================//
            void TIMER1_interrupt()    interrupt 3
            {
                
            TR1 0;    //stop timer1
                
            TF1 0;    //clear TF1
                
            TH1 0;
                
            TL1 1;
                
            CONTROL_INVISIBLE++;
                if(
            CONTROL_INVISIBLE==5)
                {
                    
            IN_VISIBLE 0x00;
                }
                else if(
            CONTROL_INVISIBLE==10)
                {
                    
            IN_VISIBLE SHIFT_CURCOR;
                    
            CONTROL_INVISIBLE=0;
                 }
                else {;}
                
            TR1 1;
                
            }
            //==========================================================//
            //                                                            //
            //                External Interrupt 1                        //
            //==========================================================//
            void EX1_interrupt()interrupt 2
            {
                
            unsigned char unit,tens;
                
            EX1 0//    disable ex interrupt 1
                
            EX0 0//    disable ex interrupt 0
                
            counter_status=0x00;
                
            TR1 1;    //enable TIMER1
                
            IN_VISIBLE 0xc0;
                
            SHIFT_CURCOR =       IN_VISIBLE;
                
            CONTROL_INVISIBLE=0;
            //    GET_TIME();
                
            while(MODE==0)DISPLAY_2__(TIME_DISPLAY);
                while(
            counter_status!=0x07)
                {
                    
                     switch(
            counter_status)
                    {
                         case 
            0x00:    {
                                        while(
            MODE)
                                        {
                                             if(
            INC==0)
                                            {
                                                 while(
            INC==0)DISPLAY_2__(TIME_DISPLAY);
                                                
            unit _TIME.HOUR;
                                                
            unit &=0x0f;
                                                
            tens _TIME.HOUR;
                                                
            tens >>= 4;
                                                if(
            tens!=2)
                                                {
                                                        
            unit++;
                                                        if(
            unit==10)
                                                        {
                                                            
            tens++;
                                                            
            unit=0;
                                                        }
                                                }
                                                else
                                                {
                                                     
            unit++;
                                                    if(
            unit==4)
                                                    {
                                                        
            tens=0;
                                                        
            unit 0;
                                                    }
                                                    
                                                }
                                                
            _TIME.HOUR tens;
                                                
            _TIME.HOUR <<=4;
                                                
            _TIME.HOUR |= unit;
                                                
            CONVERT();
                                            }
                                            if(
            DEC==0)
                                            {
                                                while(
            DEC==0)DISPLAY_2__(TIME_DISPLAY);
                                                
            unit _TIME.HOUR;
                                                
            unit &=0x0f;
                                                
            tens _TIME.HOUR;
                                                
            tens >>= 4;
                                                if(
            tens!=0)
                                                {
                                                        
            unit--;
                                                        if(
            unit==0xff)
                                                        {
                                                            
            tens--;
                                                            
            unit 0x09;
                                                        }
                                                }
                                                else
                                                {
                                                     
            unit--;
                                                    if(
            unit==0xff)
                                                    {
                                                        
            tens 0x02;
                                                        
            unit 0x03;
                                                    }
                                                    
                                                }
                                                
            _TIME.HOUR tens;
                                                
            _TIME.HOUR <<=4;
                                                
            _TIME.HOUR |= unit;
                                                
            CONVERT();
                                            }
                                            
            DISPLAY_2__(TIME_DISPLAY);
                                        }
                                        while(
            MODE==0){DISPLAY_2__(TIME_DISPLAY);}
                                        while(
            IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
                                        
            IN_VISIBLE>>=3;
                                        
            SHIFT_CURCOR IN_VISIBLE;

                                        
            counter_status++;
                                        break;
                                    }
                        case 
            0x01:    {
                                        while(
            MODE)
                                        {
                                             if(
            INC==0)
                                            {
                                                 while(
            INC==0)DISPLAY_2__(TIME_DISPLAY);
                                                
            unit _TIME.MIN;
                                                
            unit &=0x0f;
                                                
            tens _TIME.MIN;
                                                
            tens >>= 4;
                                                
            unit++;
                                                if(
            unit==10)
                                                {
                                                    
            tens++;
                                                    
            unit=0;
                                                }
                                                if(
            tens==6)
                                                     
            tens=0;
                                                
            _TIME.MIN tens;
                                                
            _TIME.MIN <<=4;
                                                
            _TIME.MIN |= unit;
                                                
            CONVERT();
                                            }
                                            if(
            DEC==0)
                                            {
                                                while(
            DEC==0)DISPLAY_2__(TIME_DISPLAY);
                                                
            unit _TIME.MIN;
                                                
            unit &=0x0f;
                                                
            tens _TIME.MIN;
                                                
            tens >>= 4;
                                                
            unit--;
                                                if(
            unit==0xff)
                                                {
                                                    
            tens--;
                                                    
            unit=9;
                                                }
                                                if(
            tens==0xff)
                                                     
            tens=5;
                                                
            _TIME.MIN tens;
                                                
            _TIME.MIN <<=4;
                                                
            _TIME.MIN |= unit;
                                                
            CONVERT();
                                            }
                                            
            DISPLAY_2__(TIME_DISPLAY);
                                        }
                                        while(
            MODE==0){DISPLAY_2__(TIME_DISPLAY);}
                                        while(
            IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
                                        
            IN_VISIBLE>>=3;
                                        
            SHIFT_CURCOR IN_VISIBLE;
                                        
            counter_status++;
                                        break;
                                    }
                        case 
            0x02:    {
                                        while(
            MODE)
                                        {
                                             if(
            INC==0)
                                            {
                                                 while(
            INC==0)DISPLAY_2__(TIME_DISPLAY);
                                                
            unit _TIME.SEC;
                                                
            unit &=0x0f;
                                                
            tens _TIME.SEC;
                                                
            tens >>= 4;
                                                
            unit++;
                                                if(
            unit==10)
                                                {
                                                    
            tens++;
                                                    
            unit=0;
                                                }
                                                if(
            tens==6)
                                                     
            tens=0;
                                                
            _TIME.SEC tens;
                                                
            _TIME.SEC <<=4;
                                                
            _TIME.SEC|= unit;
                                                
            CONVERT();
                                            }
                                            if(
            DEC==0)
                                            {
                                                while(
            DEC==0)DISPLAY_2__(TIME_DISPLAY);
                                                
            unit _TIME.SEC;
                                                
            unit &=0x0f;
                                                
            tens _TIME.SEC;
                                                
            tens >>= 4;
                                                
            unit--;
                                                if(
            unit==0xff)
                                                {
                                                    
            tens--;
                                                    
            unit=9;
                                                }
                                                if(
            tens==0xff)
                                                     
            tens=5;
                                                
            _TIME.SEC tens;
                                                
            _TIME.SEC <<=4;
                                                
            _TIME.SEC|= unit;
                                                
            CONVERT();
                                            }
                                          
            DISPLAY_2__(TIME_DISPLAY);
                                        }
                                        while(
            MODE==0){DISPLAY_2__(TIME_DISPLAY);}
                                        while(
            IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
                                        
            IN_VISIBLE=0xc0;
                                        
            SHIFT_CURCOR IN_VISIBLE;
                                        
            counter_status++;
                                        break;
                                    }
                        case 
            0x03:    {
                                        while(
            MODE)
                                        {
                                             if(
            INC==0)
                                            {
                                                 while(
            INC==0)DISPLAY_2__(DATE_DISPLAY);
                                                
            unit _TIME.DATE;
                                                
            unit &=0x0f;
                                                
            tens _TIME.DATE;
                                                
            tens >>= 4;
                                                if(
            _TIME.MONTH%2==1)
                                                {
                                                     if(
            tens<3)
                                                    {
                                                        
            unit++;
                                                        if(
            unit==10)
                                                        {
                                                            
            tens++;
                                                            
            unit=0;
                                                        }
                                                    }
                                                    else
                                                    {
                                                         
            unit++;
                                                        if(
            unit==2)
                                                        {
                                                            
            tens=0;
                                                            
            unit=0;
                                                        }
                                                    }
                                                }
                                                else if(
            _TIME.MONTH%2==0)
                                                {
                                                     if(
            tens<3)
                                                    {
                                                        
            unit++;
                                                        if(
            unit==10)
                                                        {
                                                            
            tens++;
                                                            
            unit=0;
                                                        }
                                                    }
                                                    else
                                                    {
                                                         
            unit++;
                                                        if(
            unit==1)
                                                        {
                                                            
            tens=0;
                                                            
            unit=0;
                                                        }
                                                    }
                                                }
                                                
            _TIME.DATE tens;
                                                
            _TIME.DATE <<=4;
                                                
            _TIME.DATE |= unit;
                                                
            CONVERT();
                                            }
                                            if(
            DEC==0)
                                            {
                                                while(
            DEC==0)DISPLAY_2__(DATE_DISPLAY);
                                                
            unit _TIME.DATE;
                                                
            unit &=0x0f;
                                                
            tens _TIME.DATE;
                                                
            tens >>= 4;
                                                if(
            _TIME.MONTH%2==1)
                                                {
                                                     
            unit--;
                                                    if(
            unit==0xff)
                                                    {
                                                        
            tens--;
                                                        
            unit=9;
                                                    }
                                                    if(
            tens==0xff)
                                                    {
                                                         
            tens=3;
                                                        
            unit=1;
                
                                                    }
                                                }
                                                else if(
            _TIME.MONTH%2==0)
                                                {
                                                     
            unit--;
                                                    if(
            unit==0xff)
                                                    {
                                                        
            tens--;
                                                        
            unit=9;
                                                    }
                                                    if(
            tens==0xff)
                                                    {
                                                         
            tens=3;
                                                        
            unit=0;
                
                                                    }
                                                }
                                                
            _TIME.DATE tens;
                                                
            _TIME.DATE <<=4;
                                                
            _TIME.DATE |= unit;
                                                
            CONVERT();
                                            }
                                            
            DISPLAY_2__(DATE_DISPLAY);
                
                                        }
                                        while(
            MODE==0){DISPLAY_2__(DATE_DISPLAY); }
                                        while(
            IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
                                        
            IN_VISIBLE>>=3;
                                        
            SHIFT_CURCOR IN_VISIBLE;
                                        
            counter_status++;
                                        break;
                                    }

                        case 
            0x04:    {
                                        while(
            MODE)
                                        {
                                             if(
            INC==0)
                                            {
                                                 while(
            INC==0)DISPLAY_2__(DATE_DISPLAY);
                                                
            unit _TIME.MONTH;
                                                
            unit &=0x0f;
                                                
            tens _TIME.MONTH;
                                                
            tens >>= 4;
                                                if(
            tens!=1)
                                                {
                                                    
            unit++;
                                                    if(
            unit==10)
                                                    {
                                                        
            tens++;
                                                        
            unit=0;
                                                    }
                                                }
                                                else
                                                {
                                                     
            unit++;
                                                    if(
            unit==3)
                                                    {
                                                        
            tens=0;
                                                        
            unit=0;
                                                    }
                                                }
                                                
            _TIME.MONTH tens;
                                                
            _TIME.MONTH <<=4;
                                                
            _TIME.MONTH |= unit;
                                                
            CONVERT();
                                            }
                                            if(
            DEC==0)
                                            {
                                                while(
            DEC==0)DISPLAY_2__(DATE_DISPLAY);
                                                
            unit _TIME.MONTH;
                                                
            unit &=0x0f;
                                                
            tens _TIME.MONTH;
                                                
            tens >>= 4;
                                                
            unit--;
                                                if(
            unit==0xff)
                                                {
                                                    
            tens--;
                                                    
            unit=9;
                                                }
                                                if(
            tens==0xff)
                                                {
                                                     
            tens=1;
                                                    
            unit=2;

                                                }
                                                
            _TIME.MONTH tens;
                                                
            _TIME.MONTH <<=4;
                                                
            _TIME.MONTH |= unit;
                                                
            CONVERT();
                                            }
                                            
            DISPLAY_2__(DATE_DISPLAY);
                
                                        }
                                        while(
            MODE==0){DISPLAY_2__(DATE_DISPLAY);}
                                        while(
            IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
                                        
            IN_VISIBLE>>=3;
                                        
            SHIFT_CURCOR IN_VISIBLE;
                                        
            counter_status++;
                                        break;
                                    }
                                    
                        case 
            0x05:    {
                                        while(
            MODE)
                                        {
                                             if(
            INC==0)
                                            {
                                                 while(
            INC==0)DISPLAY_2__(DATE_DISPLAY);
                                                
            unit _TIME.YEAR;
                                                
            unit &=0x0f;
                                                
            tens _TIME.YEAR;
                                                
            tens >>= 4;
                                                
            unit++;
                                                if(
            unit==10)
                                                {
                                                    
            tens++;
                                                    
            unit=0;
                                                }
                                                if(
            tens==9)
                                                     
            tens=0;
                                                
            _TIME.YEAR tens;
                                                
            _TIME.YEAR <<=4;
                                                
            _TIME.YEAR |= unit;
                                                
            CONVERT();
                                            }
                                            if(
            DEC==0)
                                            {
                                                while(
            DEC==0)DISPLAY_2__(DATE_DISPLAY);
                                                
            unit _TIME.YEAR;
                                                
            unit &=0x0f;
                                                
            tens _TIME.YEAR;
                                                
            tens >>= 4;
                                                
            unit--;
                                                if(
            unit==0xff)
                                                {
                                                    
            tens--;
                                                    
            unit=9;
                                                }
                                                if(
            tens==0xff)
                                                     
            tens=9;
                                                
            _TIME.YEAR tens;
                                                
            _TIME.YEAR <<=4;
                                                
            _TIME.YEAR |= unit;
                                                
            CONVERT();
                                            }
                                            
            DISPLAY_2__(DATE_DISPLAY);
                
                                        }
                                        while(
            MODE==0){DISPLAY_2__(DATE_DISPLAY);}
                                        while(
            IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
                                        
            IN_VISIBLE 0xff;
                                        
            SHIFT_CURCOR IN_VISIBLE;
                                        
            counter_status++;
                                        break;
                                        
                                    }
                        case 
            0x06:    {
                                        while(
            MODE)
                                        {
                                            
            CHECK_DAY(0);
                                             if(
            INC==0)
                                            {
                                                 while(
            INC==0)DISPLAY_2__(DAY_DISPLAY);
                                                
            _TIME.DAY++;
                                                if(
            _TIME.DAY==8)
                                                    
            _TIME.DAY=1;
                                                
            CHECK_DAY(0);
                                            }
                                            if(
            DEC==0)
                                            {
                                                while(
            DEC==0)DISPLAY_2__(DAY_DISPLAY);
                                                
            _TIME.DAY--;
                                                if(
            _TIME.DAY==0xff)
                                                    
            _TIME.DAY=7;
                                                
            CHECK_DAY(0);
                                            }
                                            
            DISPLAY_2__(DAY_DISPLAY);
                
                                        }
                                        while(
            MODE==0){DISPLAY_2__(DAY_DISPLAY);}
                                        while(
            IN_VISIBLE==0x00){DISPLAY_2__(DAY_DISPLAY);}
                                        
            SHIFT_CURCOR IN_VISIBLE;
                                        
            counter_status++;
                                        break;
                                        
                                    }
                                    
                    }
                    
            RTC_INI();
                }
                
            IE1 0;//clear external interrupt 1 flag
                
            TR1 0;
                
            EX0 1;
                
            EX1 1;
            }
            //==========================================================//
            //                                                            //
            //                CHECK_DAY                                    //
            //==========================================================//
            void CHECK_DAY(bit get)
            {
                
            unsigned char index,DAY;
                if(
            get)
                
            DAY RTC_READ(0x03);
                else
                
            DAY _TIME.DAY;
                switch(
            DAY)
                {
                     case 
            0x01:     for(index=0;index<24;index++)DAY_DISPLAY[index]=SUN[index];break;
                    case 
            0x02:     for(index=0;index<24;index++)DAY_DISPLAY[index]=MON[index];break;
                    case 
            0x03:     for(index=0;index<24;index++)DAY_DISPLAY[index]=TUE[index];break;
                    case 
            0x04:     for(index=0;index<24;index++)DAY_DISPLAY[index]=WED[index];break;
                    case 
            0x05:     for(index=0;index<24;index++)DAY_DISPLAY[index]=THU[index];break;
                    case 
            0x06:     for(index=0;index<24;index++)DAY_DISPLAY[index]=FRI[index];break;
                    case 
            0x07:     for(index=0;index<24;index++)DAY_DISPLAY[index]=SAT[index];break;
                }
            }


            //===========================================================///
            void update_time() interrupt 0
            {
                
            EX0 0;
                
            GET_TIME();
                
            IE0 0;
                
            EX0 1;

            }
            //===========================================================//
            void GET_T()
            {
                 
            unsigned char temp;
                
            _RW 0;
                
            _RW 1;
                while(
            _INT);
                
            RD 0;
                
            temp P1;
                
            temp&=0x7f;
                
            RD 1;
                
            T_value[0]=seg_code[temp/10];
                
            T_value[1]=seg_code[temp%10];    


            nâng cấp đề tài này lên giao tiếp và hiển thị nhiệt độ lên máy tính luôn đi bác
            dù sao cũng thanks bác nhé .


            Comment


            • #7
              Nguyên văn bởi dientuvui25 Xem bài viết
              nâng cấp đề tài này lên giao tiếp và hiển thị nhiệt độ lên máy tính luôn đi bác
              dù sao cũng thanks bác nhé .
              Giao tiếp với máy tính thì đơn giản thôi, nhưng mình làm cái đó ko có mục đích nên cũng ko ham lắm , bạn nào muốn giao tiếp với máy tính thì cứ trao đổi, nâng cấp nó lên

              Comment


              • #8
                Nguyên văn bởi chumanh Xem bài viết
                hihi, cậu ko thấy là mình có 2 code ak, code thứ nhất là để dùng cho việc cấp thời gian đầu tiên cho DS1307, còn code thứ 2 là sau khi đã nạp và khởi động code thứ nhất ,việc cập nhật thời gian mình có nhiều phương pháp lắm nhưng chỉ đưa ra phương án là sử dụng việc nạp lần đầu cho DS1307 và lần thứ 2 thì bỏ nó đi bằng cách :

                nạp code lần đầu:

                sửa chỗ này:
                PHP Code:

                    
                /********Time Default**************/
                    
                _TIME.SEC 0x00 ;
                    
                _TIME.MIN 0x00 ;
                    
                _TIME.HOUR 0x12 ;
                    
                _TIME.DAY  0x04 ;
                    
                _TIME.DATE 0x10;
                    
                _TIME.MONTH 0x04;
                    
                _TIME.YEAR     0x11;
                    
                RTC_INI();
                    
                ////////////////////////////////////*/ 
                code nạp lần 2 sửa lại như thế này:

                PHP Code:

                    
                /********Time Default**************
                    _TIME.SEC = 0x00 ;
                    _TIME.MIN = 0x00 ;
                    _TIME.HOUR = 0x12 ;
                    _TIME.DAY  = 0x04 ;
                    _TIME.DATE = 0x10;
                    _TIME.MONTH = 0x04;
                    _TIME.YEAR     = 0x11;
                    RTC_INI();
                    ////////////////////////////////////*/ 
                nó hok chạy là do ko cập nhật thời gian trong protues, mà mình sử dụng ngắt để lấy thời gian vì vậy nó ko có chạy là đúng rồi, nhưng cậu xem video demo đó, rất ok, tắt nguồn cắm lại vẫn lưu giờ bình thường. Thân!
                Khi lần đầu tiên khởi động DS1307 thì nó chưa thể chạy ngay đc vì trong thanh ghi giây có bit ngoài cùng: bít này nếu bằng 1 thì DS1307 sẽ ở trạng thái treo nên cần phải xóa bit này trước nó mới chạy đc. Dễ nhận thấy là khi cấp nguồn lần đầu tiên thì sẽ hiện ra giờ là: 00:00:80 nhiều người tưởng là mạch bị sai gì nhưng thực tế thì phần cứng như thế là OK rồi. Số 80 đổi ra số nhị phân là 1000|0000 do đó để cho đồng hồ chạy đc thì nên viết thêm cái hàm chỉnh giây nữa (reset giây về 00) là đảm bảo mạch chạy, dễ chỉnh mà không phải nạp chíp 2 lần.

                Comment


                • #9
                  Mình có cái đồng hồ này nữa.
                  http://www.mediafire.com/?9a51ekf9ydmcbaa
                  Mua bán thiết bị điện công nghiệp tại Hà Nội, toàn quốc.
                  http://diencongnghiep360.com/
                  http://tudienhathe.vn/

                  Comment


                  • #10
                    lên nữa nào.....

                    Comment


                    • #11
                      Tìm link kiện đo nhiệt độ và độ ẩm

                      Xin chào,

                      Mình đang tìm đồng hồ hiển thị nhiệt độ+ độ ẩm dùng để lắp vào máy ấp trứng. Ở sài gòn chỗ nào bán các thiết bị này chỉ mình với.

                      Cảm ơn!

                      Comment


                      • #12
                        đây phải led anode chung ko vậy
                        mà sao mạch chạy dc 1 chu kì thì tắt lun, ko thấy hiển thị j hết
                        Mail:

                        Comment


                        • #13
                          up
                          .......................................
                          Mail:

                          Comment


                          • #14
                            Nguyên văn bởi chumanh Xem bài viết
                            Xem chừng là diễn box 8051 đang sôi động với đồng hồ số và đo nhiệt độ các loại, hôm nay rảnh ngồi send cho ae nào quan tâm tới vấn đề này. Một cái project mình làm đầy đủ cả, bạn nào thích thì load về lắp chơi nhé.

                            Screen Layout:



                            Screen Protues:


                            Demo Video:

                            ////////////////////////////
                            19052011017 - YouTube
                            /////////////////////////

                            Screen Capture: Attach
                            File Download: Attach

                            Code fix một số chỗ cho những ai cảm thấy code cũ có vấn đề
                            PHP Code:
                            /***********************************************************
                            FileName: Hai-Clock-7segment.c
                            MCU: 8051
                            Xtal: 12Mhz
                            App: Digital Clock    
                            Author:     manhcuong.k08@gmail.com
                            Creat Date: 4/5/2011
                            Finish Date: 
                            ************************************************************/
                            #include <at89x52.h>
                            /**********************define var,port*********************/
                            #define data_port P2
                            #define sel_port P0
                            sbit _RW P3^6;            //
                            sbit _RD P3^7;          // 
                            sbit _INT P1^7;
                            sbit MODE P3^3;    //external interrupt 1
                            sbit DEC P3^4;    //DEC value
                            sbit INC P3^5;    //increment value
                            sbit SDA P3^0;    //I2c data line
                            sbit SCL P3^1;    //I2c clock line

                            //===================time variable============================//
                            struct FREE_USER{
                                                 
                            unsigned char SEC;
                                                 
                            unsigned char MIN;
                                                 
                            unsigned char HOUR;
                                                 
                            unsigned char DAY;
                                                 
                            unsigned char DATE;
                                                 
                            unsigned char MONTH;
                                                 
                            unsigned char YEAR;
                                                 } 
                            _TIME ;
                            //============================================================//
                            //            Byte control Real Time Cloclk DS1307              //
                            //                                                              //
                            //============================================================//
                            #define CONTROL_WRITE 0xd0
                            #define CONTROL_READ 0xd1

                            /*********************sub program**************************/

                            //==========================================================//
                            //                                                            //
                            //                RTC class                                    //
                            //==========================================================//
                            unsigned char  RTC_READ(unsigned char ADRESS);
                            void RTC_WRITE(unsigned char ADRESS,unsigned char DAT);
                            void I2C_START();
                            void I2C_STOP();
                            void I2C_WRITE(unsigned char byte);
                            unsigned char I2C_READ();
                            void RTC_INI();
                            //==========================================================//
                            //                                                            //
                            //                other                                        //
                            //==========================================================//
                            void DISPLAY_1__(unsigned char ARRAY[],unsigned char STATUS,bit istempsensor);
                            void DISPLAY_2__(unsigned char ARRAY[]);
                            void delay(int time);
                            void GET_TIME();
                            void TIMER0_ini();
                            void TIMER1_ini();                
                            void CHECK_DAY(bit get);
                            void CONVERT();
                            void GET_T();
                            void DISPLAY_3__(unsigned char ARRAY[]);
                            unsigned char code     seg_code[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
                            unsigned char code HELLO[] = {
                                                            
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                            
                            0x00,0x76,0x79,0x38,0x38,0x3f,0x00,0x00,
                                                            
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
                            unsigned char code MORNING[] = {
                                                            
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                            
                            0x39,0x74,0x77,0x5C,0x00,0x7C,0x1C,0x5C,0x10,
                                                            
                            0x00,0x6D,0x77,0x54,0x6F,
                                                            
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
                            unsigned char code AFTERNOON[] = {
                                                            
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                            
                            0x39,0x74,0x77,0x5C,0x00,0x7C,0x1C,0x5C,0x10,
                                                            
                            0x00,0x58,0x74,0x10,0x79,0x1c,
                                                            
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff};
                            //day on week==============================================
                            unsigned char code SUN[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x39,0x74,0x1c,0x00,0x54,0x74,0x77,0x31,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };
                            unsigned char code MON[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x07,0x76,0x3e,0x00,0x5b,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };    
                            unsigned char code TUE[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x07,0x76,0x3e,0x00,0x4f,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };    
                            unsigned char code WED[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x07,0x76,0x3e,0x00,0x66,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };    
                            unsigned char code THU[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x07,0x76,0x3e,0x00,0x6d,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };    
                            unsigned char code FRI[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x07,0x76,0x3e,0x00,0x7d,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };    
                            unsigned char code SAT[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x07,0x76,0x3e,0x00,0x07,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };

                            unsigned char TIME_DISPLAY[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };    
                            unsigned char DATE_DISPLAY[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };    
                            unsigned char DAY_DISPLAY[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };    
                            unsigned char code T_SENSOR[] = {
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x63,0x39,0x00,0x00,
                                                                
                            0x00,0x00,0x00,0x00,0x00,0x0,0x00,0x00,/*null*/0xff
                                                                
                            };    
                            unsigned char T_value[2];    
                            #define SHIFT 0x00
                            #define STOP 0x01
                            #define CLEAR 0x02
                            #define TIME_STATUS 1080

                            int GLOBAL_DISPLAY=0;
                            unsigned char IN_VISIBLE;
                            unsigned char CONTROL_INVISIBLE=0;
                            unsigned char SHIFT_CURCOR;
                            unsigned char counter_status;
                            /********************************************************/
                            /*            Main Program                                */
                            /********************************************************/
                            void main()
                            {

                                
                            /********Time Default**************
                                _TIME.SEC = 0x00 ;
                                _TIME.MIN = 0x00 ;
                                _TIME.HOUR = 0x12 ;
                                _TIME.DAY  = 0x04 ;
                                _TIME.DATE = 0x10;
                                _TIME.MONTH = 0x04;
                                _TIME.YEAR     = 0x11;
                                RTC_INI();
                                ////////////////////////////////////*/
                                
                            _RD 1;
                                
                            _RW 1;
                                
                            TIMER0_ini();
                                
                            TIMER1_ini();
                                
                            //enable global interrupt
                                
                            EX1 1;    //enable external interrupt 1
                                
                            IT1 1;    //
                                
                            EX0 1;    //enable external interrupt 1
                                
                            IT0 1;    //
                                
                            EA 1;
                                
                            TR0 1;    //timer0 run
                                
                            PT1 =1;
                                
                            PX0 1;
                                
                                while(
                            1)
                                {        
                                
                            //    GET_TIME();DISPLAY_1__(TIME_DISPLAY,STOP);
                                    
                            switch(GLOBAL_DISPLAY)
                                    {
                                         case 
                            0:    DISPLAY_1__(HELLO,SHIFT,0);while(GLOBAL_DISPLAY<100)DISPLAY_1__(HELLO,STOP,0);DISPLAY_1__(HELLO,CLEAR,0);break;
                                        case 
                            140:  DISPLAY_1__(TIME_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<600)DISPLAY_1__(TIME_DISPLAY,STOP,0);DISPLAY_1__(TIME_DISPLAY,CLEAR,0);break;
                                        case 
                            620:  if((_TIME.HOUR>=0)&&(_TIME.HOUR<12))DISPLAY_3__(MORNING);else if(_TIME.HOUR>=12)DISPLAY_3__(AFTERNOON);break;
                                        case 
                            700:  CHECK_DAY(1);DISPLAY_1__(DAY_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<800){CHECK_DAY(1);DISPLAY_1__(DAY_DISPLAY,STOP,0);}DISPLAY_1__(DAY_DISPLAY,CLEAR,0);break;
                                        case 
                            820:  DISPLAY_1__(DATE_DISPLAY,SHIFT,0);while(GLOBAL_DISPLAY<920)DISPLAY_1__(DATE_DISPLAY,STOP,0);DISPLAY_1__(DATE_DISPLAY,CLEAR,0);break;
                                        case 
                            950:  GET_T();DISPLAY_1__(T_SENSOR,SHIFT,1);while(GLOBAL_DISPLAY<1050)DISPLAY_1__(T_SENSOR,STOP,1);DISPLAY_1__(T_SENSOR,CLEAR,1);break;
                                        default:     {;}break;
                                    }    
                                }
                            }
                             
                            //==========================================================//
                            //                                                            //
                            //                DISPLAY_3__                                     //
                            //==========================================================//
                            void DISPLAY_3__(unsigned char ARRAY[])
                            {
                                 
                            unsigned char counter_char=0,index,time_shift,counter;
                                 
                            unsigned char __SELECT__ ;
                                 while(ARRAY[
                            counter_char]!=0xff)
                                             
                            counter_char++;
                                 for(
                            index=0;index<counter_char-8;index++)
                                        {
                                            for(
                            time_shift=0;time_shift<20;time_shift++)
                                            {    
                                                
                            __SELECT__ 0x7f;
                                                for(
                            counter=0;counter<8;counter++)
                                                {
                                                    
                            data_port = ARRAY[counter+index];
                                                    
                            sel_port __SELECT__;
                                                    
                            delay(7);
                                                    
                            sel_port 0xff;     //disable all led
                                                    
                            data_port 0x00;    //disable all led
                                                    
                            __SELECT__ >>= 1;
                                                    
                            __SELECT__ |= 0x80;
                                                }
                                            }
                                        }
                            }
                             
                            //==========================================================//
                            //                                                            //
                            //                DISPLAY_2__                                     //
                            //==========================================================//
                            void DISPLAY_2__(unsigned char ARRAY[])
                            {
                                    
                            unsigned char counter;
                                     
                            unsigned char __SELECT__=0x7f ;
                                                       for(
                            counter=0;counter<8;counter++)
                                                            {
                                                                
                            sel_port __SELECT__;
                                                                
                            sel_port |= IN_VISIBLE;
                                                                
                            data_port = ARRAY[counter+8];
                                                                
                            delay(7);
                                                                
                            sel_port 0xff;     //disable all led
                                                                
                            data_port 0x00;    //disable all led
                                                                
                            __SELECT__ >>= 1;
                                                                
                            __SELECT__ |= 0x80;
                                                            }
                            }
                             
                            //==========================================================//
                            //                                                            //
                            //                DISPLAY_1__                                     //
                            //==========================================================//    
                            void DISPLAY_1__(unsigned char ARRAY[],unsigned char _STATUS_,bit istempsensor)
                            {
                                 
                            unsigned char counter_char=0,index,time_shift,counter;
                                 
                            unsigned char __SELECT__ ;
                                 while(ARRAY[
                            counter_char]!=0xff)
                                             
                            counter_char++;
                                 switch(
                            _STATUS_)
                                 {
                                    
                                    case 
                            SHIFT: {
                                                    for(
                            index=0;index<counter_char-16;index++)
                                                    {
                                                         for(
                            time_shift=0;time_shift<20;time_shift++)
                                                        {
                                                            
                            __SELECT__ 0x7f;
                                                             for(
                            counter=0;counter<8;counter++)
                                                            {
                                                                if(
                            istempsensor)
                                                                {
                                                                     if(
                            counter+index==0x0a)
                                                                    
                            data_port T_value[0];
                                                                    else if(
                            counter+index==0x0b)
                                                                    
                            data_port T_value[1];
                                                                    else
                                                                    
                            data_port = ARRAY[counter+index];
                                                                }
                                                                else 
                                                                
                            data_port = ARRAY[counter+index];
                                                                
                            sel_port __SELECT__;
                                                                
                            delay(7);
                                                                
                            sel_port 0xff;     //disable all led
                                                                
                            data_port 0x00;    //disable all led
                                                                
                            __SELECT__ >>= 1;
                                                                
                            __SELECT__ |= 0x80;
                                                            }
                                                        }
                                                    }
                                                break;
                                                }
                                    case 
                            STOP:    {
                                                    
                            __SELECT__ 0x7f;
                                                       for(
                            counter=0;counter<8;counter++)
                                                            {
                                                                if(
                            istempsensor)
                                                                {
                                                                     if(
                            counter+8==0x0a)
                                                                    
                            data_port T_value[0];
                                                                    else if(
                            counter+8==0x0b)
                                                                    
                            data_port T_value[1];
                                                                    else
                                                                    
                            data_port = ARRAY[counter+8];
                                                                }
                                                                else
                                                                 
                            data_port = ARRAY[counter+8];
                                                                
                            sel_port __SELECT__;
                                                                
                            delay(7);
                                                                
                            sel_port 0xff;     //disable all led
                                                                
                            data_port 0x00;    //disable all led
                                                                
                            __SELECT__ >>= 1;
                                                                
                            __SELECT__ |= 0x80;
                                                            }
                                                        break;
                                                        }
                                    case 
                            CLEAR: {
                                                    for(
                            index=8;index<counter_char-8;index++)
                                                    {
                                                         for(
                            time_shift=0;time_shift<20;time_shift++)
                                                        {
                                                            
                            __SELECT__ 0x7f;
                                                             for(
                            counter=0;counter<8;counter++)
                                                            {
                                                                if(
                            istempsensor)
                                                                {
                                                                     if(
                            counter+index==0x0a)
                                                                    
                            data_port T_value[0];
                                                                    else if(
                            counter+index==0x0b)
                                                                    
                            data_port T_value[1];
                                                                    else
                                                                    
                            data_port = ARRAY[counter+index];
                                                                }
                                                                else
                                                                 
                            data_port = ARRAY[counter+index];
                                                                
                            sel_port __SELECT__;
                                                                
                            delay(7);
                                                                
                            sel_port 0xff;     //disable all led
                                                                
                            data_port 0x00;    //disable all led
                                                                
                            __SELECT__ >>= 1;
                                                                
                            __SELECT__ |= 0x80;
                                                            }
                                                        }
                                                    }
                                                break;
                                                }
                                                    
                                 }

                            }
                             
                            //==========================================================//
                            //                                                            //
                            //                delay                                     //
                            //==========================================================//         
                            void delay(int time)
                            {
                                
                            int i,j;
                                for(
                            i=0;i<time;i++)
                                     for(
                            j=0;j<time;j++)
                                    {;}
                            }
                            //==========================================================//
                            //                                                            //
                            //                I2c_START                                     //
                            //==========================================================//
                            void I2C_START()
                            {
                                 
                            SDA 1;
                                
                            SCL 1;
                                
                            SDA 0;
                                
                            SCL 0;
                                
                            SDA 1;
                            }
                            //==========================================================//
                            //                                                            //
                            //                I2c_STOP                                     //
                            //==========================================================//
                            void I2C_STOP()
                            {
                                
                            SDA 0;
                                
                            SCL 1;
                                
                            SDA 1;
                            }
                            //==========================================================//
                            //                                                            //
                            //                I2c_WRITE                                     //
                            //==========================================================//
                            void I2C_WRITE(unsigned char byte)
                            {
                                
                            unsigned char counter;
                                for(
                            counter 0;counter<8;counter++)
                                {
                                     if(
                            byte&0x80)
                                        
                            SDA=1;
                                    else
                                        
                            SDA=0;
                                    
                            SCL 1;
                                    
                            SCL 0;
                                    
                            byte<<=1;
                                }
                                    
                            SDA 1;
                                    
                            SCL 1;
                                    
                            SCL 0;
                                    
                            }
                            //==========================================================//
                            //                                                            //
                            //                I2c_READ                                     //
                            //==========================================================//
                            unsigned char I2C_READ()
                            {
                                
                            unsigned char return_value=0x00,counter=8;
                                    while(
                            counter>0)
                                    {
                                         
                            SCL=1;
                                        
                            return_value<<=1;
                                        
                            return_value|=SDA;
                                        
                            SCL=0;
                                        
                            counter--;    
                                    }

                                    
                            SDA 1
                                    
                            SCL 1;
                                    
                            SCL 0;
                                    
                            SDA 1
                                    return 
                            return_value;
                                    
                            }
                            //==========================================================//
                            //                                                            //
                            //                RTC_WRITE                                     //
                            //==========================================================//
                            void RTC_WRITE(unsigned char ADDRESS,unsigned char DAT)
                            {
                                
                            I2C_START();                    //i2c start
                                
                            I2C_WRITE(CONTROL_WRITE);       //send control byte
                                
                            I2C_WRITE(ADDRESS);            //send address byte
                                
                            I2C_WRITE(DAT);                    //send data byte
                                
                            I2C_STOP();                      //i2c stop

                            }
                            //==========================================================//
                            //                                                            //
                            //                RTC_READ                                     //
                            //==========================================================//
                            unsigned char RTC_READ(unsigned char ADDRESS)
                            {
                                
                            unsigned char return_value=0x00;
                                
                            I2C_START();
                                
                            I2C_WRITE(CONTROL_WRITE); //send byte control write
                                
                            I2C_WRITE(ADDRESS); // send byte address
                                
                            I2C_START(); // restart
                                
                            I2C_WRITE(CONTROL_READ); // send byte control read
                                
                            return_value I2C_READ(); //read from RTC
                                
                            I2C_STOP();
                                return 
                            return_value;
                            }
                            //==========================================================//
                            //                                                            //
                            //                RTC_INI                                     //
                            //==========================================================//
                            void RTC_INI()    
                            {          
                            //ADDRESS,DATA//
                                
                            RTC_WRITE(0x00,_TIME.SEC);
                                
                            RTC_WRITE(0x01,_TIME.MIN);
                                
                            RTC_WRITE(0x02,_TIME.HOUR);
                                
                            RTC_WRITE(0x03,_TIME.DAY);
                                
                            RTC_WRITE(0x04,_TIME.DATE);
                                
                            RTC_WRITE(0x05,_TIME.MONTH);
                                
                            RTC_WRITE(0x06,_TIME.YEAR);
                                
                            RTC_WRITE(0x07,0x10);//OUT = 1,SOUT = 1;
                            }
                            //==========================================================//
                            //                                                            //
                            //                GET_TIME                                    //
                            //==========================================================//
                            void GET_TIME()
                            {
                                 
                                
                            _TIME.SEC RTC_READ(0x00);    //GET SECOND
                                
                            _TIME.MIN RTC_READ(0x01);    //GET MIN
                                
                            _TIME.HOUR RTC_READ(0x02)&0x3f;    //GET HOUR
                                
                            _TIME.DAY RTC_READ(0x03);    //GET DAY
                                
                            _TIME.DATE RTC_READ(0x04);    //GET DATE
                                
                            _TIME.MONTH RTC_READ(0x05);    //GET MONTH
                                
                            _TIME.YEAR RTC_READ(0x06);    //GET YEAR
                                
                            CONVERT();
                            }
                                                                                               
                            //==========================================================//
                            //                                                            //
                            //                Timer0_ini                                    //
                            //==========================================================//
                            void TIMER0_ini()
                            {
                                
                            TMOD 0x01    ;//timer 0 16bit reload
                                
                            TH0 0x00;
                                
                            TL0 0x00;
                                
                            TF0 0;
                                
                            TR0 0;
                                
                            ET0 1;    //enable timer0 interrupt
                                
                            }
                            //==========================================================//
                            //                                                            //
                            //                CONVERT                                    //
                            //==========================================================//
                            void CONVERT()
                            {
                            unsigned char temp,index=15;
                             
                            //GET SECCOND
                                
                            temp _TIME.SEC;
                                
                            temp&=0x0f;        //get the unit
                                
                            TIME_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                                
                            temp _TIME.SEC;
                                
                            temp&=0xf0;        //get the tens
                                
                            temp>>=4;
                                
                            TIME_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                            //SPACER
                                
                            TIME_DISPLAY[index]=0x40;    //
                                
                            index--;
                             
                            //GET MIN
                                
                            temp _TIME.MIN;
                                
                            temp&=0x0f;        //get the unit
                                
                            TIME_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                                
                            temp _TIME.MIN;
                                
                            temp&=0xf0;        //get the tens
                                
                            temp>>=4;
                                
                            TIME_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                            //SPACER
                                
                            TIME_DISPLAY[index]=0x40;    //
                                
                            index--;
                             
                            //GET HOUR
                                
                            temp _TIME.HOUR;
                                
                            temp&=0x0f;        //get the unit
                                
                            TIME_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                                
                            temp _TIME.HOUR;
                                
                            temp&=0xf0;        //get the tens
                                
                            temp>>=4;
                                
                            TIME_DISPLAY[index]=seg_code[temp];

                                
                            index=15;
                            //GET YEAR
                                
                            temp _TIME.YEAR;
                                
                            temp&=0x0f;        //get the unit
                                
                            DATE_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                                
                            temp _TIME.YEAR;
                                
                            temp&=0xf0;        //get the tens
                                
                            temp>>=4;
                                
                            DATE_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                            //SPACER
                                
                            DATE_DISPLAY[index]=0x40;    //
                                
                            index--;
                             
                            //GET MONTH
                                
                            temp _TIME.MONTH;
                                
                            temp&=0x0f;        //get the unit
                                
                            DATE_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                                
                            temp _TIME.MONTH;
                                
                            temp&=0xf0;        //get the tens
                                
                            temp>>=4;
                                
                            DATE_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                            //SPACER
                                
                            DATE_DISPLAY[index]=0x40;    //
                                
                            index--;
                             
                            //GET DATE
                                
                            temp _TIME.DATE;
                                
                            temp&=0x0f;        //get the unit
                                
                            DATE_DISPLAY[index]=seg_code[temp];
                                
                            index--;
                                
                            temp _TIME.DATE;
                                
                            temp&=0xf0;        //get the tens
                                
                            temp>>=4;
                                
                            DATE_DISPLAY[index]=seg_code[temp];
                            }
                            //==========================================================//
                            //                                                            //
                            //                Timer1_ini                            //
                            //==========================================================//
                            void TIMER1_ini()
                            {
                                
                            TMOD |= 0x10;    //timer 1 16bit reload
                                
                            TH1 0x00;
                                
                            TL1 0x00;
                                
                            TF1 0;
                                
                            TR1 0;
                                
                            ET1 1;
                                
                            }
                            //==========================================================//
                            //                                                            //
                            //                Timer0_interrupt                                    //
                            //==========================================================//
                            void TIMER0_interrupt() interrupt 1
                            {
                                
                            TR0 0;
                                
                            TF0 0;
                                
                            TH0 0;
                                
                            TL0 0;
                                
                            GLOBAL_DISPLAY++;
                                if(
                            GLOBAL_DISPLAY==TIME_STATUS)
                                        
                            GLOBAL_DISPLAY=0;
                                
                            TR0 1;
                                
                            }
                            //==========================================================//
                            //                                                            //
                            //                Timer1_interrupt                            //
                            //==========================================================//
                            void TIMER1_interrupt()    interrupt 3
                            {
                                
                            TR1 0;    //stop timer1
                                
                            TF1 0;    //clear TF1
                                
                            TH1 0;
                                
                            TL1 1;
                                
                            CONTROL_INVISIBLE++;
                                if(
                            CONTROL_INVISIBLE==5)
                                {
                                    
                            IN_VISIBLE 0x00;
                                }
                                else if(
                            CONTROL_INVISIBLE==10)
                                {
                                    
                            IN_VISIBLE SHIFT_CURCOR;
                                    
                            CONTROL_INVISIBLE=0;
                                 }
                                else {;}
                                
                            TR1 1;
                                
                            }
                            //==========================================================//
                            //                                                            //
                            //                External Interrupt 1                        //
                            //==========================================================//
                            void EX1_interrupt()interrupt 2
                            {
                                
                            unsigned char unit,tens;
                                
                            EX1 0//    disable ex interrupt 1
                                
                            EX0 0//    disable ex interrupt 0
                                
                            counter_status=0x00;
                                
                            TR1 1;    //enable TIMER1
                                
                            IN_VISIBLE 0xc0;
                                
                            SHIFT_CURCOR =       IN_VISIBLE;
                                
                            CONTROL_INVISIBLE=0;
                            //    GET_TIME();
                                
                            while(MODE==0)DISPLAY_2__(TIME_DISPLAY);
                                while(
                            counter_status!=0x07)
                                {
                                    
                                     switch(
                            counter_status)
                                    {
                                         case 
                            0x00:    {
                                                        while(
                            MODE)
                                                        {
                                                             if(
                            INC==0)
                                                            {
                                                                 while(
                            INC==0)DISPLAY_2__(TIME_DISPLAY);
                                                                
                            unit _TIME.HOUR;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.HOUR;
                                                                
                            tens >>= 4;
                                                                if(
                            tens!=2)
                                                                {
                                                                        
                            unit++;
                                                                        if(
                            unit==10)
                                                                        {
                                                                            
                            tens++;
                                                                            
                            unit=0;
                                                                        }
                                                                }
                                                                else
                                                                {
                                                                     
                            unit++;
                                                                    if(
                            unit==4)
                                                                    {
                                                                        
                            tens=0;
                                                                        
                            unit 0;
                                                                    }
                                                                    
                                                                }
                                                                
                            _TIME.HOUR tens;
                                                                
                            _TIME.HOUR <<=4;
                                                                
                            _TIME.HOUR |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            if(
                            DEC==0)
                                                            {
                                                                while(
                            DEC==0)DISPLAY_2__(TIME_DISPLAY);
                                                                
                            unit _TIME.HOUR;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.HOUR;
                                                                
                            tens >>= 4;
                                                                if(
                            tens!=0)
                                                                {
                                                                        
                            unit--;
                                                                        if(
                            unit==0xff)
                                                                        {
                                                                            
                            tens--;
                                                                            
                            unit 0x09;
                                                                        }
                                                                }
                                                                else
                                                                {
                                                                     
                            unit--;
                                                                    if(
                            unit==0xff)
                                                                    {
                                                                        
                            tens 0x02;
                                                                        
                            unit 0x03;
                                                                    }
                                                                    
                                                                }
                                                                
                            _TIME.HOUR tens;
                                                                
                            _TIME.HOUR <<=4;
                                                                
                            _TIME.HOUR |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            
                            DISPLAY_2__(TIME_DISPLAY);
                                                        }
                                                        while(
                            MODE==0){DISPLAY_2__(TIME_DISPLAY);}
                                                        while(
                            IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
                                                        
                            IN_VISIBLE>>=3;
                                                        
                            SHIFT_CURCOR IN_VISIBLE;

                                                        
                            counter_status++;
                                                        break;
                                                    }
                                        case 
                            0x01:    {
                                                        while(
                            MODE)
                                                        {
                                                             if(
                            INC==0)
                                                            {
                                                                 while(
                            INC==0)DISPLAY_2__(TIME_DISPLAY);
                                                                
                            unit _TIME.MIN;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.MIN;
                                                                
                            tens >>= 4;
                                                                
                            unit++;
                                                                if(
                            unit==10)
                                                                {
                                                                    
                            tens++;
                                                                    
                            unit=0;
                                                                }
                                                                if(
                            tens==6)
                                                                     
                            tens=0;
                                                                
                            _TIME.MIN tens;
                                                                
                            _TIME.MIN <<=4;
                                                                
                            _TIME.MIN |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            if(
                            DEC==0)
                                                            {
                                                                while(
                            DEC==0)DISPLAY_2__(TIME_DISPLAY);
                                                                
                            unit _TIME.MIN;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.MIN;
                                                                
                            tens >>= 4;
                                                                
                            unit--;
                                                                if(
                            unit==0xff)
                                                                {
                                                                    
                            tens--;
                                                                    
                            unit=9;
                                                                }
                                                                if(
                            tens==0xff)
                                                                     
                            tens=5;
                                                                
                            _TIME.MIN tens;
                                                                
                            _TIME.MIN <<=4;
                                                                
                            _TIME.MIN |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            
                            DISPLAY_2__(TIME_DISPLAY);
                                                        }
                                                        while(
                            MODE==0){DISPLAY_2__(TIME_DISPLAY);}
                                                        while(
                            IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
                                                        
                            IN_VISIBLE>>=3;
                                                        
                            SHIFT_CURCOR IN_VISIBLE;
                                                        
                            counter_status++;
                                                        break;
                                                    }
                                        case 
                            0x02:    {
                                                        while(
                            MODE)
                                                        {
                                                             if(
                            INC==0)
                                                            {
                                                                 while(
                            INC==0)DISPLAY_2__(TIME_DISPLAY);
                                                                
                            unit _TIME.SEC;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.SEC;
                                                                
                            tens >>= 4;
                                                                
                            unit++;
                                                                if(
                            unit==10)
                                                                {
                                                                    
                            tens++;
                                                                    
                            unit=0;
                                                                }
                                                                if(
                            tens==6)
                                                                     
                            tens=0;
                                                                
                            _TIME.SEC tens;
                                                                
                            _TIME.SEC <<=4;
                                                                
                            _TIME.SEC|= unit;
                                                                
                            CONVERT();
                                                            }
                                                            if(
                            DEC==0)
                                                            {
                                                                while(
                            DEC==0)DISPLAY_2__(TIME_DISPLAY);
                                                                
                            unit _TIME.SEC;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.SEC;
                                                                
                            tens >>= 4;
                                                                
                            unit--;
                                                                if(
                            unit==0xff)
                                                                {
                                                                    
                            tens--;
                                                                    
                            unit=9;
                                                                }
                                                                if(
                            tens==0xff)
                                                                     
                            tens=5;
                                                                
                            _TIME.SEC tens;
                                                                
                            _TIME.SEC <<=4;
                                                                
                            _TIME.SEC|= unit;
                                                                
                            CONVERT();
                                                            }
                                                          
                            DISPLAY_2__(TIME_DISPLAY);
                                                        }
                                                        while(
                            MODE==0){DISPLAY_2__(TIME_DISPLAY);}
                                                        while(
                            IN_VISIBLE==0x00){DISPLAY_2__(TIME_DISPLAY);}
                                                        
                            IN_VISIBLE=0xc0;
                                                        
                            SHIFT_CURCOR IN_VISIBLE;
                                                        
                            counter_status++;
                                                        break;
                                                    }
                                        case 
                            0x03:    {
                                                        while(
                            MODE)
                                                        {
                                                             if(
                            INC==0)
                                                            {
                                                                 while(
                            INC==0)DISPLAY_2__(DATE_DISPLAY);
                                                                
                            unit _TIME.DATE;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.DATE;
                                                                
                            tens >>= 4;
                                                                if(
                            _TIME.MONTH%2==1)
                                                                {
                                                                     if(
                            tens<3)
                                                                    {
                                                                        
                            unit++;
                                                                        if(
                            unit==10)
                                                                        {
                                                                            
                            tens++;
                                                                            
                            unit=0;
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                         
                            unit++;
                                                                        if(
                            unit==2)
                                                                        {
                                                                            
                            tens=0;
                                                                            
                            unit=0;
                                                                        }
                                                                    }
                                                                }
                                                                else if(
                            _TIME.MONTH%2==0)
                                                                {
                                                                     if(
                            tens<3)
                                                                    {
                                                                        
                            unit++;
                                                                        if(
                            unit==10)
                                                                        {
                                                                            
                            tens++;
                                                                            
                            unit=0;
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                         
                            unit++;
                                                                        if(
                            unit==1)
                                                                        {
                                                                            
                            tens=0;
                                                                            
                            unit=0;
                                                                        }
                                                                    }
                                                                }
                                                                
                            _TIME.DATE tens;
                                                                
                            _TIME.DATE <<=4;
                                                                
                            _TIME.DATE |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            if(
                            DEC==0)
                                                            {
                                                                while(
                            DEC==0)DISPLAY_2__(DATE_DISPLAY);
                                                                
                            unit _TIME.DATE;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.DATE;
                                                                
                            tens >>= 4;
                                                                if(
                            _TIME.MONTH%2==1)
                                                                {
                                                                     
                            unit--;
                                                                    if(
                            unit==0xff)
                                                                    {
                                                                        
                            tens--;
                                                                        
                            unit=9;
                                                                    }
                                                                    if(
                            tens==0xff)
                                                                    {
                                                                         
                            tens=3;
                                                                        
                            unit=1;
                                
                                                                    }
                                                                }
                                                                else if(
                            _TIME.MONTH%2==0)
                                                                {
                                                                     
                            unit--;
                                                                    if(
                            unit==0xff)
                                                                    {
                                                                        
                            tens--;
                                                                        
                            unit=9;
                                                                    }
                                                                    if(
                            tens==0xff)
                                                                    {
                                                                         
                            tens=3;
                                                                        
                            unit=0;
                                
                                                                    }
                                                                }
                                                                
                            _TIME.DATE tens;
                                                                
                            _TIME.DATE <<=4;
                                                                
                            _TIME.DATE |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            
                            DISPLAY_2__(DATE_DISPLAY);
                                
                                                        }
                                                        while(
                            MODE==0){DISPLAY_2__(DATE_DISPLAY); }
                                                        while(
                            IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
                                                        
                            IN_VISIBLE>>=3;
                                                        
                            SHIFT_CURCOR IN_VISIBLE;
                                                        
                            counter_status++;
                                                        break;
                                                    }

                                        case 
                            0x04:    {
                                                        while(
                            MODE)
                                                        {
                                                             if(
                            INC==0)
                                                            {
                                                                 while(
                            INC==0)DISPLAY_2__(DATE_DISPLAY);
                                                                
                            unit _TIME.MONTH;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.MONTH;
                                                                
                            tens >>= 4;
                                                                if(
                            tens!=1)
                                                                {
                                                                    
                            unit++;
                                                                    if(
                            unit==10)
                                                                    {
                                                                        
                            tens++;
                                                                        
                            unit=0;
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                     
                            unit++;
                                                                    if(
                            unit==3)
                                                                    {
                                                                        
                            tens=0;
                                                                        
                            unit=0;
                                                                    }
                                                                }
                                                                
                            _TIME.MONTH tens;
                                                                
                            _TIME.MONTH <<=4;
                                                                
                            _TIME.MONTH |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            if(
                            DEC==0)
                                                            {
                                                                while(
                            DEC==0)DISPLAY_2__(DATE_DISPLAY);
                                                                
                            unit _TIME.MONTH;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.MONTH;
                                                                
                            tens >>= 4;
                                                                
                            unit--;
                                                                if(
                            unit==0xff)
                                                                {
                                                                    
                            tens--;
                                                                    
                            unit=9;
                                                                }
                                                                if(
                            tens==0xff)
                                                                {
                                                                     
                            tens=1;
                                                                    
                            unit=2;

                                                                }
                                                                
                            _TIME.MONTH tens;
                                                                
                            _TIME.MONTH <<=4;
                                                                
                            _TIME.MONTH |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            
                            DISPLAY_2__(DATE_DISPLAY);
                                
                                                        }
                                                        while(
                            MODE==0){DISPLAY_2__(DATE_DISPLAY);}
                                                        while(
                            IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
                                                        
                            IN_VISIBLE>>=3;
                                                        
                            SHIFT_CURCOR IN_VISIBLE;
                                                        
                            counter_status++;
                                                        break;
                                                    }
                                                    
                                        case 
                            0x05:    {
                                                        while(
                            MODE)
                                                        {
                                                             if(
                            INC==0)
                                                            {
                                                                 while(
                            INC==0)DISPLAY_2__(DATE_DISPLAY);
                                                                
                            unit _TIME.YEAR;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.YEAR;
                                                                
                            tens >>= 4;
                                                                
                            unit++;
                                                                if(
                            unit==10)
                                                                {
                                                                    
                            tens++;
                                                                    
                            unit=0;
                                                                }
                                                                if(
                            tens==9)
                                                                     
                            tens=0;
                                                                
                            _TIME.YEAR tens;
                                                                
                            _TIME.YEAR <<=4;
                                                                
                            _TIME.YEAR |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            if(
                            DEC==0)
                                                            {
                                                                while(
                            DEC==0)DISPLAY_2__(DATE_DISPLAY);
                                                                
                            unit _TIME.YEAR;
                                                                
                            unit &=0x0f;
                                                                
                            tens _TIME.YEAR;
                                                                
                            tens >>= 4;
                                                                
                            unit--;
                                                                if(
                            unit==0xff)
                                                                {
                                                                    
                            tens--;
                                                                    
                            unit=9;
                                                                }
                                                                if(
                            tens==0xff)
                                                                     
                            tens=9;
                                                                
                            _TIME.YEAR tens;
                                                                
                            _TIME.YEAR <<=4;
                                                                
                            _TIME.YEAR |= unit;
                                                                
                            CONVERT();
                                                            }
                                                            
                            DISPLAY_2__(DATE_DISPLAY);
                                
                                                        }
                                                        while(
                            MODE==0){DISPLAY_2__(DATE_DISPLAY);}
                                                        while(
                            IN_VISIBLE==0x00){DISPLAY_2__(DATE_DISPLAY);}
                                                        
                            IN_VISIBLE 0xff;
                                                        
                            SHIFT_CURCOR IN_VISIBLE;
                                                        
                            counter_status++;
                                                        break;
                                                        
                                                    }
                                        case 
                            0x06:    {
                                                        while(
                            MODE)
                                                        {
                                                            
                            CHECK_DAY(0);
                                                             if(
                            INC==0)
                                                            {
                                                                 while(
                            INC==0)DISPLAY_2__(DAY_DISPLAY);
                                                                
                            _TIME.DAY++;
                                                                if(
                            _TIME.DAY==8)
                                                                    
                            _TIME.DAY=1;
                                                                
                            CHECK_DAY(0);
                                                            }
                                                            if(
                            DEC==0)
                                                            {
                                                                while(
                            DEC==0)DISPLAY_2__(DAY_DISPLAY);
                                                                
                            _TIME.DAY--;
                                                                if(
                            _TIME.DAY==0xff)
                                                                    
                            _TIME.DAY=7;
                                                                
                            CHECK_DAY(0);
                                                            }
                                                            
                            DISPLAY_2__(DAY_DISPLAY);
                                
                                                        }
                                                        while(
                            MODE==0){DISPLAY_2__(DAY_DISPLAY);}
                                                        while(
                            IN_VISIBLE==0x00){DISPLAY_2__(DAY_DISPLAY);}
                                                        
                            SHIFT_CURCOR IN_VISIBLE;
                                                        
                            counter_status++;
                                                        break;
                                                        
                                                    }
                                                    
                                    }
                                    
                            RTC_INI();
                                }
                                
                            IE1 0;//clear external interrupt 1 flag
                                
                            TR1 0;
                                
                            EX0 1;
                                
                            EX1 1;
                            }
                            //==========================================================//
                            //                                                            //
                            //                CHECK_DAY                                    //
                            //==========================================================//
                            void CHECK_DAY(bit get)
                            {
                                
                            unsigned char index,DAY;
                                if(
                            get)
                                
                            DAY RTC_READ(0x03);
                                else
                                
                            DAY _TIME.DAY;
                                switch(
                            DAY)
                                {
                                     case 
                            0x01:     for(index=0;index<24;index++)DAY_DISPLAY[index]=SUN[index];break;
                                    case 
                            0x02:     for(index=0;index<24;index++)DAY_DISPLAY[index]=MON[index];break;
                                    case 
                            0x03:     for(index=0;index<24;index++)DAY_DISPLAY[index]=TUE[index];break;
                                    case 
                            0x04:     for(index=0;index<24;index++)DAY_DISPLAY[index]=WED[index];break;
                                    case 
                            0x05:     for(index=0;index<24;index++)DAY_DISPLAY[index]=THU[index];break;
                                    case 
                            0x06:     for(index=0;index<24;index++)DAY_DISPLAY[index]=FRI[index];break;
                                    case 
                            0x07:     for(index=0;index<24;index++)DAY_DISPLAY[index]=SAT[index];break;
                                }
                            }


                            //===========================================================///
                            void update_time() interrupt 0
                            {
                                
                            EX0 0;
                                
                            GET_TIME();
                                
                            IE0 0;
                                
                            EX0 1;

                            }
                            //===========================================================//
                            void GET_T()
                            {
                                 
                            unsigned char temp;
                                
                            _RW 0;
                                
                            _RW 1;
                                while(
                            _INT);
                                
                            RD 0;
                                
                            temp P1;
                                
                            temp&=0x7f;
                                
                            RD 1;
                                
                            T_value[0]=seg_code[temp/10];
                                
                            T_value[1]=seg_code[temp%10];    


                            Mạch của bạn rất hay, bạn cho mình hỏi mấy câu lệnh trong C dược không mình mới mày mò về C nên chưa hiểu nhiều. Thanks

                            yahoo: minhthanh29mtp
                            Nhận vẽ mạch in ^_^
                            TEL: 0167 4500 365
                            Mail:

                            Comment


                            • #15
                              em đang làm cái đồng hồ, mà code của em có vấn đề hiển thị led 7 đọan, mô phỏng thì chạy nhưng khi nạp vào ic thì led sáng hết lên ko chạy được . có anh nào biết và sửa lại giúp em được ko. em cám ơn nhiều

                              code:

                              #include <REGX51.H>
                              #define SEC 0x00
                              #define MIN 0x01
                              #define HOUR 0x02
                              #define DAY 0x03
                              #define DATE 0x04
                              #define MONTH 0x05
                              #define YEAR 0x06
                              #define A_MIN 0x08
                              #define A_HOUR 0x09

                              char sec,hour,min,day,date,month,year,year_20,a_min,a_h our;
                              sbit SDA = P1^0;
                              sbit SCL = P1^1;
                              sbit Mode = P1^2;
                              sbit Up = P1^3;
                              sbit Down = P1^4;
                              sbit Ok = P1^5;
                              sbit Alarm = P1^6;
                              sbit Loa = P1^7;

                              sbit L01 = P2^0;
                              sbit L02 = P2^1;
                              sbit L03 = P2^2;
                              sbit L04 = P2^3;
                              sbit L05 = P2^4;
                              sbit L06 = P2^5;
                              sbit L07 = P2^6;
                              sbit L08 = P2^7;

                              sbit L09 = P3^0;
                              sbit L10 = P3^1;
                              sbit L11 = P3^2;
                              sbit L12 = P3^3;
                              sbit L13 = P3^4;
                              sbit L14 = P3^5;
                              sbit L15 = P3^6;
                              sbit PM = P3^7;

                              //************************************************** ****************************
                              // KHAI BAO BIEN, MANG...
                              unsigned char led7_data[10] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90 }; //Decimal to Led7seg
                              unsigned char Data,Display,time,index,mode,bat_nhay,read_time,al arm,kt,on_off;

                              // KHAI BAO HAM, CHUONG TRINH CON
                              void set_main(void); // Chuong trinh khoi tao main
                              void setup_timer(void); // Chuong trinh cai dat timer 1 va 0
                              void delay(unsigned int time); // Delay
                              void Fix_time(void); // Kiem tra va hieu chinh gia tri cua gio,phut,giay
                              void Keypad(void); // Kiem tra xu ly phim nhan.
                              void T1_ISR(void); //ngat timer 1 phuc vu nhay led
                              void T0_ISR(void); // Dung ngat timer 0 de quet led
                              //************************************************** ****************************
                              void bip(void)
                              {
                              unsigned char n;
                              for(n=0;n<100;n++)
                              {
                              Loa=1; delay(50);
                              Loa=0; delay(50);
                              }
                              }
                              //************************************************** ****************************
                              // CAC CHUONG TRINH CON CHO I2C
                              //************************************************** ****************************
                              void I2C_start(void)
                              {
                              SCL = 1; SCL = 0;
                              SDA = 1; SCL = 1;
                              delay(2);
                              SDA = 0; delay(2);
                              SCL = 0; delay(2);
                              }
                              void I2C_stop(void)
                              {
                              SCL = 1; SCL = 0;
                              SDA = 0; delay(2);
                              SCL = 1; delay(2);
                              SDA = 1;
                              }
                              bit I2C_write(unsigned char dat)
                              {
                              unsigned char i;
                              for (i=0;i<8;i++)
                              {
                              SDA = (dat & 0x80) ? 1:0;
                              SCL=1;SCL=0;
                              dat<<=1;
                              }
                              SCL = 1; delay(2);
                              SCL = 0;
                              return dat;
                              }
                              unsigned char I2C_read(void)
                              {
                              bit rd_bit;
                              unsigned char i, dat;
                              dat = 0x00;
                              for(i=0;i<8;i++) /* For loop read data 1 byte */
                              {
                              delay(2);
                              SCL = 1; delay(2); /* Set SCL */
                              rd_bit = SDA; /* Keep for check acknowledge */
                              dat = dat<<1;
                              dat = dat | rd_bit; /* Keep bit data in dat */
                              SCL = 0; /* Clear SCL */
                              }
                              return dat;
                              }
                              //************************************************** ****************************
                              // CAC CHUONG TRINH CON CHO DS1307
                              //************************************************** ****************************
                              unsigned char DS1307_read(unsigned char addr)
                              {
                              unsigned int temp,ret;
                              I2C_start(); /* Start i2c bus */
                              I2C_write(0xD0); /* Connect to DS1307 */
                              I2C_write(addr); /* Request RAM address on DS1307 */
                              I2C_start(); /* Start i2c bus */
                              I2C_write(0XD1); /* Connect to DS1307 for Read */
                              ret = I2C_read(); /* Receive data */
                              I2C_stop();
                              //************************************************** ********
                              temp = ret; /*BCD to HEX*/
                              ret = (((ret/16)*10)+ (temp & 0x0f)); /*for Led 7seg*/
                              //************************************************** ********
                              return ret;
                              }

                              void DS1307_Write(unsigned char addr,unsigned char dat)
                              {
                              unsigned int temp;
                              //**********************************************
                              temp = dat ; /*HEX to BCD*/
                              dat = (((dat/10)*16)|(temp %10)); /*for Led 7seg*/
                              //**********************************************
                              I2C_start(); /* Start i2c bus */
                              I2C_write(0XD0); /* Connect to DS1307 */
                              I2C_write(addr); /* Request RAM address on DS1307 */
                              I2C_write(dat); /* Connect to DS1307 for Read */
                              I2C_stop();
                              }

                              void Out_1Hz()
                              {
                              I2C_start(); /* Start i2c bus */
                              I2C_write(0xD0); /* Connect to DS1307 */
                              I2C_write(0x07); //vi tri con tro RTC
                              I2C_write(0x10);
                              I2C_stop();
                              }

                              void Read_DS1307()
                              {
                              sec = DS1307_read(SEC);
                              min = DS1307_read(MIN);
                              hour = DS1307_read(HOUR);
                              day = DS1307_read(DAY);
                              date = DS1307_read(DATE);
                              month = DS1307_read(MONTH);
                              year = DS1307_read(YEAR);
                              }

                              void Write_DS1307()
                              {
                              DS1307_Write(SEC,sec);
                              DS1307_Write(MIN,min);
                              DS1307_Write(HOUR,hour);
                              DS1307_Write(DAY,day);
                              DS1307_Write(DATE,date);
                              DS1307_Write(MONTH,month);
                              DS1307_Write(YEAR,year);
                              }

                              void Write_Alarm()
                              {
                              DS1307_Write(A_MIN,a_min);
                              DS1307_Write(A_HOUR,a_hour);
                              }
                              //************************************************** ****************************
                              void delay(unsigned int time)
                              {
                              while(time--);
                              }
                              void set_main(void) // Chuong trinh khoi tao main
                              {
                              P1=0xFF;
                              P0=P2=P3=0x00;
                              }
                              void setup_timer(void) // Setup timer 0 va timer 1
                              {
                              TMOD=0x11; // timer0 & timer1 set che do 1
                              ET1=1; ET0=1; EA=1;
                              TF0=0; TF1=0;
                              TR0=1; TR1=1;
                              }
                              void Set_Clock(void) // Kiem tra va hieu chinh gia tri cua gio,phut,giay
                              {
                              unsigned char y;
                              y=(year%4)*100;
                              //Tang
                              if(min>59) { min=0; }
                              if(hour>23){ hour=0; }
                              if(day>8) day=2;
                              if((month==2)&&(date>29)&&(y==0)) { date=1; }
                              else if((month==2)&&(date>28)&&(y!=0)) { date=1; }
                              else if(((month==4)||(month==6)||(month==9)||(month==11 ))&&(date>30)&&(y!=0)){ date=1; }
                              else if(date>31) { date=1; }
                              if(month>12) { month=1; }
                              if(year>99) { year_20++; year=0; if(year_20>99){year_20=0;} }
                              //Giam
                              if(min<0) { min=59; }
                              if(hour<0) { hour=23; }
                              if(day<2) day=8;
                              if((month==2)&&(date<1)&&(y==0)) { date=29; }
                              else if((month==2)&&(date<1)&&(y!=0)) { date=28; }
                              else if(((month==4)||(month==6)||(month==9)||(month==11 ))&&(date<1)&&(y!=0)){ date=30; }
                              else if(date<1) { date=31; }
                              if(month<1) { month=12; }
                              if(year<0) { year_20--; year=99; if(year_20<0){year_20=99;} }
                              }
                              void Keypad(void) // Kiem tra phim nhan.
                              {
                              if(!Ok)
                              {
                              bip();
                              if(on_off==1)
                              {
                              Display=mode=alarm=0;
                              Write_Alarm();
                              }
                              else
                              {
                              Display=alarm=mode=0;
                              Write_DS1307();
                              }
                              }
                              //************************************************** *******************
                              if(Display==0)
                              {
                              if(!Mode)
                              {
                              bip(); mode++; sec=0;
                              if(mode==7)
                              {
                              mode=1;
                              }
                              }
                              if(mode==1)
                              {
                              if(!Up)
                              {
                              min=min+1; delay(50000);
                              }
                              if(!Down)
                              {
                              min=min-1; delay(50000);
                              }
                              }
                              if(mode==2)
                              {
                              if(!Up)
                              {
                              hour=hour+1; delay(50000);
                              }
                              if(!Down)
                              {
                              hour=hour-1; delay(50000);
                              }
                              }
                              if(mode==3)
                              {
                              if(!Up)
                              {
                              day=day+1; delay(50000);
                              }
                              if(!Down)
                              {
                              day=day-1; delay(50000);
                              }
                              }
                              if(mode==4)
                              {
                              if(!Up)
                              {
                              date=date+1; delay(50000);
                              }
                              if(!Down)
                              {
                              date=date-1; delay(50000);
                              }
                              }
                              if(mode==5)
                              {
                              if(!Up)
                              {
                              month=month+1; delay(50000);
                              }
                              if(!Down)
                              {
                              month=month-1; delay(50000);
                              }
                              }
                              if(mode==6)
                              {
                              if(!Up)
                              {
                              year=year+1; delay(50000);
                              }
                              if(!Down)
                              {
                              year=year-1; delay(50000);
                              }
                              }
                              }
                              if(!Alarm)
                              {
                              bip(); Display=1;
                              }
                              if(Display==1)
                              {
                              if(!Mode)
                              {
                              bip(); alarm++;
                              if(alarm==4)
                              {
                              alarm=1;
                              }
                              }
                              if(alarm==1)
                              {
                              if(!Up) //min++;
                              {
                              a_min=a_min+1; delay(50000);
                              }
                              if(!Down) //min--;
                              {
                              a_min=a_min-1; delay(50000);
                              }
                              }
                              if(alarm==2)
                              {
                              if(!Up) //hour++;
                              {
                              a_hour=a_hour+1; delay(50000);
                              }
                              if(!Down) //hour--;
                              {
                              a_hour=a_hour-1; delay(50000);
                              }
                              }
                              if(alarm==3)
                              {
                              if(!Up) //hour++;
                              {
                              on_off=1; delay(50000);
                              }
                              if(!Down) //hour--;
                              {
                              on_off=0; delay(50000);
                              }
                              }
                              }

                              //************************************************** *******************
                              Set_Clock();
                              delay(1000);
                              }
                              void T0_ISR(void) interrupt 1 // Dung ngat Timer0 de doc DS1307
                              {
                              TR0=0;
                              TF0=0;
                              TH0=0x3C; // Gia tri cho Timer0: 50000(us)x10=0.5(s)
                              TL0=0xAF;
                              time++;
                              if(time==10)
                              {
                              time=0; bat_nhay++; read_time=1;
                              if(bat_nhay==2) bat_nhay=0;
                              }
                              TR0=1;
                              }
                              /*************************************/
                              void T1_ISR(void) interrupt 3 // Dung ngat Timer1 de hien thi 15 Led_7D
                              {
                              TR1=0;
                              TF1=0;
                              TH1=0xFC; // Gia tri cho Timer1: 1000(us) x 15 = 15(ms)
                              TL1=0x18;
                              if(Display==0)
                              {
                              index++;
                              if(index==1)
                              {
                              Data=sec;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L01=1;
                              P0=led7_data[Data%10];//xuat gia tri hang don vi
                              }
                              if(index==2)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L02=1;
                              P0=led7_data[Data/10]; //xuat gia tri hang truc
                              }
                              //************************************************** ****************************
                              if(index==3)
                              {
                              if(mode==1 && bat_nhay==1){ index++; index++; }
                              else
                              {
                              Data=min;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L03=1;
                              P0=led7_data[Data%10];//xuat gia tri hang don vi
                              }
                              }
                              if(index==4)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L04=1;
                              P0=led7_data[Data/10]; //xuat gia tri hang truc
                              }
                              //************************************************** ****************************
                              if(index==5)
                              {
                              if(mode==2 && bat_nhay==1){ index++; index++; }
                              else
                              {
                              Data=hour;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L05=1;
                              P0=led7_data[Data%10];
                              }
                              }
                              if(index==6)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L06=1;
                              P0=led7_data[Data/10];
                              }
                              //************************************************** ****************************
                              if(index==7)
                              {
                              if(mode==3 && bat_nhay==1){ index++; }
                              else
                              {
                              Data=day;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L15=1;
                              P0=led7_data[Data%10];
                              }
                              }
                              //************************************************** ****************************
                              if(index==8)
                              {
                              if(mode==4 && bat_nhay==1){ index++; index++; }
                              else
                              {
                              Data=date;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L07=1;
                              P0=led7_data[Data/10];// xuat gia tri hang truc
                              }
                              }
                              if(index==9)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L08=1;
                              P0=led7_data[Data%10];//xuat gia tri hang don vi
                              }
                              //************************************************** ****************************
                              if(index==10)
                              {
                              if(mode==5 && bat_nhay==1){ index++; index++; }
                              else
                              {
                              Data=month;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L09=1;
                              P0=led7_data[Data/10];// xuat gia tri hang truc
                              }
                              }
                              if(index==11)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L10=1;
                              P0=led7_data[Data%10];//xuat gia tri hang don vi
                              }
                              //************************************************** ****************************
                              if(index==12)
                              {
                              if(mode==6 && bat_nhay==1){ index++; index++; }
                              else
                              {
                              Data=year;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L13=1;
                              P0=led7_data[Data/10];// xuat gia tri hang truc
                              }
                              }
                              if(index==13)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L14=1;
                              P0=led7_data[Data%10];//xuat gia tri hang don vi
                              }
                              if(index==14)
                              {
                              Data=year_20;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L11=1;
                              P0=led7_data[Data/10];// xuat gia tri hang truc
                              }
                              if(index==15)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L12=1;
                              P0=led7_data[Data%10];//xuat gia tri hang don vi
                              index=0;
                              }
                              }
                              if(Display==1)
                              {
                              index++;
                              if(index==1)
                              {
                              if(alarm==1 && bat_nhay==1){ index++; index++; }
                              else
                              {
                              Data=a_min;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L03=1;
                              P0=led7_data[Data%10];
                              }
                              }
                              if(index==2)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L04=1;
                              P0=led7_data[Data/10];
                              }
                              if(index==3)
                              {
                              if(alarm==2 && bat_nhay==1){ index++; index++; }
                              else
                              {
                              Data=a_hour;
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L05=1;
                              P0=led7_data[Data%10];
                              }
                              }
                              if(index==4)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L06=1;
                              P0=led7_data[Data/10];
                              }
                              if(index==5)
                              {
                              if(alarm==3 && bat_nhay==1){ index++; index++; }
                              else
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              if(on_off==1)
                              {
                              L13=1;
                              P0=0xC8;
                              }
                              else
                              {
                              L13=1;
                              P0=0x8E;
                              }
                              }
                              }
                              if(index==6)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              if(on_off==1)
                              {
                              L14=1;
                              P0=0xFF;
                              }
                              else
                              {
                              L14=1;
                              P0=0x8E;
                              }
                              }
                              if(index==7)
                              {
                              P2=0x00; L09=L10=L11=L12=L13=L14=L15=0;
                              P0=0xff;
                              L12=1;
                              P0=led7_data[0];
                              index=0;
                              }
                              }

                              //************************************************** ****************************
                              TR1=1;
                              }
                              //************ CHUONG TRINH CHINH *************
                              void main()
                              {
                              bip(); delay(10);
                              Out_1Hz();

                              set_main();
                              year_20=20;
                              time=index=mode=read_time=0;
                              setup_timer();
                              while(1)
                              {
                              Keypad();
                              if(hour>=12) PM=0;
                              else PM=1;
                              if((mode==0)&&(read_time==1))
                              {
                              read_time = 0;
                              Read_DS1307();
                              }
                              if(((a_min==min)&&(a_hour==hour)))
                              {
                              if(sec<59) { bip(); delay(10000);}
                              }
                              }
                              }
                              ? M? Ngu?n Chương Tr?nh đ?ng h? s? Keil C
                              #include<regx52.h>
                              #include<math.h>
                              unsigned char a,b,nd;
                              unsigned char M[10]={0x40,0x79,0x24,0x30,0x19,0x12,0x03,0x78,0x00,0x1 8};
                              void delay(unsigned char time)
                              {
                              unsigned char i,j;
                              for(i=1;i<10;i++)
                              for(j=1;j<time;j++)
                              {}
                              }
                              void hienthi(void)
                              {
                              a=nd/10;
                              b=nd%10;
                              P3=M[a];
                              P0_0=1;
                              P0_0=0;
                              delay(2);
                              P3=M[b];
                              P0_1=1; //mo
                              P0_1=0; //chot
                              delay(2);
                              }
                              void chuyendoi(void)
                              {
                              P1_0=1; //RD=1
                              P1_1=0; //WR=0
                              delay(2);
                              P1_1=1; //WR=1 bat dau chuyen doi
                              while(P1_2);//cho cho chuyen doi xong
                              P1_0=0; //dua du lieu ra cac chan D0 - D7
                              nd=P2;
                              }
                              void main()
                              {
                              P2=0xff; //dat P2 lam cong vao
                              P1_2=1; //dat P1_2 lam cong vao INTR
                              while(1)
                              {
                              chuyendoi();
                              hienthi();
                              }
                              Last edited by bitbabon170; 22-05-2012, 01:37.

                              Comment

                              Về tác giả

                              Collapse

                              chumanh Tìm hiểu thêm về chumanh

                              Bài viết mới nhất

                              Collapse

                              Đang tải...
                              X