#include <16f628A.H>
#fuses NOMCLR
#fuses INTRC_IO
#FUSES NOWDT //No Watch Dog Timer
//#FUSES XT //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES RESERVED //Used to set the reserved FUSE bits
#use delay (clock=4000000)
#use rs232(baud=9600, xmit=pin_B2, rcv=pin_B1)
#define display_1 PIN_B4
#define display_2 PIN_B5
#define display_3 PIN_B6
#define display_4 PIN_B7
void alarma(void);
// NUMEROS [0-9] = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
int Numeros[10] = {0X00,0X01,0X02,0x03,0x04,0x05,0X06,0x07,0X08,0x09};
char trama_serial[10]; // Arreglo para recibir los datos.
int1 flag_rx = 0; // Variable bandera de recepción.
volatile int indice=0;
int8 basura;
// Variable bandera de recepción.
int8 Num_1,Num_2,Num_3,Num_4,Num_2x;
int interrupt_counter=0;
#define LED PIN_A0 // Aquí el pin donde esta el led
#INT_TIMER0
void TIMER0_isr()
{
interrupt_counter++;
if(interrupt_counter==61) // Ese 61 es para controlar el período de parpadeo.
output_toggle(LED);
}
#INT_RDA
void RECEPCION_RS232(void)
{
if(indice<5) // Solo 5 valores nomas.
{
trama_serial
[indice
]=getc(); indice++;
}
else
{
flag_rx = 1; // Se indica recepción completa.
basura
= getc(); // Descarto el caracter }
}
void main (void)
{
// Configuramos el Timer0... Esto investigalo vos
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);
set_timer0(0);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
set_tris_a(0x00);
//set_tris_b(0x06);
while (true)
{
if(flag_rx==1 ) // Si hay datos en el buffer...
{
Num_1 = ((trama_serial[0])-48); Num_3 = ((trama_serial[3])-48);
Num_2 = ((trama_serial[1])-48); Num_4 = ((trama_serial[4])-48);
Num_2X =(trama_serial[2]);
printf("%d%d%c%d%d\r"Num_1
,Num_2
,Num_2x
,Num_3
,Num_4
);
flag_rx = 0;
}
alarma(); //Esto se ejecuta constantemete, no importa si se ha recivido trama nueva o no.
}
}
void alarma(void)
{
output_high(Display_1);
output_a(Numeros[Num_1]);
delay_ms(1);
output_low(Display_1);
output_high(Display_2);
output_a(Numeros[Num_2]);
delay_ms(1);
output_low(Display_2);
output_high(Display_3);
output_a(Numeros[Num_3]);
delay_ms(1);
output_low(Display_3);
output_high(Display_4);
output_a(Numeros[Num_4]);
delay_ms(1);
output_low(Display_4);
}