/************************************************************************
*							  ---- 居加居 ----							 
*  文件名:		Adc.c
*  编写人员:		Kinve JQ
*  说明:		 
*  版本:			V0.1
*  编写日期:		2018-09-30
*  程序维护:	 
*  维护记录:	
*	 				2018-09-30.Kinve:1.创建文件
* 免责声明：
* (c) Author Kinve JQ. All rights reserved.
**************************************************************************/

#include "Adc.h"

u8 Group_Light;
u8 Adc_read (void) 
{
	u16 time=0;
	u16 Data = 0;
	u8 CKDIV_back = CKDIV;
	
	CKDIV = 0x02;				// IMPORTANT!! Modify system clock to 4MHz ,then add the ADC sampling clock base to add the sampling timing.
	Enable_ADC_AIN0;			// 使能	ADC0	

	clr_ADCF;					//清中断
	set_ADCS;					//ADC开始											
	while(ADCF == 0){			//等待中断
		if(time++>=65535){break;}
	};	
	Data = ADCRH;				//读取数据
	Data = Data<<8 | ADCRL;
	Disable_ADC;				//ADC关闭

	CKDIV = CKDIV_back;			//恢复时钟
	
	Group_Light = Data*1.0/0xffff*100;
	return time>=65535?0:1;
}


/*************** (C) COPYRIGHT Kinve JQ  *******END OF FILE **************/

