C program to read all eight channels of the HC12 A/D converter in 10-bit mode

C program ad_10bit.c
/* Set up for 10-bit, multi-channel, scan mode.
 * Save values in variables
 */

#include "hc12.h"

/* Define AD result registers for 10 bit mode */
#define ADR0    (* (volatile unsigned int *) 0x70)	
#define ADR1    (* (volatile unsigned int *) 0x72)	
#define ADR2    (* (volatile unsigned int *) 0x74)	
#define ADR3    (* (volatile unsigned int *) 0x76)	
#define ADR4    (* (volatile unsigned int *) 0x78)	
#define ADR5    (* (volatile unsigned int *) 0x7a)	
#define ADR6    (* (volatile unsigned int *) 0x7c)	
#define ADR7    (* (volatile unsigned int *) 0x7e)	

main()
{
	unsigned int ch[8];   /* Variable to hod result */

	ATDCTL2 = 0x80;  /* Power up A/D, no interrupts */
	ATDCTL4 = 0x81;	 /* 10 us/conversion, 10-bit mode */
	ATDCTL5 = 0x64;  /* 0 1 0 0 0 0 0 0
						  | | | \____/
						  | | |    |
						  | | |    \___  CD = 0; others don't care
						  | | \________  Mult = 1 => multiple channels
						  | \__________  Scan = 0 => one set of conversions
						  \____________  S8CM => do eight conversions
				 	*/

/**************************************************************************/

	while ((ATDSTAT & 0x8000) == 0 ) ;     /* Wait for conversion to finish */
	ch[0] = ADR0 >> 6;
	ch[1] = ADR1 >> 6;
	ch[2] = ADR2 >> 6;
	ch[3] = ADR3 >> 6;
	ch[4] = ADR4 >> 6;
	ch[5] = ADR5 >> 6;
	ch[6] = ADR6 >> 6;
	ch[7] = ADR7 >> 6;
}