XDEF Entry            ; export 'Entry' symbol
            ABSENTRY Entry        ; for absolute assembly: mark this as application entry point

            INCLUDE 'mc9s12c128.inc'
            ORG $4000
Entry:
            LDS   #$1000                 ;Initialize the stack pointer
            BSET  DDRT,$C0               ;Make PT7 and PT6 outputs for LEDs
            BCLR  ATDDIEN,%10000000      ;Make PAD7 analog input
            BSET  ATDCTL2,%10000000      ;Power up A/D Subsystem
            LDX #$FFFF
WT_ATD_PWR_UP:
            DEX 
            BNE WT_ATD_PWR_UP
            MOVB #%00001000,ATDCTL3       ;Select 1 conversion
            MOVB #%00000001,ATDCTL4       ;Select 10-bit conversion
                                         ;2-clock sample time, and
                                         ;1/16 ATD clock prescaling
NEXTCONV:   MOVB #$83,ATDCTL5             ;Start a conversion on Channel 3
WT_TIL_DONE:
            BRCLR ATDSTAT0,$80,WT_TIL_DONE ; and right-justify result in
                                           ; result register.
            LDD ATDDR0H                  ;Load 10-bit result into D
            CPD #$3FF/4
            BLO LightLED1                ;Go to LightLED1 if below 5/4V
            CPD #3*($3FF/4)
            BHI LightLED2                ;Go to LightLED2 if below 15/4 V
            BCLR PTT,$C0                  ;Turn off both LED1 and LED2
            BRA NEXTCONV
LightLED1:  BSET PTT,$80                  ;Light LED1 (on PT7) if analog
            BCLR PTT,$40                  ;Turn off LED2
            BRA NEXTCONV                  ;Input is below 5/4 volts
LightLED2:  BSET PTT,$40                  ;Light LED2 (on PT6) if analog
            BCLR PTT,$80                  ;Turn off LED1
            BRA NEXTCONV                  ;input is above 15/4 volts
            ORG   $FFFE
            DC.W  Entry                 ; Reset Vector