大家好我所使用的是PIC18F4550
我把霍尔编码器的A向接在CCP2抓取脉波
霍尔编码器的VCC接上5V
接上超级终端机却无任何反应 不知道是哪里出问题了
#include <20160225MOTORTEST.h>
unsigned int flag_counter=0;
#INT_CCP2
void CCP2_isr(void)
{
flag_counter++;
if(flag_counter==5000)
{
printf("%d\n\r",flag_counter);
flag_counter=0;
}
}
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1); //13.1 ms overflow
setup_timer_2(T2_DIV_BY_4,249,1); //200 us overflow, 200 us interrupt
setup_ccp1(CCP_PWM|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
setup_ccp2(CCP_CAPTURE_RE);
set_pwm1_duty((int16)798);
enable_interrupts(INT_CCP2);
enable_interrupts(GLOBAL);
while(TRUE)
{
output_bit(PIN_D0 , 1); //1和0搭配是反转
output_bit(PIN_D1 , 0);
}
}