Controls LED's 1


Controls LED's and reads switch positions on AVR I/O module

Toolkit:AVR Development System

Location:/bipom/devtools/WinAVR/minimaxavrc/Examples/Labs/Lab02

Code Example


int main(void)
{
	unsigned char ndx;

	/* Initialize the UART1 */
	uart0Init(19200);	
					
	while(1)
	{
		
		//RED	LED group of input pins, X3 LCD connector

		uart0Printf("\n\r\n\r ( %s LED group )",X3_RED.name );

		for ( ndx =0; ndx < MAX_PIN_PER_GROUP; ndx++)
		{
			SetIO(&X3_RED.pin[ndx]);
			if (X3_RED.pin[ndx].port == UNUSED_PORT) 		  uart0Printf("\n\rNote. Not connected");
			else if (GetInput(&X3_RED.pin[ndx]) == SWITCH_ON) uart0Printf("\n\rSwitch  %s  is  ON  ",X3_RED.pin[ndx].nameSwitch);
				 else  		                            	  uart0Printf("\n\rSwitch  %s  is  OFF",X3_RED.pin[ndx].nameSwitch);

		}

		//ORANGE	LED group of input pins, X7 EXPANSION connector

		uart0Printf("\n\r\n\r ( %s LED group )",X6_ORANGE.name );
		for ( ndx =0; ndx < MAX_PIN_PER_GROUP; ndx++)
		{
			SetIO(&X6_ORANGE.pin[ndx]);
			if (X6_ORANGE.pin[ndx].port == UNUSED_PORT)    	     uart0Printf("\n\rNote. Not connected");
			else if (GetInput(&X6_ORANGE.pin[ndx]) == SWITCH_ON) uart0Printf("\n\rSwitch  %s  is  ON  ",X6_ORANGE.pin[ndx].nameSwitch);
				 else  		                               	     uart0Printf("\n\rSwitch  %s  is  OFF",X6_ORANGE.pin[ndx].nameSwitch);

		}
		
		//YELLOW	LED group of input pins, X4 KEYPAD connector

		uart0Printf("\n\r\n\r ( %s LED group )",X4_YELLOW.name );
		for ( ndx =0; ndx < MAX_PIN_PER_GROUP; ndx++)
		{
			SetIO(&X4_YELLOW.pin[ndx]);
			if (X4_YELLOW.pin[ndx].port == UNUSED_PORT)    	     uart0Printf("\n\rNote. Not connected");
			else if (GetInput(&X4_YELLOW.pin[ndx]) == SWITCH_ON) uart0Printf("\n\rSwitch  %s  is  ON  ",X4_YELLOW.pin[ndx].nameSwitch);
				 else  		                                     uart0Printf("\n\rSwitch  %s  is  OFF",X4_YELLOW.pin[ndx].nameSwitch);

		}
		
		//GREEN	LED group of output pins, X7 EXPANSION connector

		uart0Printf("\n\r\n\r ( %s LED group )",X6_GREEN.name );
		for ( ndx =0; ndx < MAX_PIN_PER_GROUP; ndx++)
		{
			SetIO(&X6_GREEN.pin[ndx]);
			if (X6_GREEN.pin[ndx].port == UNUSED_PORT) 	        uart0Printf("\n\rNote. Not connected");
			else if (GetInput(&X6_GREEN.pin[ndx]) == SWITCH_ON) uart0Printf("\n\rSwitch  %s  is   ON",X6_GREEN.pin[ndx].nameSwitch);
				 else  		                                    uart0Printf("\n\rSwitch  %s  is  OFF ",X6_GREEN.pin[ndx].nameSwitch);

		}
		
		_delay_ms(5000);

	}
}