www.pudn.com > RS485_USART-ok.rar > drv_led.c, change:2007-09-18,size:5753b


//*---------------------------------------------------------------------------- 
//*      Shenzhen ANCHE Tech CO.,LTD 
//*---------------------------------------------------------------------------- 
//*---------------------------------------------------------------------------- 
//* File Name           : drv_led.c 
//* Object              : led Library. 
//* Designer            : Tianlong Jing, at 2006 
//* 
//* 1.0 25/08/00 LLD    : Creation 
//* 2.0 10/12/01 PFi    : Access to Data Pointer/Counter Registers has been removed. 
//*                     : The RevA of the M558000 does not features DAC PDC. 
//*---------------------------------------------------------------------------- 
#include "includes.h" 
 
 
// 设置对应LED的状态---初始化 (OUTPUT、TURNOFF) 
void Led_Init(void) 
{ 
	// 1 --- Enable PIO Control the PIN 
	AT91F_PIO_Enable(AT91C_BASE_PIOA, BIT_LED0); 
        #if  (hardversion ==_812DASV11)||(hardversion == ACDASV11) 
           AT91F_PIO_Enable(AT91C_BASE_PIOA, BIT_LED1 | BIT_LED2 | BIT_LED3); 
        #else 
	  AT91F_PIO_Enable(AT91C_BASE_PIOB, BIT_LED1 | BIT_LED2); 
        #endif 
	// 2 --- Set to Output and Opendrain 
	  AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, BIT_LED0); 
        #if  (hardversion ==_812DASV11)||(hardversion == ACDASV11) 
           AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, BIT_LED1 | BIT_LED2 |BIT_LED3);   
        #else  
           AT91F_PIO_CfgOutput(AT91C_BASE_PIOB, BIT_LED1 | BIT_LED2);   
        #endif 
           AT91F_PIO_CfgOpendrain(AT91C_BASE_PIOA, BIT_LED0); 
        #if  (hardversion ==_812DASV11)||(hardversion == ACDASV11) 
           AT91F_PIO_CfgOpendrain(AT91C_BASE_PIOA, BIT_LED1 | BIT_LED2 | BIT_LED3); 
        #else 
	   AT91F_PIO_CfgOpendrain(AT91C_BASE_PIOB, BIT_LED1 | BIT_LED2); 
        #endif 
	// 3 --- Turn off the LED 
	AT91F_PIO_SetOutput(AT91C_BASE_PIOA, BIT_LED0); 
        #if  (hardversion ==_812DASV11)||(hardversion == ACDASV11) 
            AT91F_PIO_SetOutput(AT91C_BASE_PIOA, BIT_LED1 | BIT_LED2 |BIT_LED3); 
        #else 
	    AT91F_PIO_SetOutput(AT91C_BASE_PIOB, BIT_LED1 | BIT_LED2); 
        #endif 
} 
 
void Led_On(unsigned char  led) 
{ 
	switch(led) 
	{ 
		case 0: 
			AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, BIT_LED0); 
			break; 
		case 1: 
                      #if (hardversion ==_812DASV11)||(hardversion == ACDASV11) 
                         AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, BIT_LED1);      
                      #else 
                        AT91F_PIO_ClearOutput(AT91C_BASE_PIOB, BIT_LED1); 
                      #endif 
			break; 
		case 2: 
                      #if (hardversion ==_812DASV11)||(hardversion == ACDASV11) 
                        AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, BIT_LED2); 
                      #else 
			            AT91F_PIO_ClearOutput(AT91C_BASE_PIOB, BIT_LED2); 
                      #endif 
                        break; 
               case 3:  
                      #if (hardversion ==_812DASV11)||(hardversion == ACDASV11) 
			   AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, BIT_LED3);		 
		      #endif 
                        break; 
	} 
} 
 
 
void Led_Off(unsigned char  led) 
{ 
	switch(led) 
	{ 
		case 0: 
			AT91F_PIO_SetOutput(AT91C_BASE_PIOA, BIT_LED0); 
			break; 
		case 1:  
 
                      #if (hardversion ==_812DASV11)||(hardversion == ACDASV11)                       
                          AT91F_PIO_SetOutput(AT91C_BASE_PIOA, BIT_LED1); 
                      #else  
			  AT91F_PIO_SetOutput(AT91C_BASE_PIOB, BIT_LED1); 
                      #endif 
			break; 
		case 2: 
		       #if (hardversion ==_812DASV11)||(hardversion == ACDASV11)                       
                          AT91F_PIO_SetOutput(AT91C_BASE_PIOA, BIT_LED2); 
                      #else  
			  AT91F_PIO_SetOutput(AT91C_BASE_PIOB, BIT_LED2); 
                      #endif 
			break; 
                case 3:   
                           
		      #if (hardversion ==_812DASV11)||(hardversion == ACDASV11)         
                        AT91F_PIO_SetOutput(AT91C_BASE_PIOA, BIT_LED3); 
		      #endif 
                       break; 
		} 
} 
 
void Led_Toggle(unsigned char led) 
{ 
	switch(led) 
	{ 
		case 0:                                     
			if (AT91C_BASE_PIOA->PIO_ODSR & BIT_LED0)  
				AT91C_BASE_PIOA->PIO_CODR = BIT_LED0; 
			else 
				AT91C_BASE_PIOA->PIO_SODR = BIT_LED0; 
			 break; 
		case 1: 
                        #if (hardversion ==_812DASV11)||(hardversion == ACDASV11)  
                          if (AT91C_BASE_PIOA->PIO_ODSR & BIT_LED1)  
				AT91C_BASE_PIOA->PIO_CODR = BIT_LED1; 
			  else 
				AT91C_BASE_PIOA->PIO_SODR = BIT_LED1; 
			  break; 
                        #else 
			   if (AT91C_BASE_PIOB->PIO_ODSR & BIT_LED1)  
				AT91C_BASE_PIOB->PIO_CODR = BIT_LED1; 
			   else 
				AT91C_BASE_PIOB->PIO_SODR = BIT_LED1; 
			   break; 
                        #endif 
                         
		case 2: 
                        #if (hardversion ==_812DASV11)||(hardversion == ACDASV11)  
                          if (AT91C_BASE_PIOA->PIO_ODSR & BIT_LED2)  
				AT91C_BASE_PIOA->PIO_CODR = BIT_LED2; 
			  else 
			 	AT91C_BASE_PIOA->PIO_SODR = BIT_LED2; 
			  break; 
                        #else 
			  if (AT91C_BASE_PIOB->PIO_ODSR & BIT_LED2)  
				AT91C_BASE_PIOB->PIO_CODR = BIT_LED2; 
			  else 
				AT91C_BASE_PIOB->PIO_SODR = BIT_LED2; 
			  break; 
                        #endif 
 
               case 3:   
			#if (hardversion ==_812DASV11)||(hardversion == ACDASV11)   
                          if (AT91C_BASE_PIOA->PIO_ODSR & BIT_LED3)  
				AT91C_BASE_PIOA->PIO_CODR = BIT_LED3; 
			  else 
				AT91C_BASE_PIOA->PIO_SODR = BIT_LED3; 
			#endif		 
			  break; 
                      
			    
                          
        } 
}