06-05-2009, 01:30 PM | #14 |
Đệ tử 6 túi
Tham gia ngày: Oct 2008
Nơi Cư Ngụ: HCM
Bài gửi: 137
: |
Hỏi cách thiết lập timer1 là counter đếm xung ngoài!?
#int_timer1
void timer1_ext_isr(void) { count++; rpm++; } void main() { set_tris_a(0x00); set_tris_b(0x01); set_tris_c(0x8f); set_tris_e(0xff); set_tris_d(0x00); set_timer1(65335);//200xung=65535-65335 setup_timer_1(T1_EXTERNAL); enable_interrupts(int_timer1); ENABLE_INTERRUPTS(GLOBAL); count=0; rpm=0; while(TRUE) { led_scan(count/100,led5); led_scan((count/10)%10,led6); led_scan(count%10,led7); led_scan(rpm/1000,led1); led_scan((rpm/100)%10,led2); led_scan((rpm%100)/10,led3); led_scan((rpm%100)%10,led4); } } Encoder nối RC0 :200xung/vòng nhưng sao mình thấy động cơ quay cả chục vòng thì 2 biến count,rpm mới tăng lên 1 đơn vị.Có bác nào biết tại sao không? |
|
|