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

sbit CMP0_P0      = P0^0;
sbit CMP0_P1      = P0^1;
sbit CMP0_P2      = P0^2;
sbit CMP0_N0      = P0^3;
extern bit g_PwmInterrupt;
extern void Test_Fault_B(void);
extern void Test_Fault_A(void);
extern unsigned int PWM_DUTY0  ;      //PWM0 Duty
extern unsigned int PWM_DUTY1  ;      //PWM1 Duty
extern unsigned int PWM_DUTY2  ;      //PWM2 Duty

extern void Delay (unsigned int nDelay);

void Delay (unsigned int nDelay)
{
	while(nDelay--);
}

void main(void)
{
	unsigned char Buff;
	P0M0 = 0x00;
	P0M1 = 0x08;
	P1M0 = 0x00;
	P1M1 = 0x00;
	P2M0 = 0x00;
	P2M1 = 0x00;
	P3M0 = 0x00;
	P3M1 = 0x00;
	CMP0_P0 = 0x00;
	CMP0_P1 = 0x00;
	CMP0_P2 = 0x00; 	
	CMP0_N0 = 0x00;
	
	ACMP0_Open(0, 0,  d_HYS_RANGE_30);	
	ACMP0OUTPUT= 0x01 | 0x08;
	
	PWM_Duty(PWM_DUTY0,PWM_DUTY1, PWM_DUTY2);
	PWM_Init();
	Delay4TransH = 0x00;
	Delay4TransL = 0x20;
	
	while(1)
	{
		CMP0_P0 = 0x01;
		CMP0_N0 = 0x00;
		Delay(5);
		Buff = (ACMP0OUTPUT >> 0x04) & 0x01;
		if(Buff == 0x00)
			P1_0 = 0;
		else
			P1_0 = 1;
	
		CMP0_P0 = 0x00;
		CMP0_N0 = 0x01;			 
		Delay(5);
		Buff = (ACMP0OUTPUT >> 0x04) & 0x01;
	  if(Buff == 0x00)
			P1_0 = 0;
		else
			P1_0 = 1;
	}
}



