/*
 * FVR.c
 *
 *  Created on: 2019-8-28
 *      Author: charles_cai
 */
#include"main.h"

#ifndef FVR_C_
#define FVR_C_

void Init_FVR(unsigned char mode)
{
	switch (mode)
	{
		case 1:
		VREFCTL =0x30;//1.5V
		break ;

		case 2:
		VREFCTL =0x70;//2V
		break ;

		case 3:
		VREFCTL =0xB0;//3V
		break ;

		case 4:
		VREFCTL =0xF0;//4V
		break ;
	}

	//校准内部参考电压
	__asm
	MOVP #0X30 ;切换到PAGE1区
	MOVB #0X01 ;切换到存储区1区
	CALL 0XFFA
	MOV VREFCAL0 , R0
	CALL 0XFF9
	MOV VREFCAL1 , R0
	MOVB #0X00 ;切换回存储器0区
	MOVP #0X00 ;切换回PAGE0区
	__endasm;

	VREFEN =1;//使能参考电压
}

#endif /* FVR_C_ */
