View Single Post
Old 31-12-2008, 07:18 PM   #17
daythienha2007
Đệ tử 2 túi
 
Tham gia ngày: Apr 2008
Bài gửi: 26
:
Trích:
Nguyên văn bởi nms48 View Post
cho mình hỏi tí: minh mô phỏng mà chay kô đúng ,có ai biết chương trình còn sai chỗ nào kô.(mình thấy timer0 chay ko đúng.timer1 thì dường như là chưa chạy)

nguyen lý như sau: lúc có xung cạnh lên thì khởi tạo timer0 5ms.khi timer0 tràn thì xuất xung ra D0 và khời tạo timer1 10ms.khi timer1 tràn thì xuất xung ra D1,bình thường thì xuất xung ra D2

chương trình mình như sau:

Code:
#include <16f877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)

// ngat ngoai---------------
#int_EXT
void EXT_isr()
{
   set_timer0(40534);           //khoi tao timer0 5ms thi tran

}

//ngat timer0------------------
#int_timer0
void timer0_isr()
{
    output_high(pin_D0);
    delay_us(10);
    output_low(pin_D0);
    set_timer1(15534);           // khoi tao timer1 10ms

}
//ngat timer1--------------
#int_timer1
void timer1_isr()
{    output_high(pin_D1);
     delay_us(10);
     output_low(pin_D1);
}

// chuong trinh chinh
void main()
{
   enable_interrupts(INT_EXT);
   ext_int_edge(L_TO_H);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   enable_interrupts(int_timer0);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   enable_interrupts(int_timer1);
   enable_interrupts(global);

while(true)
{
   output_high(pin_d2);
   delay_ms(100);
   output_low(pin_d2);
    delay_ms(100);
}
}
cám ơn các bạn rất nhiều và mong được giúp đỡ sớm
Khi bạn thiết lập timer :" setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
enable_interrupts(int_timer0); "
thì timer0ddax chạy rôif,khong fải tới lúc bạn set_timer0 nó mới chạy đâu.Tương tự đối với timer1.Hơn nưa Thời gian bạn delay quá ngắn,sao bạn biết timer1 ko chạy
daythienha2007 vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn