Đồng hồ số chạy quá lệch thời gian! Giúp mình với các bạn ơi.....

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • tienrau2
    Nhập môn đệ tử
    • Nov 2012
    • 3

    #1

    Đồng hồ số chạy quá lệch thời gian! Giúp mình với các bạn ơi.....

    mình mới học VDK về Pic, làm đồ án mạch đồng hồ số dùng PIC 16F887A và DS1307. Viết được đoạn code nhận thời gian từ DS1307 và hiển thị lên Led, nhưng sao cái mô phỏng nó chạy chậm quá. Không đúng với đồng hồ mình so sánh ở máy tính. Mấy bạn xem giùm mình với nha. Có thể sữa ở chỗ nào?
    Code:
    #include <16F877A.h>
    #FUSES NOWDT, HS, NOPUT, PROTECT, NODEBUG, NOBROWNOUT, NOLVP
    #use delay(clock=20000000)
    #use i2c(master,fast,sda=pin_d7,scl=pin_d6)

    unsigned char sec,min,hour,day,month,year,date;
    unsigned char a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
    unsigned char sec1,sec2,min1,min2,hour1,hour2,day1,day2,month1,m onth2,year1,year2;
    ///////////define//////
    void update_time();
    void display1();
    void main()
    {
    while (1) {
    update_time();
    display1();
    }
    }
    void update_time() {
    i2c_start();
    i2c_write(0xD0); //Gui dia chi cua slave
    i2c_write(0x00); //thiet lap lai con tro - set register pointer
    i2c_stop();
    I2C_start();
    I2C_write(0xD1); /* gui lenh doc du lieu */
    sec = i2c_read(1);
    min = i2c_read(1);
    hour = i2c_read(1);
    date =i2c_read(1);
    day = i2c_read(1);
    month = i2c_read(1);
    year = i2c_read(0);

    i2c_stop();
    sec1=sec & 0x0F;
    sec2=(sec & 0x70)>>4;
    min1=min & 0x0F;
    min2=(min & 0x70)>>4;
    hour1=hour & 0x0F;
    hour2=(hour & 0x30)>>4;
    day1=day & 0x0F;
    day2=(day & 0x30)>>4;
    month1=month & 0x0F;
    month2=(month & 0x10)>>4;
    year1=year & 0x0F;
    year2=(year & 0xF0)>>4;
    }
    void display1()
    {
    output_b(a[sec1]); output_high(pin_c0);//SEC1
    delay_us(400); output_low(pin_c0);
    output_b(a[sec2]); output_high(pin_c1);//SEC2
    delay_us(400); output_low(pin_c1);
    output_b(a[min1]); output_high(pin_c2);//SEC1
    delay_us(400); output_low(pin_c2);
    output_b(a[min2]); output_high(pin_c3);//SEC2
    delay_us(400); output_low(pin_c3);
    output_b(a[hour1]); output_high(pin_c4);//SEC1
    delay_us(400); output_low(pin_c4);
    output_b(a[hour2]); output_high(pin_c5);//SEC2
    delay_us(400); output_low(pin_c5);
    output_b(a[day1]); output_high(pin_c6);//SEC1
    delay_us(400); output_low(pin_c6);
    output_b(a[day2]); output_high(pin_c7);//SEC2
    delay_us(400); output_low(pin_c7);
    output_b(a[month1]); output_high(pin_d0);//SEC1
    delay_us(400); output_low(pin_d0);
    output_b(a[month2]); output_high(pin_d1);//SEC2
    delay_us(400); output_low(pin_d1);
    output_b(a[2]); output_high(pin_d2);//SEC1
    delay_us(400); output_low(pin_d2);
    output_b(a[0]); output_high(pin_d3);//SEC2
    delay_us(400); output_low(pin_d3);
    output_b(a[year1]); output_high(pin_d4);//SEC1
    delay_us(400); output_low(pin_d4);
    output_b(a[year2]); output_high(pin_d5);//SEC2
    delay_us(400); output_low(pin_d5);
    }
    Còn đây là file mô phỏng và code:
    Attached Files
  • qloi
    Đệ tử 3 túi
    • Sep 2010
    • 55

    #2
    Nguyên văn bởi tienrau2 View Post
    mình mới học VDK về Pic, làm đồ án mạch đồng hồ số dùng PIC 16F887A và DS1307. Viết được đoạn code nhận thời gian từ DS1307 và hiển thị lên Led, nhưng sao cái mô phỏng nó chạy chậm quá. Không đúng với đồng hồ mình so sánh ở máy tính. Mấy bạn xem giùm mình với nha. Có thể sữa ở chỗ nào?
    Code:
    #include <16F877A.h>
    #FUSES NOWDT, HS, NOPUT, PROTECT, NODEBUG, NOBROWNOUT, NOLVP
    #use delay(clock=20000000)
    #use i2c(master,fast,sda=pin_d7,scl=pin_d6)

    unsigned char sec,min,hour,day,month,year,date;
    unsigned char a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
    unsigned char sec1,sec2,min1,min2,hour1,hour2,day1,day2,month1,m onth2,year1,year2;
    ///////////define//////
    void update_time();
    void display1();
    void main()
    {
    while (1) {
    update_time();
    display1();
    }
    }
    void update_time() {
    i2c_start();
    i2c_write(0xD0); //Gui dia chi cua slave
    i2c_write(0x00); //thiet lap lai con tro - set register pointer
    i2c_stop();
    I2C_start();
    I2C_write(0xD1); /* gui lenh doc du lieu */
    sec = i2c_read(1);
    min = i2c_read(1);
    hour = i2c_read(1);
    date =i2c_read(1);
    day = i2c_read(1);
    month = i2c_read(1);
    year = i2c_read(0);

    i2c_stop();
    sec1=sec & 0x0F;
    sec2=(sec & 0x70)>>4;
    min1=min & 0x0F;
    min2=(min & 0x70)>>4;
    hour1=hour & 0x0F;
    hour2=(hour & 0x30)>>4;
    day1=day & 0x0F;
    day2=(day & 0x30)>>4;
    month1=month & 0x0F;
    month2=(month & 0x10)>>4;
    year1=year & 0x0F;
    year2=(year & 0xF0)>>4;
    }
    void display1()
    {
    output_b(a[sec1]); output_high(pin_c0);//SEC1
    delay_us(400); output_low(pin_c0);
    output_b(a[sec2]); output_high(pin_c1);//SEC2
    delay_us(400); output_low(pin_c1);
    output_b(a[min1]); output_high(pin_c2);//SEC1
    delay_us(400); output_low(pin_c2);
    output_b(a[min2]); output_high(pin_c3);//SEC2
    delay_us(400); output_low(pin_c3);
    output_b(a[hour1]); output_high(pin_c4);//SEC1
    delay_us(400); output_low(pin_c4);
    output_b(a[hour2]); output_high(pin_c5);//SEC2
    delay_us(400); output_low(pin_c5);
    output_b(a[day1]); output_high(pin_c6);//SEC1
    delay_us(400); output_low(pin_c6);
    output_b(a[day2]); output_high(pin_c7);//SEC2
    delay_us(400); output_low(pin_c7);
    output_b(a[month1]); output_high(pin_d0);//SEC1
    delay_us(400); output_low(pin_d0);
    output_b(a[month2]); output_high(pin_d1);//SEC2
    delay_us(400); output_low(pin_d1);
    output_b(a[2]); output_high(pin_d2);//SEC1
    delay_us(400); output_low(pin_d2);
    output_b(a[0]); output_high(pin_d3);//SEC2
    delay_us(400); output_low(pin_d3);
    output_b(a[year1]); output_high(pin_d4);//SEC1
    delay_us(400); output_low(pin_d4);
    output_b(a[year2]); output_high(pin_d5);//SEC2
    delay_us(400); output_low(pin_d5);
    }
    Còn đây là file mô phỏng và code:
    Mấy cái này không mô phỏng được đâu , test trực tiếp trên mạch thiệt là được thoy.
    heart.touching.2010@gmail.com!

    Comment

    • quanghuy_125
      Đệ tử 2 túi
      • Apr 2009
      • 44

      #3
      Ds1307

      Nguyên văn bởi tienrau2 View Post
      mình mới học VDK về Pic, làm đồ án mạch đồng hồ số dùng PIC 16F887A và DS1307. Viết được đoạn code nhận thời gian từ DS1307 và hiển thị lên Led, nhưng sao cái mô phỏng nó chạy chậm quá. Không đúng với đồng hồ mình so sánh ở máy tính. Mấy bạn xem giùm mình với nha. Có thể sữa ở chỗ nào?
      Code:
      #include <16F877A.h>
      #FUSES NOWDT, HS, NOPUT, PROTECT, NODEBUG, NOBROWNOUT, NOLVP
      #use delay(clock=20000000)
      #use i2c(master,fast,sda=pin_d7,scl=pin_d6)

      unsigned char sec,min,hour,day,month,year,date;
      unsigned char a[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x9 0};
      unsigned char sec1,sec2,min1,min2,hour1,hour2,day1,day2,month1,m onth2,year1,year2;
      ///////////define//////
      void update_time();
      void display1();
      void main()
      {
      while (1) {
      update_time();
      display1();
      }
      }
      void update_time() {
      i2c_start();
      i2c_write(0xD0); //Gui dia chi cua slave
      i2c_write(0x00); //thiet lap lai con tro - set register pointer
      i2c_stop();
      I2C_start();
      I2C_write(0xD1); /* gui lenh doc du lieu */
      sec = i2c_read(1);
      min = i2c_read(1);
      hour = i2c_read(1);
      date =i2c_read(1);
      day = i2c_read(1);
      month = i2c_read(1);
      year = i2c_read(0);

      i2c_stop();
      sec1=sec & 0x0F;
      sec2=(sec & 0x70)>>4;
      min1=min & 0x0F;
      min2=(min & 0x70)>>4;
      hour1=hour & 0x0F;
      hour2=(hour & 0x30)>>4;
      day1=day & 0x0F;
      day2=(day & 0x30)>>4;
      month1=month & 0x0F;
      month2=(month & 0x10)>>4;
      year1=year & 0x0F;
      year2=(year & 0xF0)>>4;
      }
      void display1()
      {
      output_b(a[sec1]); output_high(pin_c0);//SEC1
      delay_us(400); output_low(pin_c0);
      output_b(a[sec2]); output_high(pin_c1);//SEC2
      delay_us(400); output_low(pin_c1);
      output_b(a[min1]); output_high(pin_c2);//SEC1
      delay_us(400); output_low(pin_c2);
      output_b(a[min2]); output_high(pin_c3);//SEC2
      delay_us(400); output_low(pin_c3);
      output_b(a[hour1]); output_high(pin_c4);//SEC1
      delay_us(400); output_low(pin_c4);
      output_b(a[hour2]); output_high(pin_c5);//SEC2
      delay_us(400); output_low(pin_c5);
      output_b(a[day1]); output_high(pin_c6);//SEC1
      delay_us(400); output_low(pin_c6);
      output_b(a[day2]); output_high(pin_c7);//SEC2
      delay_us(400); output_low(pin_c7);
      output_b(a[month1]); output_high(pin_d0);//SEC1
      delay_us(400); output_low(pin_d0);
      output_b(a[month2]); output_high(pin_d1);//SEC2
      delay_us(400); output_low(pin_d1);
      output_b(a[2]); output_high(pin_d2);//SEC1
      delay_us(400); output_low(pin_d2);
      output_b(a[0]); output_high(pin_d3);//SEC2
      delay_us(400); output_low(pin_d3);
      output_b(a[year1]); output_high(pin_d4);//SEC1
      delay_us(400); output_low(pin_d4);
      output_b(a[year2]); output_high(pin_d5);//SEC2
      delay_us(400); output_low(pin_d5);
      }
      Còn đây là file mô phỏng và code:
      Mình thấy bài mo phỏng của bạn trên Proteus là đúng đấy. Proteus chạy mô phỏng sẽ chậm hơn đồng hồ thực ở máy tính, bạn phải nhìn và so sánh với thời gian ở góc trái ở dưới của time line Proteus ấy!
      Chúc vui!
      ĐT : 0167 6455 880 Mail: quanghuy1205@gmail.com
      https://www.facebook.com/ThietKeDienTu

      Comment

      • trasuasang
        Nhập môn đệ tử
        • Aug 2011
        • 1

        #4
        chào các bạn, các bạn cho mình hỏi với mạch đồng hồ thời gian như thế này,,lúc mình làm mạch thật thì mình phải thêm vào các điện trở vào trước các led 7 đoạn và các transistor trước các nút nguồn của các led 7s phai ko,,nhưng lúc mô phỏng thì nó lại chạy sai thời gian..

        Comment

        Working...