Listing 2—This is the entire interrupt routine. It's really the heartbeat of the program. It performs all the ADC and DAC operations while pacing the program.

void tc0 (void) __irq 
{
	unsigned int val;

	if(aiFlag == AI_ENABLE) //capture and send analog input value if 
							   //flag is set
	{
  	val = ai();
		printf(“%c\n”,val);
	}
	
	if(aoFlag == AI_ENABLE) //output and increment analog output 
					//buffer if flag is set
	{
 			DACR = aoBuffer[aoBufferIndex];
			aoBufferIndex++;
			if(aoBufferIndex >= 500)
				aoBufferIndex = 0;
	}

		T0IR        = 1; // Clear interrupt flag      
		VICVectAddr = 0; 
}