Documentos de Académico
Documentos de Profesional
Documentos de Cultura
<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
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;
}
;---------------------------------------------------------
;Autor: LONELY113
; http://lonely113.blogspot.com
;
;Programa de control de 2 semaforos
;Salidas: Puerto B (RB0-RB5)
; RB0=Verde1, RB1=Ambar1, RB2=Rojo1
; RB3=Verde2, RB4=Ambar2, RB5=Rojo2
;---------------------------------------------------------
include "p16f84a.inc"
list P=16f84a
;Subrutinas
'****************************************************************
'* Name : SEMAFORO.BAS *
'* Author : LONELY113 *
'* Notice : Copyright (c) 2011 LONELY113 *
'* : All Rights Reserved *
'* Date : 12/05/2011 *
'* Version : 1.0 *
'* Notes : PIC16F84a *
'* : RB0=GREEN1, RB1=YELLOW1, RB2=RED1 *
'* : RB3=GREEN2, RB4=YELLOW2, RB5=RED2 *
'****************************************************************
loop1:
portb=100001 'Green1, Red2
PAUSE 25000 'Retardo de 25 segundo
portb=100010 'Ambar1, Red2
PAUSE 5000 'Retardo 5 segundos
portb=001100 'Red1, Green2
PAUSE 25000 'Retardo 25 segundos
portb=010100 'Red1, Yellow2
PAUSE 5000 'Retardo 5 segundos
GOTO loop1
END