Created
October 27, 2017 17:00
-
-
Save esmarr58/45e95c6c4ceb5625fd5298e323126cea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <16f84a.h> //PIC a utilizar | |
#fuses XT,NOWDT,NOPROTECT,NOPUT //ordenes para el programador | |
#use delay (clock=4000000) //Se usaran retardos tomando en cuenta que la frecuencia del | |
//oscilador es de 4Mhz | |
#use fast_io(a) //Rápida entrada y salida | |
int Modo=1, Temp=1, i=0; //Declaración de variables del tipo entero | |
//Prototipo de la funcion que configurara los puertos | |
void Config_Puertos(void); | |
//Funciones de interrupciones | |
#INT_EXT //Para la interrupción INT (RB0) | |
void EXT_isr(void) | |
{ | |
Modo++; | |
if(Modo==3) | |
{ | |
Modo=1; | |
Temp=1; | |
} | |
} | |
#INT_RB //Para la interrupción RB (RB4) | |
void RB_isr(void) | |
{ | |
if(input(PIN_B4)) | |
{ | |
Temp++; | |
} | |
if(Modo==1 && Temp==3) | |
{ | |
Temp=1; | |
} | |
if(Modo==2 && Temp==4) | |
{ | |
Temp=1; | |
} | |
} | |
///Programa principal | |
void main(void) | |
{ | |
Config_Puertos();//Llamado a funcion | |
while(true) | |
{ | |
if(Modo==1)//Modo automatico | |
{ | |
output_low(PIN_A2); //led verde off | |
output_low(PIN_A1); //led amarillo off | |
output_low(PIN_A0); //led rojo off | |
if(Temp==1)//Temporizacion 1 | |
{ | |
output_high(PIN_A2); //led verde on | |
delay_ms(6000); | |
output_low(PIN_A2); //led rojo off | |
for(i=0;i<=4;i++) | |
{ | |
output_high(PIN_A1); //led amarillo on | |
delay_ms(500); | |
output_low(PIN_A1); //led amarillo off | |
delay_ms(500); | |
} | |
output_high(PIN_A0);//lrd rojo on | |
delay_ms(4000); | |
output_low(PIN_A0); //led rojo off | |
} | |
if(Temp==2)//Temporizacion 2 | |
{ | |
output_high(PIN_A2); //led verde on | |
delay_ms(4000); | |
output_low(PIN_A2); //led rojo off | |
for(i=0;i<=3;i++) | |
{ | |
output_high(PIN_A1); //led amarillo on | |
delay_ms(500); | |
output_low(PIN_A1); //led amarillo off | |
delay_ms(500); | |
} | |
output_high(PIN_A0);//lrd rojo on | |
delay_ms(6000); | |
output_low(PIN_A0); //led rojo off | |
} | |
} | |
if(Modo==2)//Modo manual | |
{ | |
while(Temp==1) | |
{ | |
output_high(PIN_A2); //led verde on | |
output_low(PIN_A1); //led amarillo off | |
output_low(PIN_A0); //led rojo off | |
} | |
while(Temp==2) | |
{ | |
output_low(PIN_A2); //led verde off | |
output_high(PIN_A1); //led amarillo on | |
delay_ms(500); | |
output_low(PIN_A1); //led amarillo off | |
delay_ms(500); | |
output_low(PIN_A0); //led rojo off | |
} | |
while(Temp==3) | |
{ | |
output_low(PIN_A2); //led verde off | |
output_low(PIN_A1); //led amarillo off | |
output_high(PIN_A0); //led rojo on | |
} | |
} | |
} //bucle infinito | |
} | |
void Config_Puertos(void) | |
{ | |
set_tris_A(0xF8); //portA como salidas(RA0, RA1 y RA2 ,las demas desactivadas) | |
set_tris_B(0xFF); | |
enable_interrupts(GLOBAL); //todas las interrupciones activadas | |
enable_interrupts(INT_EXT);//Habilitando interrupcion externa (RB0) | |
enable_interrupts(INT_RB);//Habilitando interrupciones de cambio de nivel (RB4-RB7) | |
ext_int_edge(H_TO_L);//Seleccionando flanco de interrupcion externa | |
output_low(PIN_A2); //led verde off | |
output_low(PIN_A1); //led amarillo off | |
output_low(PIN_A0); //led rojo off | |
Modo=1; | |
Temp=1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment