Está en la página 1de 6

#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;
}

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

__CONFIG _WDT_OFF & _XT_OSC

TIME equ 0x0C


COUNT1 equ 0x0D
COUNT2 equ 0x0E
COUNT3 equ 0x0F

org 0x00 ; Inicio de programa


bsf STATUS,5 ; Inicio configiracion E/S
clrf PORTB ; Puerto B como salida
bcf STATUS,5 ; Fin configuracion E/S
movlw 0x21 ; b'000100001'
movwf PORTB ; RB0=Verde1 y RB5=Rojo2
BEGIN: call COUNTER ; Llama a subrutina COUNTER
movlw 0x00 ; 0 segundos
subwf TIME,0
btfsc STATUS,2 ; Si TIME =0 segundos saltar a FIRST
goto FIRST
movlw 0x19 ; 25 segundos
subwf TIME,0
btfsc STATUS,2 ; Si TIME=25 segundos saltar a SECOND
goto SECOND
movlw 0x1E ; 30 segundos
subwf TIME,0
btfsc STATUS,2 ; Si TIME=30 segundos saltar a THIRD
goto THIRD
movlw 0x37 ; 55 segundos
subwf TIME,0
btfsc STATUS,2 ; Si TIME=55 segundos saltar a FOURTH
goto FOURTH
goto FINISH
FIRST: movlw 0x21 ; b'000100001'
movwf PORTB ; RB0=Verde1 y RB5=Rojo2
goto FINISH
SECOND: movlw 0x22 ; b'000100010'
movwf PORTB ; RB1=Ambar1 y RB5=Rojo2
goto FINISH
THIRD: movlw 0x0C ; b'00001100'
movwf PORTB ; RB2=Rojo1 y RB3=Verde2
goto FINISH
FOURTH: movlw 0x14 ; b'00010100'
movwf PORTB ; RB2=Rojo1 y RB4=Ambar2
goto FINISH
FINISH: goto BEGIN

;Subrutinas

COUNTER movlw 0xFA ; Subrutina para que TIME


movwf COUNT1 ; se incremente cada 1 segundo
movlw 0xC8 ; calibrado para cristal de 10 MHz
movwf COUNT2 ; modificar COUNT1, COUNT2 y COUNT3
movlw 0x12 ; para otras frecuencias
movwf COUNT3
LOOP: decfsz COUNT1,1
goto LOOP
movlw 0xFA
movwf COUNT1
decfsz COUNT2,1
goto LOOP
movlw 0xFA
movwf COUNT1
movlw 0xC8
movwf COUNT2
decfsz COUNT3,1
goto LOOP
incf TIME,1
movlw 0x3C ; 60 segundos entonces reiniciar TIME
subwf TIME,0
btfsc STATUS,2
clrf TIME
return

end ; Fin de programa

****Programa Pic Basic (Microcode)****

'****************************************************************
'* 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 *
'****************************************************************

@ __config _HS_OSC & _WDT_OFF

DEFINE OSC 10 '10 MHz


trisb=$00 'Puerto B como salida

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

También podría gustarte