bit set_ad_channel(const enum AD_CHANNELS channel)
{
    data bit success;
    data U8  buff_ad_status;

    // Assume failure, prove otherwise.
    success = FALSE;

    // Get a snapshot of the s_ad_status for multiple comparisons.
    buff_ad_status = s_ad_status;

    // Channel may be set only if A/D is not busy and not locking a value.
    if (!(buff_ad_status & (BUSY | VALUE_LOCKED))) {
        // Make sure caller didn't ask for an invalid channel.
        if (chan_num < NUM_AD_CHANNELS) {
            // Valid channel. Select the channel. Clear out old channel before
            // setting the new channel.
            s_ad_command &= ~CHANNEL_MASK;
            s_ad_command |= chan_num;
            success       = TRUE;
        }
    }

    return(success);
}