#include "18F2520.h"
#fuses HS, NOPROTECT, INTRC_IO
#use delay(clock=4000000) // 4MHZ internal clock
// fout = fclk/(4*prescaler* (256-TMR0)*count)
// for prescaler = 1 : 256 and TMR0 = 0
// if need 5sec delay
// Tout = 1/fout = 1/0.2Hz = 5sec
// count = 4Mhz/(4*256*(256-0)*0.2Hz) = 76.29 = 76 counts(approxi)
unsigned int count;
#int_RTCC
void clock_isr()
{
set_timer0(0);
count++;
if(count==76) // 76 for 5sec delay // 15 for 1 sec delay
{
output_high(PIN_B7);
count=0;
}
}
void main()
{
set_tris_b(0x00);
setup_oscillator(OSC_4MHZ);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_BIT);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while(1)
{
output_high(PIN_B6);
}
}