/******************************************************************************
;  *   	@MCU				 : MC51F003A4
;  *   	@Create Date         : 2020.01.02
;  *   	@Author/Corporation  : Martin/SinoMCU
;  *   	@晟矽微技术支持QQ群   : 814641858
;  *    @晟矽微官方论坛       : http://bbs.sinomcu.com/
;  *   	@Copyright           : 2020 SINOMCU Corporation,All Rights Reserved.
;  *----------------------Abstract Description---------------------------------
;  *			          定义                              		
******************************************************************************/

#ifndef ADC_LIB_H__
#define ADC_LIB_H__

#include "MC51F003A4_COMMON.h"


#define ADC_CHX_ADDR        0xf0     //通道所在位
#define ADC_INT_PRI_ADDR    0x40     //中断优先级所在位
#define ADC_ADEOC_ADDR    0x02     //ADEOC所在位
#define ADC_VREF_ADDE	DEF_SET_BIT5		//外部VREF

//ADC IO
#define ADC_IOP22   0x01
#define ADC_IOP23   0x02
#define ADC_IOP24   0x04
#define ADC_IOP25   0x08
#define ADC_IOP11   0x10
#define ADC_IOP12   0x20
#define ADC_IOP13   0x40
#define ADC_IOP14   0x80
#define ADC_IOP15   0x0100
#define ADC_IOP16   0x0200
//AD通道
#define ADC_CH0             0
#define ADC_CH1             0x10
#define ADC_CH2             0x20
#define ADC_CH3             0x30
#define ADC_CH4             0x40
#define ADC_CH5             0x50
#define ADC_CH6             0x60
#define ADC_CH7             0x70
#define ADC_CH8             0x80
#define ADC_CH9             0x90
#define ADC_CH_VDD_4        0xE0
#define ADC_CHGND           0XF0
//AD时钟
#define ADC_CKS_DIV_1        0  
#define ADC_CKS_DIV_2      0x10
#define ADC_CKS_DIV_4      0x20
#define ADC_CKS_DIV_8      0x30
#define ADC_CKS_DIV_16     0x40
#define ADC_CKS_DIV_32     0x50
#define ADC_CKS_DIV_64     0x60
#define ADC_CKS_DIV_128    0x70
//数据格式
#define ADC_DATA_SEL_8H_4L  0
#define ADC_DATA_SEL_4H_8L  0x80
//转换时间
#define ADC_SAM_TIME_1ADCLK    1
#define ADC_SAM_TIME_2ADCLK    2
#define ADC_SAM_TIME_3ADCLK    3
#define ADC_SAM_TIME_4ADCLK    4
#define ADC_SAM_TIME_5ADCLK    5
#define ADC_SAM_TIME_6ADCLK    6
#define ADC_SAM_TIME_7ADCLK    7
#define ADC_SAM_TIME_8ADCLK    8
#define ADC_SAM_TIME_9ADCLK    9
#define ADC_SAM_TIME_10ADCLK    10
#define ADC_SAM_TIME_11ADCLK    11
#define ADC_SAM_TIME_12ADCLK    12
#define ADC_SAM_TIME_13ADCLK    13
#define ADC_SAM_TIME_14ADCLK    14
#define ADC_SAM_TIME_15ADCLK    15
//参考电压
#define ADC_VREF_2V             0
#define ADC_VREF_VDD            0X0C
#define ADC_VREF_EXT_VREF       0x20


typedef struct
{
    uint8_t ADC_clock_division;       //ADC时钟
    uint8_t ADC_sam_time;  //采样时间
    uint16_t ADC_IOx;       //设置ADC IO
    uint8_t ADC_chx;       //通道
    uint8_t ADC_data_sel;  //数据格式  
    uint8_t ADC_vref;      //VREF
    uint8_t ADC_interrupt; //中断允许	ENABLE,DISABLE
    uint8_t ADC_interrupt_priority;  //中断优先级 DEF_HIGH,DEF_LOW
}ADC_InitTypeDef;

void ADC_Init(ADC_InitTypeDef *ADCx);
void ADC_Cmd(uint8_t new_state);
void ADC_IO_Configure(uint16_t IOx);
void ADC_Channel_Configure(uint8_t ch);
uint16_t ADC_Value_4H_8L(void);
uint16_t ADC_Value_8H_4L(void);
void ADC_Start_One_Conversion(void);
flagstatus ADC_Get_FlagStatus(void);
uint8_t ADC_Zero_ADJ(void);

#endif

/**************************** end of file *********************************************/
