C2 Con Interrupcion
C2 Con Interrupcion
h>
#device ADC = 10
#fuses NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,INTRC_IO,NOMCLR
#use delay(clock=4MHZ)
#include <math.h>
long vin0;
//long vin1;
int8 A=0;
int8 B=0;
int8 C=0;
int8 D=0;
int32 n=1;
int32 pulso;
#int_ext
void PortA_Interrupt(void)
C = 1;
D = 1;
//delay_ms(1);
}
void motor_pap()
while(C==1)
if(input(pin_a3)==1)
delay_ms(200);
n = n+1;
if(input(pin_a4)==1)
delay_ms(200);
n = n-1;
if((input(pin_c7)==1)&&(C==1))
delay_ms(200);
C = 0;
output_high(pin_b4);//ENABLE
output_low(pin_b5);//DIRECCION
for(pulso=0;pulso<(1600*n);pulso++)
output_high(pin_b6);//PULSO
delay_ms(5);
output_low(pin_b6);//PULSO
delay_ms(5);
C = 0;
pulso = 0;
output_low(pin_b4);//ENABLE
D = 0;
void vin_0()
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
delay_ms(1);
vin0=read_adc();
delay_ms(1);
setup_adc(ADC_OFF);
if((vin0<=402)&&(B==0))
portc=0x00;
A = 0;
//B = 0;
if((vin0>=504)&&(A==0))
//delay_ms(5);
A = 1;
}
if((A==1)&&(vin0>=612))
//delay_ms(5);
A = 2;
switch(A)
case 1:
portc=0x01;
break;
case 2:
portc=0x03;
break;
if(vin0>=401)
B = 0;
if(vin0<=310)
B = 1;
switch(B)
case 1:
portc=0x04;
break;
void main(void)
PORTC = 0x00;
PORTB = 0x00;
set_tris_A(0xFF);
set_tris_B(0x00);
set_tris_C(0x80);
//setup_oscillator(OSC_8MHZ|OSC_INTRC);
enable_interrupts(GLOBAL);
enable_interrupts(INT_EXT);
ext_int_edge(L_TO_H);
//enable_interrupts(INT_RA5);
while(true)
delay_ms(350);
vin_0();
if(D==1)
delay_ms(1);
motor_pap();