#include <12F508.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOPROTECT // codigo protegido
#FUSES MCLR
// #use delay(crystal=4000000) // oscilador con cristal
#use delay(internal=4000000) // oscilador interno
//#DEFINE SW PORTB,1 // le doy un nombre al pin
// #define LED PIN_B0 // llamamos led al pin b0
// #define LED2 PIN_B2 // llamamos led al pin b0
#define pulsador pin_b1 //Nombra a delay_ms() como Retardo
// #define pulsador2 pin_b2
// #define pulsador3 pin_b4
#DEFINE LED PIN_b0
//#DEFINE LED2 PIN_b2
#BYTE PORTB=0X06 // lugar de memoria del puerto A ( muy importante )
#USE FAST_IO (B) // Optimizamos E/S del PORTB ( muy importante para ahorrar memoria )
#ORG 0x50, 0X01FF // proteger el codigo a partir de la linea 50
// #USE STANDARD_IO (B)
//#use FIXED_IO( B_outputs=PIN_B5,PIN_B4,PIN_B2,PIN_B1,PIN_B0 )
//#define set_options (value) {#ASM \
// value \
//OPTION \
//#ENDASM}
int cont;
int cont2;
int cont3;
//int SEGUNDOS=0;
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
VOID TEMPO(); // PROTOTIPO DE LA FUNCION
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void main()
{
SET_TRIS_B(0B001010);
//set_options (0B000000);
#asm
movlw 0xC0 ; GPWU = 1, GPPU = 1, T0CS, T0SE, PSA, PS2, PS1, PS0 = 0
option#endasm
PORTB=0;
// fin configuracion *************
//SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_128|RTCC_8_bit); // GENERALMENTE VA AQUI SI MANTENGO EL PREESCALER FIJO
//se pueden modificar en el transcurso del programa las configuraciones del tmr0 y los registros para altere los tempos
while( true)
{
if (input(pulsador))
{
SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_128|RTCC_8_bit); // LO COLOCO AQUI POR SI DESEO MODIFICAR EL PREESCALER EN ALGUN MOMENTO
cont2=126;
cont3=194;
tempo();
}
}
}
//======================================
VOID tempo()
{
//SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_128|RTCC_8_bit); // LO COLOCO AQUI POR SI DESEO MODIFICAR EL PREESCALER EN ALGUN MOMENTO
Cont=cont2; // =126
output_high(LED); //cargo el contador
while(Cont>0) //hasta que el contador sea 217(1ms*217=217ms)
{
set_timer0(cont3); //se carga el timer para 1s
while(get_timer0()); //se espera aqui hasta que el timer valga 0 osea que se ha desbordado y ha pasado 1s
{
Cont--; //Cada ms se incrementa contador
}
}
Cont=cont2; //pasado los 10ms en alto pasamos el contador a 0
output_low(LED); //pone en bajo el pin b0
while(Cont>0) //hara lo siguiente hasta que contador sea =10
{
set_timer0( cont3); //se carga el timer para 1ms
while(get_timer0()); //se espera hasta que se desborde el timer0
Cont--; //incrementamos el contador cada ms
}
//al finalizar los 10ms en bajo se pone a 0 el contador
}