RP Store Tìm linh kiện theo mã, gửi BOM nhận báo giá Gửi BOM

cần Giúp hàm Delay_ms...

Collapse
X
 
  • Giờ
  • Show
Clear All
new posts
  • thuanbk1989
    Nhập môn đệ tử
    • Mar 2012
    • 8

    #1

    cần Giúp hàm Delay_ms...

    hi!
    Chào mọi người. mọi người giúp e với nhé.
    E dùng lệnh delay_ms(10000); nói chung là lệnh delay thì nó chạy k có đúng lệnh delay_ms(10000) mà nó chạy 13,5s lận. e phải làm sao giờ tại e cần độ chính xác xíu.
    Nọi thứ đều hoạt động tốt chỉ sai chỗ này thui .e có dùng lênh #use delay( clock = 20000000)
    CODE:
    #int_EXT
    #use delay( clock = 20000000)
    void EXT_isr(void)
    {
    //delay_ms(1000);
    Output_high(pin_a1);
    //delay_ms(2000);
    }
    void main()
    {

    setup_adc_ports(sAN0|VSS_VDD);
    setup_adc(ADC_CLOCK_DIV_2);
    setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
    setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
    setup_timer_2(T2_DISABLED,0,1);
    setup_ccp1(CCP_OFF);
    setup_comparator(NC_NC_NC_NC);
    setup_vref(FALSE);
    enable_interrupts(INT_EXT);
    enable_interrupts(GLOBAL);
    ext_int_edge (0 ,L_TO_H) ; //chon kieu ngat tu muc thap len cao
    //Setup_Oscillator parameter not selected from Intr Oscillator Config tab

    // TODO: USER CODE!!
    set_tris_a(0b00000101);
    //set_tris_c(0b00000000);

    while(1) {
    Output_high(pin_a1);
    delay_ms(5000);
    Output_low(pin_a1);
    delay_ms(5000);

    }
    cảm ơn moi người trước nhé
  • thuanbk1989
    Nhập môn đệ tử
    • Mar 2012
    • 8

    #2
    Ai ghé qua giúp e nhé

    Comment

    • thuanbk1989
      Nhập môn đệ tử
      • Mar 2012
      • 8

      #3
      Chawcs ngày lễ không ai giúp cả

      Comment

      • buivantuyen89th
        Đệ tử 3 túi
        • Jun 2012
        • 54

        #4
        Nguyên văn bởi thuanbk1989 View Post
        hi!
        Chào mọi người. mọi người giúp e với nhé.
        E dùng lệnh delay_ms(10000); nói chung là lệnh delay thì nó chạy k có đúng lệnh delay_ms(10000) mà nó chạy 13,5s lận. e phải làm sao giờ tại e cần độ chính xác xíu.
        Nọi thứ đều hoạt động tốt chỉ sai chỗ này thui .e có dùng lênh #use delay( clock = 20000000)
        CODE:
        #int_EXT
        #use delay( clock = 20000000)
        void EXT_isr(void)
        {
        //delay_ms(1000);
        Output_high(pin_a1);
        //delay_ms(2000);
        }
        void main()
        {

        setup_adc_ports(sAN0|VSS_VDD);
        setup_adc(ADC_CLOCK_DIV_2);
        setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
        setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
        setup_timer_2(T2_DISABLED,0,1);
        setup_ccp1(CCP_OFF);
        setup_comparator(NC_NC_NC_NC);
        setup_vref(FALSE);
        enable_interrupts(INT_EXT);
        enable_interrupts(GLOBAL);
        ext_int_edge (0 ,L_TO_H) ; //chon kieu ngat tu muc thap len cao
        //Setup_Oscillator parameter not selected from Intr Oscillator Config tab

        // TODO: USER CODE!!
        set_tris_a(0b00000101);
        //set_tris_c(0b00000000);

        while(1) {
        Output_high(pin_a1);
        delay_ms(5000);
        Output_low(pin_a1);
        delay_ms(5000);

        }
        cảm ơn moi người trước nhé
        Mình cũng chưa có điều kiện thử độ chính xác của delay.hi. nhưng mình nghĩ thế này.bạn làm xem có được không nhé.
        bỏ hết các ngắt khác ( chỉ để mình ngắt ngoài để kiểm tra) và chuyển lệnh use delay lên bên trên int_EXT.
        Chúc bạn thành công!

        Comment

        • binhbk247
          Đệ tử 2 túi
          • Jun 2011
          • 37

          #5
          Delay bị sai chủ yếu do mạch. Trong code chỉ cần bạn khai báo đúng tần số thạch anh mà bạn sử dụng là được. Nếu đã khai báo đúng rồi mà vẫn sai thì có thể do thạch anh hư, do chip ko nhận thạch anh và cũng có thể do 2 con tụ dao dộng. Bạn thử thay thạch anh thử. Mình gặp nhiều trường hợp bị lỗi thạch anh rồi lắm

          Comment

          Working...