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

extern bit g_PwmInterrupt;
extern unsigned int PWM_DUTY0  ;      //PWM0 Duty
extern unsigned int PWM_DUTY1  ;      //PWM1 Duty
extern unsigned int PWM_DUTY2  ;      //PWM2 Duty
extern void Test_Aux(void);

unsigned char gTimer3Int;

void TIMER3_Interrupt(void) interrupt 6
{
	P0_1 = ~P0_1;
	T3CON = T3CON | 0x20;
	if((T3CON & 0x20) != 0x00)
	  while(1);	
	T3CON = T3CON | 0x10;
	gTimer3Int++;
}

void main(void)
{
	P0M0 = 0x00;
	P0M1 = 0x00;
	P1M0 = 0x00;
	P1M1 = 0x00;
	P2M0 = 0x00;
	P2M1 = 0x00;
	P3M0 = 0x00;
	P3M1 = 0x00;

	PWM_Duty(PWM_DUTY0,PWM_DUTY1, PWM_DUTY2);
	PWM_Init();
	Test_Aux();
	while(1);

}

void Test_Aux(void)
{
	unsigned char Loop;
	PWMAUX = 0x04;	
	Loop = 0x00;
	P0M0 = 0x00;
	P0M1 = 0x00;
	OVRDAT_5 = 0x00;
	OVRDIS_5 = 0x01;
		
	OVRDAT_4 = 0x00;
	OVRDIS_4 = 0x01;
		
	OVRDAT_3 = 0x00;
	OVRDIS_3 = 0x01;
		
	OVRDAT_2 = 0x00;
	OVRDIS_2 = 0x01;
		
	OVRDAT_1 = 0x00;
	OVRDIS_1 = 0x01;
		
	OVRDAT_0 = 0x00;
	OVRDIS_0 = 0x01;

	OCS2_5 = 0x01;
	OCS1_5 = 0x11;
	OCS0_5 = 0x11;

	OCS2_4 = 0x10;
	OCS1_4 = 0x11;
	OCS0_4 = 0x11;

	OCS2_3 = 0x11;
	OCS1_3 = 0x01;
	OCS0_3 = 0x11;

	OCS2_2 = 0x11;
	OCS1_2 = 0x10;
	OCS0_2 = 0x11;


	OCS2_1 = 0x11;
	OCS1_1 = 0x11;
	OCS0_1 = 0x01;

	OCS2_0 = 0x11;
	OCS1_0 = 0x11;
	OCS0_0 = 0x10;

	HALLSEL = Loop;
//----------------------------
	gTimer3Int = 0x00;	

	EA = 1;	
	IEN0 = IEN0 | 0x40;	
	T3CNTL = 0x12;
	T3CNTH = 0xF4;
	T3NDIV = 0x04;
	T3CON = T3CON | 0x10;
	HALLCON = HALLCON | 0x81;
	gTimer3Int = 0x00;
//----------------
	while(1)
	{
		if(gTimer3Int >= 0x01)
		{
			gTimer3Int = 0x00;
			HALLSEL = Loop;
			if(Loop >= 0x05)
			 Loop = 0x00;
		 else
			Loop++;
		}
	}
}