#include "OB6710.h"

// AUX[6]: Swap INT0 function
#define INT0_Swap0_P13   0x00
#define INT0_Swap1_P04   0x40

#define INT0_PinSel      INT0_Swap1_P04

// Debounce count(0x00 ~ 0xff)
#define INT_DB_CNT_00H   0x00    // 00­Óclk = 00*41.666 = 0us
#define INT_DB_CNT_30H   0x30    // 48­Óclk = 48*41.666 = 2.00us
#define INT_DB_CNT_40H   0x40    // 64­Óclk = 64*41.666 = 2.66us

#define INT_DB_CNT       INT_DB_CNT_00H

// INT0 trigger mode
//  IT0   ENHIT
//  0     0      low level trigger
//  0     1      high level trigger
//  1     0      falling edge trigger
//  1     1      rising edge trigger
#define IT0_LEVEL        0x00
#define IT0_EDGE         0x01

#define IT0_SEL          IT0_EDGE

#define ENHIT_LOW        0x00
#define ENHIT_HIGH       0x10

#define ENHIT_SEL        ENHIT_HIGH

#define INT0_Swap0_P04   0x00

void External0(void) interrupt 0
{
	P0_7 = ~P0_7;     // Milwaukee Aª© IC
	IE0 = 0;        // clear flag
}

void main(void)
{
	P0M0 = 0x00;
  P0M1 = 0x00;
  P1M0 = 0x00;
  P1M1 = 0x00;

	EA = 1;             // Enable All interrupt

	// Pin swap
	//AUX = 0x00;       // INT0_0 = P05
	//AUX = 0x40;       // INT0_0 = P04; INT0_0 swap
	AUX = INT0_PinSel;

	// debounce
	INTDBCNT = INT_DB_CNT;      // 00­Óclk = 00*41.666 = 0us
	                            // 48­Óclk = 48*41.666 = 2.00us
	                            // 64­Óclk = 64*41.666 = 2.66us
	
	//Pin Interrupt
	TCON |= IT0_SEL;            // level or edge
	ENHIT |= ENHIT_SEL;        // low or high


	EX0 = 1;                    // Enable external interrupt 0
	
	while(1)                    // Leave STOP Mode, then execute While(1)
	{
		;
	}
}