inter2.c
Minimal PIC16F877 application that handles two time intervals via interrupts and uses watchdog.
//This sample program shows how to use interrupts.
//If there is a LED connected to B7 it will blink
//with a period of 65 ms
//If there is a LED connected to B6 it will blink
//with a period of 1 second (approx.)
// Author : Joan Ilari - e-mail: c2c@ilari.org
#pragma CLOCK_FREQ 4000000
char sscounter=15;
//------------------------------------------------
void interrupt( void )
{
PORTB ^= 10000000b; // complement PORTB:7
if (--sscounter == 0)
{
PORTB ^= 01000000b; // complement PORTB:6
sscounter = 15;
}
clear_bit(INTCON,T0IF); // clear TMR0 interrupt flag
}
//------------------------------------------------
main()
{
OPTION_REG = 7; // set prescaler to 1:256
clear_bit(TRISB,7); // set PORTB:7 as OUTPUT
clear_bit(TRISB,6); // set PORTB:6 as OUTPUT
enable_interrupt( GIE ); // enable interrupts
enable_interrupt( T0IE ); // enable TMR0 overflow bit
while(1)
{
clear_wdt();
}
}
Copyright© 2002 Pavel Baranov