28-12-2008, 04:47 PM | #14 |
Đệ tử 1 túi
Tham gia ngày: Dec 2008
Bài gửi: 11
: |
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); } } thay đổi nội dung bởi: nms48, 31-12-2008 lúc 10:47 AM. |
|
|