Aquí les comparto parte del código.
El problema se da en la condición IF en dónde compara la variable rebot==200, la variable se incrementa aparentemente pero por algún motivo, NO llega al valor 200 o bien lo saltea!
#include <18F2550.h>
//#device adc=10
#fuses NOWDT, HSPLL, NOPUT, PROTECT, NODEBUG, NOBROWNOUT, NOLVP, NOCPD, NOWRT, CPUDIV1, PLL3, NOMCLR, NOVREGEN, RESERVED
#use delay (clock=12000000)
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#zero_ram
///////////////////////////////////////////////////////////////////////////////
static int bufl[1950];
static int ptc=1;
static long rebot, x, y, pitch=130;
void main(void)
{
set_tris_a(0b11111111);
set_tris_b(0b00000000);
set_tris_c(0b00000011);
output_b(0);
///////////////////////////////////////////////////////////////////////////////
setup_adc( ADC_CLOCK_DIV_2);
setup_adc_ports(AN0|VREF_VREF); // VRef_min=A2 Vref_max=A3
set_adc_channel(0); // Habilita A0= ent Analog
read_adc(ADC_START_ONLY);
//ADFM=1;
///////////////////////////////////////////////////////////////////////////////
setup_timer_2(T2_DIV_BY_1,255,1);
setup_ccp1(CCP_PWM);
//CCP1CON=0b00001100;
///////////////////////////////////////////////////////////////////////////////
setup_timer_0(T0_INTERNAL|T0_8_BIT|T0_DIV_2);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
//setup_timer_2(T2_DIV_BY_1,1,1);
///////////////////////////////////////////////////////////////////////////////
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_TIMER1);
disable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
while(true)
{
if(!RC0||!RC1) // Lee botón (A4=-) (A4=+)
{
if(rebot==200) // ===> La variable rebot no se incrementa cuándo debe
{
...
}
if(rebot<500)rebot++;
}
else rebot=0;
}
}
#INT_GLOBAL
void isr_global()
{
if(TMR0IF)
{
TMR0IF=0; // Resetea bit interrup
...
}
if(TMR1IF)
{
TMR1IF=0; // Resetea bit interrup
...
}
}