Basic of AVR Input Output


In this explanation and next others, I will use Atmega 8535/16/32. It is because this AVR series is commonly used by students and developer. But, sometime I will use Atmega 8 for some simpler case. Beside that, I also use C programming because it is easy to use and many people choose this programming language.
These are some superiority of Atmega 8535:
Advanced RISC Architecture
– 130 Powerful Instructions
– Most Single Clock Cycle Execution
– 32 x 8 General Purpose Working Registers
– Fully Static Operation
– Up to 16 MIPS Throughput at 16 MHz
– On-chip 2-cycle Multiplier
Nonvolatile Program and Data Memories
– 8K Bytes of In-System Self-Programmable Flash
Endurance: 10,000 Write/Erase Cycles
– Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
– 512 Bytes EEPROM
Endurance: 100,000 Write/Erase Cycles
– 512 Bytes Internal SRAM
– Programming Lock for Software Security
Peripheral Features
– Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
– One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture
– Real Time Counter with Separate Oscillator
– Four PWM Channels
– 8-channel, 10-bit ADC
8 Single-ended Channels
7 Differential Channels for TQFP Package Only
2 Differential Channels with Programmable Gain at 1x, 10x, or 200x for TQFP
Package Only
– Byte-oriented Two-wire Serial Interface
– Programmable Serial USART
– Master/Slave SPI Serial Interface
– Programmable Watchdog Timer with Separate On-chip Oscillator
– On-chip Analog Comparatoror
 And Many More
