Demo entry 6333806

Practica 1

   

Submitted by anonymous on Dec 04, 2016 at 22:52
Language: C. Code size: 1.3 kB.

int main(void) {

	WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
	P1DIR=P1DIR|(BIT0|BIT6);	// Definimos los pines de salida
	P1REN|=BIT3;	// habilitamos el Pull-up/Pull-down resistor enable en el  pin 3
	P1OUT|=BIT3;	// Definimos si queremos Pull-up o Pull-down ( 1 para Pull-up y 0 para Pull-down )

	char status = 0;
	while(1)
	{
		switch(status){
		case(0):
		P1OUT=P1OUT|BIT0;
		P1OUT=P1OUT|BIT6;
    	if(!(P1IN&BIT3))
    	{
    		flag=1;
    	}
    	__delay_cycles(10000);
		if((P1IN&BIT3)&&flag)
		{
			flag=0;
			status++;
		}
		break;
		case(1):
			P1OUT=P1OUT&~BIT0;
    	    if(!(P1IN&BIT3))
    	    {
    	    	flag=1;
    	    }
    	    __delay_cycles(10000);
    	    if((P1IN&BIT3)&&flag)
    	    {
    	    	flag=0;
    	    	status++;
    	    }
		break;
		case(2):
			P1OUT=P1OUT&~BIT6;
			P1OUT=P1OUT|BIT0;
	   		if(!(P1IN&BIT3))
    	   	{
    	   	    flag=1;
    	   	}
	   		__delay_cycles(10000);
	   		if((P1IN&BIT3)&&flag)
	   		{
	   			flag=0;
	   			status++;
	   		}
		break;
		case(3):
			P1OUT=P1OUT&~BIT0;
    	    if(!(P1IN&BIT3))
    	    {
    	    	flag=1;
    	    }
    	    __delay_cycles(10000);
    	    if((P1IN&BIT3)&&flag)
    	    {
    	    	flag=0;
    	    	status=0;
    	    }
		break;
		}
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).