101 Comments

  1. mohi

    Hi everybody!
    How can I use adc with 2 inputs?

    Reply
  2. Wasi

    for a burglar alarm system having 8 digital and 2 analog presence detection sensor. Write a code for monitoring all the sensors contionously and display the values on serial terminal using serial port in the following format?
    Can some one make the code in C language?

    Reply
  3. Vijesh

    Awesome explanation. Thank you.

    Reply
  4. Dimas W

    Thanks you, it help me a lot 😀

    Reply
    • Elecrom

      Thanks … please share it with your friends if you have liked it 🙂

      Reply
  5. manuel

    really, good tutorial,why dont you continue this tutorials?

    Reply
    • Elecrom

      Thanks 😀 … I’m glad to know that even after so many years, it still holds value for the readers.

      Your comments are encouraging. I will try to write more and more tutorials in celecromng months 🙂

      Reply
  6. AnswerMePlz

    hi,i am a bad bad beginner.Have a Question:
    I want to send a message(Password) from mobile to bluetooth module HC05 and next, to AVR Atmega32a.
    and in the AvR, check if it is the right string(password) defined in the AVR or not!
    [if true], blink an LED.
    [else] message back “Wrong Password”. and this message goes the other way round!(AVR–>Bluetooth module–>Mobile)
    How to do this? Actually i have problem with the code,Dont know what to write for it?
    i just did supply the power to HC05 and rx to tx of avr,and tx to rx of avr.
    Thanks in advance

    Reply
  7. hal

    thank you, it helped me

    Reply
  8. Saish

    all post by me r for aTmega 32 UC

    Reply
  9. Saish

    to receive data on rx pin frm receiver module
    is dis da correct command
    DDRD=0X00;
    PORTD.0= 1;

    Reply
  10. Saish

    to get input on adc pins is dis da right command
    DDRA= 0X00
    PORTA0X00
    REPLY ME FAST.

    Reply
  11. Kia

    This arctile shows how pointer and its massive works.thanks

    Reply

  12. I am really loving the theme/design of your web site.

    Do you ever run into any browser compatibility issues? A number of my
    blog audience have complained about my website not operating correctly in Explorer but looks great in Firefox.
    Do you have any solutions to help fix this problem?

    Reply
    • Elecrom

      This is developed using standard wordpress templates. These templates are well tried and tested and work properly on most of the platforms.

      Reply
  13. S.Vishali

    why we are not getting the voltage at the specified port

    Reply
  14. M.Sabeena

    i have flashed the servo program in the ATMEGA 8L controller and practically checking the controller by connecting the servo . servo was not running and we didn’t get the voltage at the output port .

    Reply
  15. sharma

    same characters data is given into microcontroller atmega16L but it is taking some of the continous same bits as different.
    help to resolve the problem

    Reply
  16. jay dubey

    i tried to read keypad from portA and use pull ups but it displayed random numbers. can you help??

    Reply

  17. The DDRC.0 = 1; format doesn’t work for me. I get something like:

    expected ‘;’ before numeric constant

    I have to mask the relevant bits to make it happen. Is it just me?

    Reply
    • Elecrom

      DDRC.0 = 1; >> This format is supported by CodeVisionAVR compiler. Other standard C compilers don’t support it, so you will have to do masking.

      Reply

      • How can we do this type of programming in AVR Studios ?? I am not able to get how to address the particular pins of a port.

        Reply
        • Etienne Doucet

          Here’s some example of how you can manipulate a single bit in AVR Studio

          DDRx &= ~(1<<4); //To clear a bit (Same as DDRx.4 = 0)
          DDRx |= ~(1<<4); //To set a bit (Same as DDRx.4 = 1)
          DDRx ^= ~(1<<4); //TOGGLE bit 4 in DDRx register

          x Can be A,B,C,D … depending on what you need to change
          4 Can be 0-7 (the bit number you want to change)

          You can also change an entire port value with 1 command
          DDRB = 0xFF; //0b11111111
          PORTB = 0x07 ; //0b00000111

          Reply
          • Jarjan

            DDRx &= ~(1<<4); //To clear a bit (Same as DDRx.4 = 0)
            DDRx |= (1<<4); //To set a bit (Same as DDRx.4 = 1)
            DDRx ^= (1<<4); //TOGGLE bit 4 in DDRx register

            The first were OK 🙂
            Hi

  18. ran

    I don’t understand how to set an interupt. Can you help me, if I want to program atmega 8535 with interupt after 1 minute. I really need some help 🙁

    Reply
  19. WSS

    THANKS A LOT. REALLY THANK YOU 🙂

    Reply

  20. Its a great start for freshers…thanks.

    Reply
  21. Jason

    Now can you make a tutorial for AVR32? I can’t make a freakin port any which way and Atmel Studio 6 won’t let you..

    Reply
  22. h_chinh94fbr

    thanks a lot

    Reply
  23. Treehouse Projects

    Thanks a lot, great tutorial for someone just starting with the Atmega series!

    Reply

  24. Very neat and easy tutorial about AVR I/O, the overall credit goes to omkar. The article presentation is very impressive!

    Reply
  25. Ariz Zubair

    it was quite useful .
    Can u please help me with receiving 16 bit serial input on porta.1 and output the parallel data on portb and port c.

    Reply
  26. Thoufeeq

    Thanks for the article, was quite helpful…

    Reply
  27. Rafael

    Thanks! With this info I can work with input! 🙂

    Reply
  28. kingsley

    How can i use ATmega16 16 bits timer to create delays

    Reply
    • Elecrom

      Configure the timer in CTC top mode, set the top count in OCR register and wait till the count match occurs. This will give u variable delays.

      Reply
      • kingsley

        Thanks for the hint, to be frank i’m new at using AVR. Can you give me any code in C that is used to create the delay.

        Reply
  29. kingsley

    Thank you so much, your tutorial has given me a head start. I really appreciate your effort simplifying AVR programming

    Reply
    • Elecrom

      Thank you.

      Reply

  30. wow! I was really wondering how the hell was this PINx working? and I got the answer. Thankx admin

    Reply
  31. DEEN BANDHU AGRAWAL

    wow it had really helped me

    Reply

  32. hafxx

    thanks a lot for this information.. very nice.. and its give me some idea/clue to understand basic i/o for microcontroller…

    Reply
  33. manisha

    What is the meaning of y[0]=(PINA & 0x01);

    Reply
    • Elecrom

      it means, y[0] will get the value of 0th bit of port A. It will be either 0 or 1.

      Reply
      • gautam

        i have error of above program so please tell me solution

        Reply
    • neeraj

      how to declare the y[0] over here

      Reply
  34. kedarnath reddy

    Thanks a lot this gives a clear idea of the Input and Output configuration.

    Reply
  35. Iqbal

    is there any tutorial for AVR assembler and c language??

    Reply
    • hassan

      well there is one at a time, first learn assmbly thn c,, thts recomendation,..

      Reply
  36. Shakhawat

    Thanx a lot. Its something exxactly, I was looking for.

    Reply
  37. anoop

    Sir i am saying you my extreme thanks..Actually i was in a problem with the port setting of my ATmega32 controller.Your tutorial help me a lot…Once again i am thanking you..Expect more like this from you..

    Reply
    • Elecrom

      🙂 … thanks for appreciation.

      Reply
  38. Owais

    Thanks alot Sir, Exactly what I was searching.
    You really need a big round of applause…. Hats off.

    Reply
  39. rajput vikas singh

    sir i think u should include more led blinking programs to clear the concepts

    Reply

  40. DDRx.n, PORTx.n and PINx.n (n=0..7)do not work in WINAVR. Would have been nice if you added code for that too.

    Reply
  41. sabeeh

    thx alot man!…this is wht i waz lookin 4…

    Reply

  42. Thank you for the superb tutorial, but there is one thing I don’t fully understand.

    I have an input signal and I want it to be 0 when the output device is not connected. You mention to set the PORTX high to achieve pull-up, and set it to zero to achieve tri-state. But I want to achieve pull-down. It isn’t mentioned in the tutorial how to do this. I tried setting neither and just let it choose by it’s own, but I’m not getting a pull-down. Could anyone help me with this?

    Reply
    • Elecrom

      To do this, make port pin tri stated and then connect external 10K resistor between port pin and ground pin. This 10k resistor will act as a ‘pull down’ resistor. In this way, when device is not connected, pin will get pulled down to ground potential.

      Reply
  43. kiran

    superb tutorial, first para. gives idea of importance of this tut.

    Reply
  44. rishi

    i really like ur tutorials.i have doubts in interfacing keyboard with atmega16 using code vision avr.please clarify me the concept and programming.

    Reply
  45. Priyanka

    Thanx…this is what i was exactly looking for.

    Reply
  46. saeed

    i can’t run portl and h & k in avr stadio4.micro is atmega2560

    Reply
  47. Elliot Brown

    <codePINC.1==0</code Is this valid for atmega8 and all compilers? I've heard it doesn't work for all.

    Reply
    • Elecrom

      – ATmega8 has PORTC and hence you can use the statement if(PINC.1==0) – This statement is valid only in those compilers which support bit level access. For other compilers you can use : if( (PINC & 0x02) == 0)

      Reply
      • Tony

        i use AVR Studio, and it doesnt work with single bit acces (PORTC.1 = 1;).
        What compiler should i use to make it works?
        I work with ATMega16 THX

        Reply
        • Elecrom

          you can use CodeVisionAVR compiler. Or in AVR Studio you can also write like this : PORTC.1 = 1;.is equivalent to : PORTC = PORTC | 0x01;

          Reply
          • MP

            hey man.. what is the equivalent of PORTC.1 = 0; ?????

    • MP

      hey man.. what is the equivalent of PORTC.1 = 0; ????

      Reply
      • Elecrom

        “PORTC.1 = 0”

        is equivalent to :

        “PORTC = PORTC & 0b11111101”

        Reply
  48. fabrizio

    Mate,
    this is exactly what I wanted to know !

    well done
    fabrizio

    Reply
  49. zayed

    Design and implement a a communication link of two AVR’s using SPI. One AVR is connected to
    switches through its GPIO lines. It reads the status of the switches and send it to another using
    SPI. The second AVR reads the received data and display it on 7-segment displays. Include a
    snapshot of the serial clock and data lines as seen on an oscilloscope.

    Reply
  50. divyanaidu

    yeah,in a very simple and understanding way explained ,its very helpful for begginers,
    i am using atmega2560 –from external sensors to adc through spi communication i suppose to do

    would any one send me any source code or something how to implement

    Reply

  51. Im including a list of great AVR tutorials on my blog, so ill have to sift through your work and see if I can include your tutorials!!

    Reply
  52. almostnone

    Thanks. This helped me understand Atmega1280 as well.

    Reply
  53. noufal

    Halo, I’m just beginner of programming AVR and I have some problems. I’m working with AVR Studio 4 and writing a program for ATmega16 TIMER0 normal mode in assembly language..the code is
    .equ TCCR0=$33
    .equ TCNT0=$32
    .equ TIFR=$38
    .cseg
    .org 0x00
    JMP MAIN

    MAIN:
    LDI R16,0X02
    out TCCR0,R16
    l1: SBIS TIFR,0
    JMP L1
    JMP MAIN

    when compiling it shows the error
    D:avrtimer.asm(13): error: Operand 1 out of range: 0x38
    D:avr assemtimer.asm(22): No EEPROM data, deleting D:avr assemtimer.eep

    please help me to find the error… hopefully

    Reply
  54. praveen

    please post AVR : Tutorial 3.
    Ur first two were very informative, so please post AVR : Tutorial 3
    write abt advance prog n burning da hex file in da uC

    Reply
  55. Niklas

    Very nice and informative tutorial. Please post more of these tutorials they are really usefull for me, on the right level so to speak.

    Perhaps you can recommend some other resoures for beginners, perhaps the ones who helped you when you first got started.

    I look forward to your next post, its been 8 months!

    /Niklas

    Reply
  56. josh

    never mind, I found it. This site is very helpful, keep it up.

    Reply
  57. josh

    hi, where can i find the mega16 and delay header file? I have the original AVR library but has none of those file in it.

    Josh

    Reply
  58. aak fajar

    In datasheet ATMega8535, ADC has 10-bir resolution. But I can’t setting ADC in this resolution (10-bit). May u can help me how to setting ADC in ATMega8535 with 10-bit resolution. Or may be i must to add other circuit to use ADC 10-bit?
    I hope u can reply this question ini my mail. Thanks.

    Reply
  59. harsh

    How to burn a program from computer to atmega16 microcontroller using ping prong.

    Reply
  60. elecrom

    >>Avinash
    I don’t think its possible to overclock low speed (L) versions. I have tried overclocking 16PU versions and they work fine. 16PU can be overclocked upto 24MHz, but you should give supply voltage of 5.5 and not 5.0. Whenever you overclock, you should increase supply voltage upto (just less than) maximum limit of the chip for proper operation at elevated clock rate. However don’t run it at 24MHz unless really required. In my opinion you can run it safely upto 20MHz.

    Reply

  61. Nice work. Have you tried overclocking avrs. Can the lower power versions (L) can be made to run with speed more than 8Mhz?

    Reply
  62. elecrom

    >>Sri Ram
    I will post tutorial on interrupts soon.

    Reply

  63. Thank you very much. U tutorial really helped me in understanding i/o ports. Though I did not understand clearly (I am not EEE) the concept of impedance for tri state input, but it clarified the main concept how to use ports for different purposes. It seems to me your knowledge of AVR programming was mastered, can you please send me tutorial on interrupts and interrupt vectors (mega128 or similar) to my mail [email protected] if you have any. Any help will be much appreciapted. Thank you.

    Reply
  64. elecrom

    @Donatas : Whats this “delay.h” stuff ???
    CONTINUED …..

    In above function some delay will be generated by loop at line 5. You can change the loop count to adjust the delay. You can fix the loop count by some trial and error for 1ms or so and then use that function. You can also put lots of assembly “NOP” instructions inside loop at line 5 and get some predictable delay. For example if your uC is operating at 8MHz, then one NOP will take 125ns …

    001: void my_delay_ms(unsigned int m )
    002: {
    003: unsigned char p;
    004: for( ;m>0;m=m-1 )
    005: for(p=0;p<100;p++) //This will generate approximate delay
    006: { //of 1ms using NOPs
    007: #asm(“nop” )
    008: #asm(“nop” )
    009: #asm(“nop” )
    010: #asm(“nop” )
    011: #asm(“nop” )
    012: // … repeate total 80 times. So these NOPs will
    013: // give delay of 80 x 125ns = 10uS
    014:
    015: }
    016: }

    This function will provide approximate delay in multiples of 1ms. Delay is approximate because, delay occured by instructions required for looping are ignored. Because of this actual delay will be slightly more than the specified one.

    Reply
  65. elecrom

    @Donatas : Whats this “delay.h” stuff ???

    You have mentioned AVR studio 4 but not mentioned which compiler you are using. Anyways … many AVR C compilers have built-in delay functions to ease programming. They are defined in delay.h.

    In above program, to generate delay I am using such library function “delay_ms()”. It is defined in “delay.h” (for this specific compiler, i.e. codevisionavr) and hence included. See the code vision avr help for more details of “delay_ms()”.

    For avr-gcc, similar file is “util/delay.h”. See this for more information about this file.
    http://www.nongnu.org/avr-libc/user-manual/group__util__delay.html

    Alternatively, if you don’t want to use built in delay, you can make some function like this :
    001: void some_delay(unsigned int some_number )
    002: {
    003: unsigned long int p;
    004: for( ;some_number>0;some_number=some_number-1 )
    005: for(p=0;p<300000;p++ )
    006: {
    007: }
    008: }

    Reply
  66. Donatas

    Hi, I’m just beginner of programming microcontrollers and I have some problems. I’m working with AVR Studio 4 and writing a program for ATmega16. In your examples and in a lot of other examples delay.h is included, but I can’t find it and for this reason I have an error. What I should do and where I can find this file?
    P.S.: it would be very nice if you write some examples about processor sleep mode and saving battery when mC is doing nothing.

    Reply
  67. Benzun

    I must say your tutorial is very good.. i am just entering second yr… and was never clear about avr pin setting.. but your tutorial cleared a lot of doubts.. can u just explain me the purpose of pull up… i dont understand it clearly.. if u have time can u pls mail me at [email protected] ?? must say your work is awesome.. you have a very clear understanding of avr programming….

    Reply
  68. Ashutosh

    Actually iam using two ir sensors kept at a fixed distance.Both connected to two adc pins of atmega8L.When a object passes in front of first sensor,the analogue signal is taken and converted into digital and goes to pc via parallel port,here a timer starts as the signal is received and stops on receiving second signal.As distance is known and time ir there,speed can be calculated.I want to know abt how to go for programing.

    Reply
  69. elecrom

    @Ashutosh
    I didn’t get what u say.

    Reply
  70. Ashutosh

    Hey i need to use adc port of atmega8L to receive input from ir sensors and then send to the parallel port to measure speed. Guide me in programming part.

    Reply
  71. ashishd

    Elecrom, Can u created swf file?
    Are we not suppose to upload files?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.