Giúp e cái code encoder này với mọi người ơi
E muốn đọc tốc độ từ encoder nhưng không biết sai ở đâu cả.Hixhix.Cả nhà giúp e với.E muốn đọc 2 encoder dùng 1 pic 16f877a.Dùng ngắt ngoài INT_EXT và TIMER0 tín hiệu vào là chân RB0 và RB1 e đã làm được rồi nhưng dùng ngắt RB thì ko biết lỗi ở đâu cả.Cả nhà test hộ e với.
Đây là code ạ: #include <16f877a.h> #fuses HS, NOWDT,NOPROTECT , NOLVP #use delay(clock=20000000) #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bi ts=8) #include <Lcd_lib_4bit.c> #include <stdlib.h> #include <stdlibm.h> int32 dem; int32 counterb; float speed; #INT_RB void encoder_ISR() { counterb++; // printf("\n\r%lu", counterb); } #INT_TIMER1 void Sampling_Time() { set_timer1(59286); ++dem; if(dem==5000) { dem=0; speed=(float)counterb/10; } } void main(void) { set_tris_B(0xFF); //counterb = 0; // port_b_pullups(TRUE); enable_interrupts(INT_RB); enable_interrupts(GLOBAL); enable_interrupts(INT_TIMER1); setup_timer_1(RTCC_INTERNAL|T1_DIV_BY_2); LCD_init(); //LCD_PutCmd(0x05); printf(LCD_PutChar,"Speed wind"); LCD_PutCmd(0xC0); printf(LCD_PutChar,"Speed %u v/s",speed); while (true) { } // disable_interrupts(INT_RB); //disable_interrupts(GLOBAL); set_timer1(59286); //port_b_pullups(TRUE); } |
Chu viet the thi chay the nao duoc
|
Múi giờ GMT. Hiện tại là 09:12 PM. |
Tên diễn đàn: vBulletin Version 3.8.11
Được sáng lập bởi Đoàn Hiệp.
Copyright © PIC Vietnam