//
// En general:
// Tosc = (1 / clock)
// Tiempo = 4 x Tosc x Valor a contar en Timer x Rango del Divisor
// Tiempo = 4 x 0.00000025 x 65535 x 4 = 262.14 mSeg. // 16 bits
// Tiempo = 4 x 0.00000025 x 62500 x 4 = 250.00 mSeg. // 16 bits
// Valor de carga de Timer1: 65535-62500=3035 (0xBDB)
//
#include <16LF1828.h>
#device adc=16
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES WDT_SW //No Watch Dog Timer, enabled in Software
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOBROWNOUT //No brownout reset
#FUSES PLL_SW //4X HW PLL disabled, 4X PLL enabled/disabled in software
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(int=4000000)
#define LED pin_A0
#define LED_1 pin_A1
#define LED_2 pin_A2
#define DELAY 150
#int_TIMER1
void TIMER1_isr(void)
{
output_toggle(LED_1); // toogle RA1
output_toggle(LED_2); // toogle RA2
set_timer1(0xBDB); // carga del TMR1 para 250 mSeg.
}
void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_4); //262 ms overflow
setup_timer_4(T4_DISABLED,0,1);
setup_timer_6(T6_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
// Inicio los LEDs para que trabajen alternados...
output_high(LED_1); // inicializo a RA1
output_low(LED_2); // inicializo a RA2
set_timer1(0xBDB); // carga del TMR1 para 250 mSeg.
while(TRUE)
{
output_low(LED);
delay_ms(DELAY);
output_high(LED);
delay_ms(DELAY);
}
}