#include "H/Function_Init.H"

#if (Test == 4)

unsigned char xdata LED_RAM[8]  _at_  0x100;

void LEDPPush_Init();

void LED_RAMatrixControl(unsigned char RAM_x,unsigned char RAM_y,unsigned state);
void LED_CTROL(unsigned char x,unsigned y,unsigned state);

/*****************************************************
*函数名称：void LED_Test(void)
*函数功能：LED测试
*入口参数：void
*出口参数：void
*****************************************************/
void LED_Test(void)
{
	unsigned int i,j;
	
	LEDPPush_Init();

	while(1)
	{  	
		/*LED0~LED7逐个点亮并逐个熄灭*/
		for(j=0;j<7;j++)
		{
				for(i=0;i<8;i++)
				{
						LED_RAMatrixControl(i,j,1); //第i行j列LED点亮
						Delay(20000);
				}
		}
		for(j=0;j<7;j++)
		{
				for(i=0;i<8;i++)
				{
						LED_RAMatrixControl(i,j,0); //第i行j列LED熄灭
						Delay(20000);
				}
		}
	}
}

/*****************************************************
*函数名称：void LEDPPush_Init()
*函数功能：LED初始化
*出口参数：void
*****************************************************/
void LEDPPush_Init()
{
  /*正反推模式设置*/
	DDRCON2 &=0xF0;
	DDRCON2 |=0x03;//亮度4
	
	SCANCON &= ~(0x1<<6);
	SCANCON |= (0x1<<6);  //恒流输出  
	
	SCANCON &= ~(3<<2);
	SCANCON |= 0<<2;  //LED0特定扫描
	
	SCANCON &= ~(3<<4);
	SCANCON |= 0x01<<4; //1T
	
	SCANCON &= ~(3<<0);
	SCANCON |= 0x00<<0; //时钟分频Fsys/4096
	
	LEDVO = 0xff;
	
	DDRCON0 |= 0x80;     //开启显示驱动
	
}

/*****************************************************
*函数名称：LED_RAMatrixControl(unsigned char x,unsigned char y,unsigned state)
*函数功能：使能LED正反推RAM控制位
*入口参数：x  第x位
          y  第y位
          state  第y行  第x列的RAM位置1
*出口参数：void
*****************************************************/
void LED_RAMatrixControl(unsigned char x,unsigned char y,unsigned state)
{
	if(state==1)
	{
		if(x<=7)
		{
			if(y<x)
			{
				LED_RAM[y]|=1<<x;
			}
			else
			{
				LED_RAM[y+1]|=1<<x;
			}
		}
	}			
	else
	{
		if(x<=7)
		{
			if(y<x)
			{
				LED_RAM[y]&=~(1<<x);
			}
			else
			{
				LED_RAM[y+1]&=~(1<<x);
			}
		}
	}
}

#endif
