static void Ph_B_OFF(void)
{
	#ifdef	L_DEBUG
		Debug_PutString("\n\rB OFF..");
	#endif
	LATCH_1 	= 1;				//	Enable Latch;
	LATCH_2 	= 1;
	A_Set 		= 0;				//	Phase-R Set	
	A_Reset 	= 0;				//	Phase-R Reset
	B_Set 		= 0;				//	Phase-Y Set
	B_Reset 	= 0;				//	Phase-Y Reset
	C_Set 		= 0;				//	Phase-B Set	
	C_Reset 	= 1;				//	Phase-B Reset	
	OSTimeDly(150);					//	700 milli Seconds minimum Delay Required
	LATCH_1 	= 0;				//	Disable Latch;
	LATCH_2	 	= 0;
}
static void ALP_En(void)
{
	#ifdef	L_DEBUG
		Debug_PutString("\n\rALP ENABLED..");
	#endif
	if( ON_OFF() )
	{
		if( SR2 && !SR3 )
			Ph_R_ON();
		Reset_Z();
	}											
	else
	{
		if(SR3 || SR4)
			Ph_R_OFF();
		Reset_Z();	 
	}					
	
	if( ON_OFF_Y() )
	{
		if(SY2 && !SY3)
			Ph_Y_ON();
		Reset_Z();
	}											
	else
	{
		if(SY3 || SY4)
			Ph_Y_OFF();
		Reset_Z();	 
	}							
	
	if( ON_OFF_B() )
	{
		if(SB2 && !SB3)
				Ph_B_ON();
			Reset_Z();
	}									
	else
	{
		if(SB3 || SB4)
			Ph_B_OFF();	
		Reset_Z();	 
	}							
}
void Init_Load_SW(void)
{	
	DDR_A_Set		=	OUTPUT;	
	DDR_A_Reset		=	OUTPUT;							
	DDR_B_Set		=	OUTPUT;	
	DDR_B_Reset		=	OUTPUT;									
	DDR_C_Set		=	OUTPUT;			
	DDR_C_Reset		=	OUTPUT;									
	DDR_D_Set		=	OUTPUT;	
	DDR_D_Reset		=	OUTPUT;	
	DDR_LATCH1		=	OUTPUT;	
	DDR_LATCH2		=	OUTPUT;		
	
	LATCH_1 = LATCH_2	 	=  0;				//	Disable Latch;
	A_Set 			=  0;				//	Phase-R Set	
	A_Reset 		=  0;				//	Phase-R Reset
	B_Set 			=  0;				//	Phase-Y Set
	B_Reset 		=  0;				//	Phase-Y Reset
	C_Set 			=  0;				//	Phase-B Set	
	C_Reset 		=  0;				//	Phase-B Reset	
	#ifdef	L_DEBUG
		Debug_PutString("\n\rINIT LOAD..");	
	#endif
}
static unsigned char ON_OFF(void)
{
	ONTime.StructTime.Reserved		=	0;			//	Reserver byte in MSB w.r.t Union is Cleared
	OFFTime.StructTime.Reserved		=	0;			//	Reserver byte in MSB w.r.t Union is Cleared
	
	if(ONTime.TimeValue < OFFTime.TimeValue)  							/* On/Off are on the same day     */   
   	{
    		if( (Sys_Time.TimeValue >= ONTime.TimeValue) && ( Sys_Time.TimeValue <= OFFTime.TimeValue))
    		{
	    		#ifdef	L_DEBUG
	    		Debug_PutString("\n\r System Time Value : ");
				Debug_PutInt(Sys_Time.TimeValue);
				Debug_PutString("\n\r On Time Value : ");
				Debug_PutInt(ONTime.TimeValue);
				Debug_PutString("\n\r Off Time Value : ");
				Debug_PutInt(OFFTime.TimeValue);
				Debug_PutString("\n\rSame Day ON\n\r");
				#endif
	   			return ON;
	   		}	
	   	else
	   		{
		   		#ifdef	L_DEBUG
		   		Debug_PutString("\n\r System Time Value : ");
				Debug_PutInt(Sys_Time.TimeValue);
				Debug_PutString("\n\r On Time Value : ");
				Debug_PutInt(ONTime.TimeValue);
				Debug_PutString("\n\r Off Time Value : ");
				Debug_PutInt(OFFTime.TimeValue);
				Debug_PutString("\n\rSame Day OFF\n\r");
				#endif
	    		return OFF;
	    	}	
	}
	else                              									/* If On/Off are on different days */
	{
		if( (Sys_Time.TimeValue >= OFFTime.TimeValue) && ( Sys_Time.TimeValue <= ONTime.TimeValue))
		{
			#ifdef	L_DEBUG
			Debug_PutString("\n\r System Time Value : ");
			Debug_PutInt(Sys_Time.TimeValue);
			Debug_PutString("\n\r On Time Value : ");
			Debug_PutInt(ONTime.TimeValue);
			Debug_PutString("\n\r Off Time Value : ");
			Debug_PutInt(OFFTime.TimeValue);
			Debug_PutString("\n\rDifferent Day OFF\n\r");
			#endif
	   		return OFF;
	 	}  		
	   	else
	   	{
		   	#ifdef	L_DEBUG
	   		Debug_PutString("\n\r System Time Value : ");
			Debug_PutInt(Sys_Time.TimeValue);
			Debug_PutString("\n\r On Time Value : ");
			Debug_PutInt(ONTime.TimeValue);
			Debug_PutString("\n\r Off Time Value : ");
			Debug_PutInt(OFFTime.TimeValue);
			Debug_PutString("\n\rDifferent Day ON\n\r");
			#endif
	   		return ON;
	   	}	
   	}
}
static void ALP_Dis(void)
{
	if( ON_OFF() )
	{
		#ifdef	L_DEBUG
				Debug_PutString("*!*!*!*!*!..");				
		#endif	
		
		if( (SR2 && !SR3) || (SY2 && !SY3) || (SB2 && !SB3) )
		{
			#ifdef	L_DEBUG
				Debug_PutString("\n\rON..");
			#endif	
			if(SR2 && !SR3)
				Ph_R_ON();
			if(SY2 && !SY3)
				Ph_Y_ON();
			if(SB2 && !SB3)
				Ph_B_ON();
			Reset_Z();
		}					//	Close if()	
	}						//	Close if(ON_OFF)						
	else
	{
		#ifdef	L_DEBUG
				Debug_PutString("*$$*$$*$$..");				
		#endif	
	
		if(SR3 || SR4 || SY3 || SY4 || SB3 || SB4 )
		{
			#ifdef	L_DEBUG
				Debug_PutString("\n\rOFF..");
			#endif
			if(SR3 || SR4)
				Ph_R_OFF();
			if(SY3 || SY4)
				Ph_Y_OFF();
			if(SB3 || SB4)
				Ph_B_OFF();	
			Reset_Z();	 
		}					//	Close if()	
	}						//	Close else(ON_OFF)	
	#ifdef	L_DEBUG
		Debug_PutString("\n\n\r\t\t********************************");	
		Debug_PutString("\n\n\r HH:MM:SS ");
		Debug_PutInt(Hour);
		Debug_PutChar(':'); 
		Debug_PutInt(Min);
		Debug_PutChar(':'); 
		Debug_PutInt(Sec);
		Debug_PutString("\t Sys_Time ");
		Debug_PutInt(Sys_Time.StructTime.Hrs); 
		Debug_PutChar(':'); 
		Debug_PutInt(Sys_Time.StructTime.Mins); 
		Debug_PutChar(':'); 
		Debug_PutInt(Sys_Time.StructTime.Secs); 									
		Debug_PutString("\t   ON Time ");
		Debug_PutInt(ONTime.StructTime.Hrs); 
		Debug_PutChar(':'); 
		Debug_PutInt(ONTime.StructTime.Mins); 
		Debug_PutChar(':'); 
		Debug_PutInt(ONTime.StructTime.Secs); 
		Debug_PutString("\t OFF Time ");
		Debug_PutInt(OFFTime.StructTime.Hrs); 
		Debug_PutChar(':'); 
		Debug_PutInt(OFFTime.StructTime.Mins); 
		Debug_PutChar(':'); 
		Debug_PutInt(OFFTime.StructTime.Secs); 	
		Debug_PutString("\n\r\t\t********************************\n");
	#endif	
			
}
Esempio n. 6
0
int main()
{
    PS2Controller psData;
    char str[20];
    uint8 state = 0;
    CYBIT circle_flag=0,cross_flag=0,previous_circle=0,previous_cross=0;
    
    CyGlobalIntEnable; /* Enable global interrupts. */
    PS2_Start();
    Debug_Start();
    initLin();
    flag_StartEx(flag_isr);

    while(1){
        
        psData = PS2_Controller_get();
        
        /*Machine Initialization*/
        Automatic_State(0);
        
        /*-----Automatic Control------*/
        if((psData.SELECT == 1) && (psData.TRIANGLE == 1)){
            sprintf(str,"automatic mode\n");
            Debug_PutString(str);
            while(1){
                psData = PS2_Controller_get();
                
                //mode reset
                if((psData.SELECT == 1) &&(psData.START == 1)){
                    state = 0;
                    sprintf(str,"mode reset\n");
                    Debug_PutString(str);
                    break;
                }
                
                //State Increment
                if(psData.CIRCLE != previous_circle){
                    previous_circle = psData.CIRCLE;
                    if(psData.CIRCLE == 1){
                        state = state + 1;
                    }
                }
                
                //State Decrement
                if(psData.CROSS != previous_cross){
                    previous_cross = psData.CROSS;
                    if(psData.CROSS == 1){
                        if(state >= 1){
                            state = state - 1;
                        }
                    }
                }
                
                if(flag == 1){
                    Automatic_State(state);
                    flag = 0;
                }
                
            }
        
        }
        
        /*-----Manual Control------*/
        if((psData.SELECT == 1) && (psData.CROSS == 1)){
            sprintf(str,"manual mode\n");
            Debug_PutString(str);
            while(1){
                psData = PS2_Controller_get();
                
                //mode reset
                if((psData.SELECT == 1) &&(psData.START == 1)){
                    sprintf(str,"mode reset\n");
                    Debug_PutString(str);
                    break;
                }
                
                /*Arm*/
                Arm_Motion(psData.L1);
                
                /*Base*/
                Base_Motion(psData.UP,psData.RIGHT,psData.DOWN);
                
                /*Air*/
                Pantograph_Motion(psData.TRIANGLE);
                PantographHand_Motion(psData.CIRCLE);
                MainHand_Motion(psData.SQUARE);
                SidesHands_Motion(psData.CROSS);
            }
        }
    }
}