//************************************************************
//---------------XiAn AnaDig IC Inc.(XAD-IC)------------------
//-----------------C File Standard--------------------
//************************************************************
//#Author      : AE_team
//#Case name   : ADC
//#Function    : 4路ADC依次采集完成后同时输出ADC值，ADC1 -> PB0 ADC2->PB6 ADC3->PC2 ADC4 ->PC0
//               UART TX-> PB2   BPS ->9600
//************************************************************
#include "AD18F06A.h"
#include "stdio.h"
#include "periph.h"
#include "usart.h"

__CONFIG(1,_FINTOSC_DIV1_1L   & _LVREN_ON_1L       & _LVR24V_1L                                                                                          );
__CONFIG(2,_FLASH_CP7_OFF_2L  & _FLASH_CP6_OFF_2L  & _FLASH_CP5_OFF_2L   & _FLASH_CP4_OFF_2L   & _FLASH_CP3_OFF_2L
         & _FLASH_CP2_OFF_2L  & _FLASH_CP1_OFF_2L  & _FLASH_CP0_OFF_2L   & _CRYLEN_OFF_2L      & _CRYHEN_OFF_2L
  	     & _IDIS_ON_2L        & _CKSUM_OFF_2L      & _CBP_OFF_2L         & _RESETE_OFF_2L      & _RSEL_LOW_2L     & _STV_ON_2L              	         );
__CONFIG(3,_DBG_OFF_3L        & _PSUT_8_3L         & _FCPU_2T_3L         & _WDTEN_OFF_3L       & _TWDT_011_3L                                            );
__CONFIG(4,_OSCM_HIRC_16M_4L  &_ENVDDL_ON_4L       & _EEDIS_OFF_4L       & _FLDIS_OFF_4L       & _FCMEN_OFF_4L    & _IESO_OFF_4L&  _DBGS_IOSEL_1_4L      );


//4路ADC依次采集完成后同时输出ADC值，Verf -> VDD,ADC1 -> PB0 ADC2->PB6 ADC3->PC2 ADC4 ->PC0
//Tx_PB2 BPS ->9600
void main(void)
{
    GPIO_OUT_Init();
    unsigned short temp0,temp1,temp2,temp3;
   	usart0_init();			//RX0_PIN TRISB1    TX0_PIN TRISB2
	printf("ADC_TEST...\r\n\r\n");

    ADC1_init();    //PB0
    ADC2_init();    //PB6
    ADC3_init();    //PC2
    ADC4_init();    //PC0

	while(1)
	{
        GO = 1;
        while(GO);
        temp0 = ((ADRESH0& 0xf)<<8)|ADRESL0;
        temp1 = ((ADRESH1& 0xf)<<8)|ADRESL1;
        temp2 = ((ADRESH2& 0xf)<<8)|ADRESL2;
        temp3 = ((ADRESH3& 0xf)<<8)|ADRESL3;

        printf("TEMP0 = %4d     ",temp0);
        printf("TEMP1 = %4d     ",temp1);
        printf("TEMP2 = %4d     ",temp2);
        printf("TEMP3 = %4d \r\n",temp3);

	}

}




void interrupt ISR_h (void)
{

}




void interrupt low_priority ISR_l (void)
{


}
