/*-------------------------------------------------------------------------
   AR168M demo external controller MCS51
   LED function copy right information

   Copyright (C) 2008. Lin, Rongrong <woody@palmmicro.com>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This software is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-------------------------------------------------------------------------*/

#include "type.h"
#include "8051.h"
#include "sys.h"

#ifdef SYS_WINBOND
#include "winbond.h"
#endif

#define LED_0		P2_0
#define LED_1		P2_1
#define LED_2		P2_2		
#define LED_3		P2_3

#ifdef SYS_WINBOND
#define LED_4		P4_0
#define LED_5		P4_1
#define LED_6		P4_2		
#define LED_7		P4_3
#endif

void LED_On(UCHAR iIndex)
{
	switch (iIndex)
	{
	case 0:
		LED_0 = 0;
		break;

	case 1:
		LED_1 = 0;
		break;

	case 2:
		LED_2 = 0;
		break;

	case 3:
		LED_3 = 0;
		break;

#ifdef SYS_WINBOND
	case 4:
		LED_4 = 0;
		break;

	case 5:
		LED_5 = 0;
		break;

	case 6:
		LED_6 = 0;
		break;

	case 7:
		LED_7 = 0;
		break;
#endif
	}
}

void LED_Off(UCHAR iIndex)
{
	switch (iIndex)
	{
	case 0:
		LED_0 = 1;
		break;

	case 1:
		LED_1 = 1;
		break;

	case 2:
		LED_2 = 1;
		break;

	case 3:
		LED_3 = 1;
		break;

#ifdef SYS_WINBOND
	case 4:
		LED_4 = 1;
		break;

	case 5:
		LED_5 = 1;
		break;

	case 6:
		LED_6 = 1;
		break;

	case 7:
		LED_7 = 1;
		break;
#endif
	}
}

void LED_Blink(UCHAR iIndex)
{
	BOOLEAN bVal;

	bVal = FALSE;
	switch (iIndex)
	{
	case 0:
		bVal = LED_0;
		break;

	case 1:
		bVal = LED_1;
		break;

	case 2:
		bVal = LED_2;
		break;

	case 3:
		bVal = LED_3;
		break;

#ifdef SYS_WINBOND
	case 4:
		bVal = LED_4;
		break;

	case 5:
		bVal = LED_5;
		break;

	case 6:
		bVal = LED_6;
		break;

	case 7:
		bVal = LED_7;
		break;
#endif
	}

	if (bVal)	
	{
		LED_On(iIndex);
	}
	else
	{
		LED_Off(iIndex);
	}
}

