RaulBlanco
07-08-2008, 03:51 PM
Em dùng con PIC 16F877A để đọc xung từ encoder về. 10ms thì xuất xung đọc được lên terminal v1.9b. Em đặt lệnh printf(xung) trong chương trình ngắt của timer tuy nhiên lại ko nhận dc gì cả. Xin các đại ca giúp đỡ. Đây là code của em://chuong trinh ve dap ung he thong vong mo bang CT terminal voi tan so 19.61khz, %duty=50%, khong tai
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6, rcv=PIN_C7)
#include <def_877a.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
char data;
int a;
int16 xung,v;
#INT_EXT
void ngat_RB()
{
xung++;
}
#INT_TIMER1
void timer1_isr()
{
v=xung*100/108;// v la van toc tuc thoi DC don vi vong/s
printf(v);//xuat ra termal van toc tuc thoi cua DC
set_timer1(59286);//lay mau trong 10ms
xung=0;
}
void main()
{
xung=0;
set_tris_b(0x01);
setup_timer_1 ( T1_DIV_BY_8);
ENABLE_INTERRUPTS(INT_EXT);
ext_int_edge(0,L_TO_H);
ENABLE_INTERRUPTS(INT_TIMER1);
ENABLE_INTERRUPTS(GLOBAL);
setup_timer_2 ( T2_DIV_BY_1, 255, 1);
set_timer1(59286);
while(1)
{ setup_ccp1(CCP_PWM);
setup_ccp2(CCP_OFF);
output_high(PIN_C3);
output_low(PIN_C4);
set_pwm1_duty(510);// %duty la 50 %
}
}//chay chung khoang vai giay thi ngung lay so lieu ve do thi.
#include <16F877a.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6, rcv=PIN_C7)
#include <def_877a.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
char data;
int a;
int16 xung,v;
#INT_EXT
void ngat_RB()
{
xung++;
}
#INT_TIMER1
void timer1_isr()
{
v=xung*100/108;// v la van toc tuc thoi DC don vi vong/s
printf(v);//xuat ra termal van toc tuc thoi cua DC
set_timer1(59286);//lay mau trong 10ms
xung=0;
}
void main()
{
xung=0;
set_tris_b(0x01);
setup_timer_1 ( T1_DIV_BY_8);
ENABLE_INTERRUPTS(INT_EXT);
ext_int_edge(0,L_TO_H);
ENABLE_INTERRUPTS(INT_TIMER1);
ENABLE_INTERRUPTS(GLOBAL);
setup_timer_2 ( T2_DIV_BY_1, 255, 1);
set_timer1(59286);
while(1)
{ setup_ccp1(CCP_PWM);
setup_ccp2(CCP_OFF);
output_high(PIN_C3);
output_low(PIN_C4);
set_pwm1_duty(510);// %duty la 50 %
}
}//chay chung khoang vai giay thi ngung lay so lieu ve do thi.