Line 1: Line 1:
[[User:Guru|Guru]] ([[User talk:Guru|talk]]) 14:35, 7 November 2015 (IST)
+
[[User:Xplore007|Xplore007]] ([[User talk:Xplore007|talk]]) 15:44, 4 February 2016 (IST)
 
----
 
----
 
[[Category:AVR Tutorials]]
 
[[Category:AVR Tutorials]]
Line 9: Line 9:
 
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
 
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
 
</html>
 
</html>
We will interface a DIP switch to one of the port pins and LED's to other port pins.  
+
 
 +
=Objective=
 +
After blinking the leds, its time control these leds depending on external inputs. In this tutorial we will interface a DIP switch to one of the Port's and display its status on LED's connected to other port.  
  
  

Revision as of 15:44, 4 February 2016

Xplore007 (talk) 15:44, 4 February 2016 (IST)


The Rock (1996)

Objective

After blinking the leds, its time control these leds depending on external inputs. In this tutorial we will interface a DIP switch to one of the Port's and display its status on LED's connected to other port.


Hookup

You may look this up with the simple breadboard as shown in section below or you could use the Ultra AVR dev kit if do not wish to jumble with wires and resistors.

Type 1:Breadboard with Explore AVR 40 Pin Breakout Board with Atmega32

Components Used

1

AVR 40 pin breakout board with Atmega32

Click here to buy from our store

2

Breadboard

Click here to buy from our store

3

Male to Male Jumper Wires

Click here to buy from our store

4

LED - 5mm RED

Click here to buy from our store

5

Resistor

Click here to buy from our store

6

DIP Switch - 8 Position

Click here to buy from our store


Wiring diagram

Type 2:Using Explore Ultra AVR Dev Kit

Components Used

The Explore Ultra AVR Kit comes with all the things required, not just for this experiment but for the entire series. And even if you think of migrating to PIC or Arduino, you'll have breakout boards that fit on to this, hence we believe it is a great investment for learning hands on Embedded Systems. The kit is fully open source, you may use the schematics, the design files and all of the source code and build something cool on your own. And when you do that do not forget to share with us what you've done. We would be happy to see you building something cool.

Code

/*-----------------------------------------------------------------------------
                 Program to demonstrate Switches and Leds
  -----------------------------------------------------------------------------
 
note: 
1.Leds are  connected to PORTC
2.Switches are connected to PORTA
 
------------------------------------------------------------------------------*/
 
 
/*contains the definition of all ports and SFRs */
#include <avr\io.h>
#include "stdutils.h"
 
#define Switches PINA
#define LEDs PORTC
 
/* start the main program */
void main() 
{
   unsigned char SwitchData;
 
  /*Configure the PORTA as I/p to read the switch data */ 
   DDRC = C_PortOutput_U8;
   DDRA = C_PortInput_U8;
 
  while(1)
    {
 
	  /*Read the switch position */ 
	   SwitchData =  Switches; 
 
	 /*Turn on the respective led depending on Switch position */ 
	   LEDs=SwitchData;
	  }
  }

Video Tutorial

For those of you, who would like to watch instead of read we have made a video with all the gyan.