DO NOT DO THIS -- Do not do something in an interrupt service routine which
takes a long time, such as printing to a serial port.
#include "hc11.h"
#include "DBug12.h"
#define TRUE 1
#define FALSE 0
void tic1_isr(void);
unsigned int time;
main()
{
TSCR = 0x80;
TMSK2 = 0x05; /* Set prescaler for divide by 32 */
/* Setup for IC1 */
TIOS = TIOS & ~0x02; /* IOC1 set for Input Capture */
TCTL4 = (TCTL2 | 0x04) & ~0x08; /* Capture Rising Edge */
TFLG1 = 0x02; /* Clear IC1 Flag */
TMSK1 = TMSK1 | 0x02; /* Enable IC1 Interrupt */
enable();
while (TRUE) ;
}
@interrupt void tic1_isr(void)
{
time = TIC1;
DBug12FNP->printf("time = %u\n\r",time); /* DO NOT DO THIS */
TFLG1 = 0x04;
}
Instead, do the printing in the main program or in a (non-interrupt) function.
Set a flag (a global variable) in the interrupt service routine to let the
program know when it is time to print. Global variables set in interrupt
service routines and used by the main program should be declared as type
volatile:
#include "hc11.h"
#include "DBug12.h"
#define TRUE 1
#define FALSE 0
void tic1_isr(void);
volatile unsigned int time, done;
main()
{
done = FALSE;
TSCR = 0x80;
TMSK2 = 0x05; /* Set prescaler for divide by 32 */
/* Setup for IC1 */
TIOS = TIOS & ~0x02; /* IOC1 set for Input Capture */
TCTL4 = (TCTL2 | 0x04) & ~0x08; /* Capture Rising Edge */
TFLG1 = 0x02; /* Clear IC1 Flag */
TMSK1 = TMSK1 | 0x02; /* Enable IC1 Interrupt */
enable();
while (TRUE)
{
if (done)
{
DBug12FNP->printf("time = %u\n\r",time);
done = FALSE;
}
}
}
@interrupt void tic1_isr(void)
{
time = TIC1;
done = TRUE;
TFLG1 = 0x04;
}