Let's Learn
Atmega 8535 has 32 I/O register. Port A, B, C, and D have 8 bit, so the total is 32 bit. If we want to make a pin working as an input pin, we set its DDR to ‘0’. But if we want to make a pin working as an output pin, we set its DDR to ‘1’.
When a port works as input, there are two options, making it as input with internal pull-up or making it as floating input. To activate the pull-up internal we set its PORT to ‘1’ but if we want make it as floating input we set its PORT to ‘0’.
When a port works as output, there are also two option, making it to have high voltage or to have low voltage. PORT is set to ‘1’ for high voltage and PORT is set to ‘0’ for low voltage.
Ok, let’s make a sample program for basic input output.
In programmer notepad or other source  editors and based on WinAVR. Please check this for explanation how to use WinAVR and AVR Studio.
Let’s make a C code:
#include <avr/io.h>
void main (void)
{ DDRA=0b00000000;
The explanation:

DDRA = 0b00000000, it makes 8 pin in PORTA to work as input.
PORTA=0b00001111, it makes PORTA.0 – PORTA.3 to use internal pull-up and PORTA.4 – PORTA.7 to be floating input.

DDRB= 0b00001111, it makes PORTB.0 – 3 to work as output and PORTA.4 –7 to work as input.
PORTB=0b00110011, it makes PORTA.0 –1 to have high voltage, PORTA.2 – 3 to have low voltage, PORTA.4 – 5 to use internal pull-up and PORTA.6 – 7 to be floating input.

DDRC=0b11111111, it makes 8 pin in PORTC to work as output.
PORTC=0b11110000, it makes PORTC0 –3 to have low voltage and PORTA4 –7 to have high voltage.

output of PORTD will be same as input to PORTA. To access the value of an input register we should use PIN not PORT. If PORTA0 – 3 are connected to Vcc and PORTA4 – 7 are connected to Ground, the output of PORTD0 – 3 are high and PORTD4 – 7 are low.

All bit in a I/O register can be access one by one for example: DDRA1, PORTC3, PIND5, etc. We can make PORTD3 = PINA5, DDRB1 = 0, etc.

Internal pull-up is usually activated when the input port is connected to switch. Floating input is usually used when the input port is connected with sensor.

In the program above, I use a macro, io.h. Why I use this macro? I use this because definition of PORT, PIN, and DDR are there. Beside that there are some function in this header file that will be usefull for our program in the next. Such as:

·         _BV(n); to set the n-th bit of a registert. e.g: DDRC = _BV(5) means DDRC5 = 1.
·         bit_is_clear(sfr, n); return value = 1, if the n-th bit of sfr (register) is clear. Clear means 0, Set means 1.
·         bit_is_set(sfr, n); return value = 0, if the n-th bit of sfr (register) is clear.
·         loop_until_bit_is_clear(sfr,n); do nothing until the n-th bit of register equal to ‘0’.
·         loop_until_bit_is_set(sfr,n); do nothing while the n-th bit of register equal to ‘0’.

Note: To be more expert, you can use AVR Studio to simulate a progarm. You can see characteristic and every changes in every register in AVR.


  1. Thanks for information Export Movers and Packers services in India provider low price save your time, comes with moving and packing services.
    Movers and Packers Mumbai
    Movers and Packers Hyderabad
    Movers and Packers Bangalore
    Movers and Packers Chennai
    Movers and Packers Pune

  2. How did you can avail the give your dream a shape with the help of make your move Adword India's No 1 online business experts.

  3. If you are Packers and Movers gives you stress free relocation services provide transport and moving services
    Packers and Movers Delhi
    Packers and Movers Noida
    Packers and Movers Faridabad
    Packers and Movers Ghaziabad

  4. All Packers and Movers India relocation services provided this company services are available pricrs for Top3th.
    Packers and Movers in Gurgaon
    Packers and Movers in Thane
    Packers and Movers in Navi Mumbai

  5. if you are looking packers and movers then dealkare is the right place for that it has huge list of verified packers and movers who provide services in all over india.
    service are packing, moving, loading, unloading etc.
    packers and movers in delhi
    packers and movers in mumbai
    packers and movers in noida

  6. Crazy Bulk Reviews
    crazy bulk is one of the best supplement for getting the weight for your body.

  7. Find best packers and movers in Etawah, uttar pradesh at home shifting wale. We provide shifting solutions for home relocation, office relocation, vehicle transportation etc. in domestic and as well as international. For more details call on+91 120-6448795
    packers and movers in Etawah
    packers and movers in Mathura
    packers and movers in aligarh
    home shifting wale

  8. This comment has been removed by the author.

  9. If you are a fresher and searching a job then go to jobsacid web portal. Here you will see many fresher jobs you just have to follow two step first to get registration and second is apply for relevant jobs which relate to your profile.
    Fresher jobs in durgapur
    Fresher jobs in agartala
    Fresher jobs in ahmedabad
    Fresher jobs in amritsar

  10. If you are looking for packers and movers in ghaziabad, then go to dealkare web portal. We have data of top 10 packing and moving services providers. Compare their price and choose best one, they also do post delivery services like unloading, unpacking etc.

  11. There are many astrologer in delhi but everyone is not genuine some of them are fraud, but now you can get information of genuine astrologer on internet, you just have to visit dealkare web portal. It has data of genuine astrologers you can get details of them easily.

  12. If you are looking for Body Massage Centres in delhi, then visit to . Dealkare will share Genuine information of SPA centres with you. They are affordable and have been providing services for long time.

  13. Find top coaching centers in delhi at . Dealkare has listed top 10 ten coaching institutes on its Website. You just have to visit there and choose best one according to your current location.

  14. If you are trying to find out the best used car to buy. But you are not able to get the car according to you, then there is a big solution of your problem. That is autocarbazar, here you will see the best collection of cars at very affordable prices.
    used cars in delhi

  15. If you are looking for Java summer training in NCR, ITSWS is one of the best company to provide you high class training on live projects. Where you can learn live experience.
    Java Summer Training in Noida

  16. Find shifting solution for all kind of relocation. We provide best shifting at genuine price. For booking call on +91-8287 608 512.
    Relocation Services in Ghaziabad

  17. Find all IBPS exams details at Findsarkarijobs. It is a government jobs web portal where job seeker can find all information about government exams.
    Ibps Exam Result 2017

  18. If you want to hire packers and movers in Chhattisgarh, you just need to check out to get the best service at very affordable price. To contact us just dial -> 91 9212 274 267
    packers and movers in chhattisgar

  19. Find SSC Exam CALENDAR 2017 at find sarkari jobs. We are online service provider whare you can see government exams information.

  20. Java Industrial Training in Noida :- If you want to make your career in Java Platform, then ITSWS technologies is the best traing centre for Java technology.

  21. Automotive Turned Components Manufacturers :-We have been Automotive Turned Components manufacturer for over many years.

  22. We shifting wale provides best relocation services in Agra. Our services are home shifting services
    packers and movers in gujarat
    packers and movers in haldwani

  23. If you are looking for Precision Turned Parts manufacturer to buy Precision Turned Parts, Sanjaypersion is one of the best Provider.

  24. Get The Best Java Training Institute in Noida at very affordable price on live projects with ITSWS COMPANY.

  25. • Hire the full services of the moving agency
    It is advisable to hire the full services of the moving agency. By hiring the full services of the moving agency your relocation will become very easy and safe. You will don’t have to do anything regarding the relocation process. Hiring the moving agency will make the relocation easier and you will feel light and comfortable.

    Packers and Movers in Pune
    Movers and Packers in Pune
    Packers and Movers Pune
    Movers and Packers Pune

  26. If you are looking for box truck rentals, then there is only one company. Which can provide you the best box truck rental service. To contact us just dial - 8287 27 8287 or visit our website:

  27. Shaila Enterprises manufactures custom RMC formulations based on the specific needs and budget of the client. We are fully equipped to ensure that both quality and consistency are maintained across each batch.

    Shaila Enterprises
    Ready Mix Concrete
    Shaila Rmc
    Shaila Concrete
    Rmc Supplier Delhi
    Best Rmc Supplier Delhi
    Ready Mix Concrete Gurgaon
    Ready Mix Concrete Company
    Rmc Plant In Gurgaon
    Shaila Ready Mix Concrete
    Ready Mix Concrete Delhi Ncr

  28. If you are searching for Turned parts manufacturers, then is the best for you

  29. Looking for Top LLB Institute in Delhi, you must check out IPEM College.

  30. Looking for Turned Parts Manufacturers, just visit Here you will get the best turned machine parts at very affordable price.

  31. Looking for cheap moving companies, visit, here you will get the best service at very good price.

  32. If you are looking for MCA college in delhi, IPEM is one of the best college. You must check it out.

  33. provides the best quality Pioneer AVH-299BT Car Head Unit at very affordable price

  34. Shiftingwale provides the best packing and moving service at very affordable price.
    Packers and movers in Noida

  35. Want To hire Agarwal Packers and Movers but looking for reviews. There is a link given below. Just visit that link and you will find the original Reviews.

    Agarwal customers Reviews

  36. If you want to hire truck and looking for the best truck rentals companies, you must check out for best result.

  37. IPEM is a top class MBA College in Ghaziabad NCR. To get more information just visit our website :

  38. Do you want to hire moving truck? If yes, you should come to truckingcube to get the best service.

  39. Buy Used Cars in Faridabad from, here you will get the best price of cars.

  40. IPEM is one of the top Best MCA Institutes in Ghaziabad. To know more just visit :

  41. To make clients Movers Packers full satisfaction and secure with most of the experience arrange complete packing, moving, loading and unloading facility to their buyers.
    Packer Mover in Gottigere
    Home Shifting Services in Gottigere

  42. Search engine optimization Services Provider Company in your city.
    SEO Service in Noida
    SEO Company in Ghaziabad

  43. If you are looking for Event in delhi and Get all information related to Delhi Events.

  44. Hey there, You have done a fantastic job. I wll definitely digg it and personally suggest to my friends. I am sure they will be benefited from this site.IELTS coaching center in Hyderabad kukatpally

  45. Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you could do with some pics to drive the message home a bit, but other than that, this is fantastic blog. An excellent read. I will definitely be back. .Costumes for Rent in Hyderabad

  46. The Webtrackker Technology is providing Best Training with industrial Expert trainer. We have Lab facility fully practically and giving Best java training institute in noida learn real-time project with 100% Placement Support.

    Best Java Training Institute in Noida

    Digital Marketing Training Institute in Noida

    Best Auto CAD Training Institute In Noida

  47. Thank you for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit.
    sap abap online training in usa

  48. Thanks for sharing this Informative content. Well explained.
    AngularJs Training in Noida

  49. If you are facing a matrimonial problem. You think your husband cheats you. He has an affair with another girl. But you are not sure about this and You want to go to the depth of truth. Then you have need of Alliance Detective Agency. We provide the best personal detective to solve these types of cases. For more information go to our website. To go to our website follow the link:

    Detective agency in Delhi

  50. Saying thanks will not just be sufficient,Matrimonial detectives for the fantastic lucidity in your writing.

  51. Lots of great information and inspiration, Detective agency in Delhi both of which we all need. Thanks

  52. Keep up your Excellency and efficiency in upcoming Blogs.
    Detective agency in Delhi

  53. This blog provided in the exact information searching in the concerns...
    Private Detective Agency in Mumbai

  54. Boost your website ranking on Google SERP page with the help of SEO activity. You are searching for an SEO service provider company in Noida then JY Infotech provides this service at a low budget. We do regular work on your website. For further information go to the website to click the given link: Best SEO company in Noida

  55. JY Infotech is the best website designing company in Noida. If you have needed your business website then contact us. We provide best design website at an affordable price. For more information you can call us: 8006748873 or follow the given link: Website designing company in Noida

  56. JY Infotech is the best website development company in Noida. If you are searching for a website development company to develop your business website then meet JY Infotech. We provide free hosting and well-developed website at an affordable price. For more information follow the given link: Website development company in Noida

  57. If are you searching for a mobile app development and IOS app development company in Noida then you contact JY Infotech. JY Infotech is the best IT company in Noida. We provide a fully functional and working application in your budget. For more information follow the given link: Mobile App Development company in Noida

  58. If you are searching for a digital marketing company in Noida for the growth of your business. JY Infotech is the best digital marketing company for you. We work on all social media platforms to give you good audience. For further information visit the given link: Best digital marketing company in Noida

  59. If you are searching for ZLD plant manufacturer company to install a ZLD plant in your industry, then meet us. We provide this service in your area with advanced technology. A Zero Liquide Discharge(ZLD) plant reuse the waste liquid or water. For more information follow given link: ZLD plant Manufacturer

  60. Thanks for sharing such an informative article. Zodiac packers movers provide best packers and movers services in Delhi at an affordable price.
    Domestic Packers
    International Packers
    Office Shifting

  61. Very informative article.
    For best packers and movers in Gurgaon visit and get big discount.
    Home relocation services in Gurgaon
    Packers and movers in Gurgaon

  62. Nice article thanks for sharing this information. Zodiac packers movers provide best packers and movers services in Delhi at an affordable price.
    packers and movers in Delhi
    packers and movers in Dwarka
    packers and movers in Pitampura
    packers and movers in Rohini

  63. Being a leading web development company, we help you grow your business through a professional web portal application development process showcasing our products in an efficient way.

  64. Nice tips. Very innovative... Your post shows all your effort and great experience towards your work Your Information is Great if mastered very well.
    AWS training in chennai | AWS training in annanagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery