#include "OB6710.h"
#include "ACMP0.h"

bit g_Acmp0Interrupt = 0;


void ACMP0_ISR(void) interrupt d_ACMP0_Vector
{	 
	ACMP0OUTPUT &= 0x7F;	// 0111_1111 clear ACMP1 INT Flag
	g_Acmp0Interrupt = 0x01;
}


void ACMP0_Open(unsigned char nPSEL, unsigned char nNSEL, unsigned char nHYS_RANGE)
{
	ACMP0CON = 0x00;
	ACMP0CON = (nNSEL << 4) | (nPSEL << 1);
  ACMP0CON = ACMP0CON | 0x01;
	ACMPHYS = nHYS_RANGE;
}
void ACMP0_Close(void)
{
	ACMP0CON = 0x00;
}

void ACMP0_EnableIE(unsigned char nIE_TYPE)
{
  EA = 1;					
	IEN2 = IEN2 | 0x04;			
	ACMP0OUTPUT = ACMP0OUTPUT & 0x9F;
	ACMP0OUTPUT = ACMP0OUTPUT | (nIE_TYPE << 0x05);
}

void ACMP0_DisableIE(void)
{
	IEN2 = IEN2 &  0xFB;			
	ACMP0OUTPUT = ACMP0OUTPUT & 0x7F;
}

void ACMP0_DebounceCount(unsigned char nDebounceCount)
{
	ACMP0DBCNT = nDebounceCount;
}


unsigned char ACMP0_OutputStatus(void)
{
  unsigned char Buff;
	Buff = (ACMP0OUTPUT >> 0x04) & 0x01;
  return Buff;
}

//-------