Controls LED's 2


Controls LED's on TB-1 board

Toolkit:AVR Development System

Location:/bipom/devtools/WinAVR/minimaxavrc/Examples/Labs/Lab03/LAB3_1

Code Example


#define LED_RED          6        //PB6

#define LED_YELLOW       4        //PB4

#define LED_GREEN        5        //PB5


#define LED_RED_ON() 		(PORTB	&=~ 0x40)
#define LED_YELLOW_ON()  	(PORTB	&=~ 0x10)
#define LED_GREEN_ON()  	(PORTB	&=~ 0x20)

#define LED_RED_OFF() 	    (PORTB	|= 0x40)
#define LED_YELLOW_OFF()   	(PORTB	|= 0x10)
#define LED_GREEN_OFF()   	(PORTB	|= 0x20)

// ****************************************************************************

int main (void)
{
	unsigned char i;

	// Initialize port pins

 	// Define pull-ups and set outputs

	// Define directions for port pins

	PORTB = (1<<LED_RED)|(1<<LED_YELLOW)|(1<<LED_GREEN);
	DDRB  = (1<<LED_RED)|(1<<LED_YELLOW)|(1<<LED_GREEN);
	
	// Initialize the UART

	uart0Init(19200);


	while(1)// loop forever

	{
		uart0Printf("\n\rRed    LED  is turned ON\n");	
		LED_RED_ON();  			//turn on Red LED

		_delay_ms(3000);   		//delay 3 seconds

		LED_RED_OFF();  		//turn off Red LED

		
		uart0Printf("\n\rYellow LED  is turned ON\n");	
		LED_YELLOW_ON(); 		//turn on Yellow LED

		_delay_ms(3000);	   	//delay 3 seconds	

		LED_YELLOW_OFF();		//turn off Yellow LED		

		
		uart0Printf("\n\rGreen  LED  is turned ON\n");	
		LED_GREEN_ON();			//turn on Green LED

		_delay_ms(3000);   		//delay 3 seconds			

		LED_GREEN_OFF() ;		//turn off Green LED

		
		uart0Printf("\n\rRed    LED  blink\n");
		for(i=0;i<10;i++)
		{
			LED_RED_ON();		//turn on Red LED

			_delay_ms(500);  	//delay 0.5 second

			LED_RED_OFF();		//turn off Red LED

			_delay_ms(500);  	//delay 0.5 second		

		}
		
		uart0Printf("\n\rAll three LED's  blink\n");
		for(i=0;i<10;i++)
		{
			LED_RED_ON();    	//turn on Red LED

			LED_GREEN_ON();		//turn on Yellow LED		

			LED_YELLOW_ON() ;	//turn on Green LED		

			_delay_ms(500<<1);  //delay 0.5 second

			
			LED_RED_OFF();     //turn off Red LED

			LED_YELLOW_OFF();  //turn off Yellow LED		

			LED_GREEN_OFF() ;  //turn off Green LED			

			_delay_ms(500);    //delay 0.5 second

		}		
	}
}