Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • EE Design News
    • DIY Reviews
    • Guest Post
    • Sponsored Content
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

How to take input from a particular pin of ATmega16- (Part 5/46)

February 4, 2011 By Ashutosh Bhatt

For understanding the human needs a system must be able to take input from user. The devices which can be used to take input for a system are keypad, touch screen, etc. In the article LED blinking, the microcontroller drives the LED or in embedded language the microcontroller was set to give o/p, this article gives brief information of getting an input from user at a particular pin of microcontroller.
 

 

In order to take input from an external source on any of the pins of the AVR microcontroller, the pins need to be configured as input pin. This configuration informs the controller that the corresponding pins are used to take input. The following steps explain how to take input from a pin:
 

Block Diagram to take input on Atmega16 pin

Fig. 2: Block Diagram to take input on Atmega16 pin
 
Step1: Set the direction of PORT
To use a port as an input port first set the direction of port. DDRx (Data Direction) Register is used to set the direction of port.
DDRA=0x00;
In DDRA, ‘A’ shows the portA and 0x00 sets all the pins of port as input pins. (Writing 0 in DDR makes it input pin and writing 1 in DDR makes it output pin.
 
Step2: To take input form a port
Make a variable and use PINx instruction to get the input from a port
Value=PINA;
Where Value is a variable.
 
How to compare a pin?
To compare a pin, the instructions bit_is_set or bit_is_clear can be used. These instructions are define in avr/sfr_defs.h library. There is no need to include this library in code if avr/io.h has been included.
 

Project Source Code

###

// Program to take input from a particular pin in AVR Microcontroller (ATmega16)
#include<avr/io.h>
#include<util/delay.h>

int main (void)
{
unsigned int i=0;
DDRA=~_BV(PA0); // PA0 as input pin
PORTA=0x00;
DDRD=0xff;

while(1)
{
PORTD=0x01;
while(PORTD!=0)
{
if(bit_is_set(PINA,PA0)) //If PA0=1
{
_delay_ms(100);

if(bit_is_set(PINA,PA0)) //Check it again due to swithc debouncing
PORTD=(PORTD<<1); //Left shift value of PORTD by 1

}

}
}
}

###

 


Circuit Diagrams

Circuit-Diagram-of-How-to-take-input-from-particular-pin-of-ATmega16

Project Components

  • ATmega16
  • LED

Project Video

Related Articles Read More >

Atmega162 UAR serial communication using Arduino IDE
Controlling a BLDC Motor with an ESC
LED chaser using AVR ATMega16
Satellite dish antenna angle controller using ATmega16

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Getting Started with the ESPlorer IDE
  • SENDING TEXT MESSAGE USING ESP8266
  • CONNECTION BETWEEN TWO ESP8266
  • ESP8266 WIFI HOTSPOT
  • HOME AUTOMATION USING ESP8266
  • Open WiFi Scanner using Esp8266

Stay Up To Date

Newsletter Signup

EE Training Center Classrooms

“ee

“ee

“ee

“ee

“ee

Recent Articles

  • TV remote hack using Arduino and IR sensor
  • Gesture sensor using Arduino
  • Diodes adds to its family of voltage-level shifters
  • Xilinx expands UltraScale+ portfolio to include compact, intelligent edge solutions
  • New Armv9 architecture designed to increase security and AI capabilities

RSS EDABOARD.com Discussions

  • WiringPi SPI without Chip Select/Enable?
  • Need help in optimizing RF antenna balun on two port network analyzer
  • Different types of screened cable, which is best?
  • Radiated immunity testing for product that has an antenna and receiver?
  • ealtek RTL8722DM_mini Arduino Compatible WiFi + BLE IoT development board

RSS Electro-Tech-Online.com Discussions

  • Help with circuit design
  • Adjustable 0-5v ground switch
  • Multiple UART Hub to USB?
  • Need to add a question to a thread.
  • Weird switching transformer noise, Audio attached
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2021 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Circuit Design
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • EE Design News
    • DIY Reviews
    • Guest Post
    • Sponsored Content
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • Video
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering