0% found this document useful (0 votes)
19 views5 pages

C2 Con Interrupcion

This document contains code for a microcontroller program that controls a motor and reads analog sensor input. It defines pin configurations and interrupt routines. The main loop calls functions to read the analog sensor voltage, control motor direction and pulsing based on the sensor reading, and respond to an external interrupt by setting flags to start the motor.

Uploaded by

Carlos Gallardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views5 pages

C2 Con Interrupcion

This document contains code for a microcontroller program that controls a motor and reads analog sensor input. It defines pin configurations and interrupt routines. The main loop calls functions to read the analog sensor voltage, control motor direction and pulsing based on the sensor reading, and respond to an external interrupt by setting flags to start the motor.

Uploaded by

Carlos Gallardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

#include <16F690.

h>

#device ADC = 10

#fuses NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,INTRC_IO,NOMCLR

#use delay(clock=4MHZ)

#include <math.h>

#BYTE TRISA = 0x85

#BYTE PORTA = 0x05

#BYTE TRISB = 0x86

#BYTE PORTB = 0x06

#BYTE TRISC = 0x87

#BYTE PORTC = 0x07

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();

You might also like