void tc0 (void) __irq //Timer counter 0 interrupt executes //every second at 60-MHz CPU clock //for testing purposes
{
static char LedFlag = 0;
unsigned int AtoDValue;
if (LedFlag == 0) //Simply toggle the on-board
//LED for debug
{
IOSET1 = 0x00010000;
LedFlag = 1;
}
else
{
IOCLR1 = 0x00010000;
LedFlag = 0;
}
AD0CR |= 0x01200000; //Start an A/D conversion
do
{
AtoDValue = AD0DR; //Read A/D data register
}
while ((AtoDValue & 0x80000000) == 0); //Wait for end of A/D
//conversion
AD0CR &= ~0x01000000; //Stop A/D conversion
AtoDValue = (AtoDValue >> 6) & 0x03FF; //Extract AIN1 10-bit A/D value
printf (“A%d\n”, AtoDValue);//Output A/D conversion result to //serial port
T0IR = 1; //Clear interrupt flag
VICVectAddr = 0; //Acknowledge ARM interrupt
Listing 1—The C function from the LPC2138 takes care of reading the LM60 temperature sensor via its on-board A/D converter. The data is then sent out the serial port to the PC running the Visual Basic application.