AVR microcontroller basic-2.

By IKTech May 29, 2017

The AVR microcontroller basics are in today’s episode. How to write a basic basic program and it can be loaded through simulation to see the effectiveness of the program.
How to Write a Basic Basic Program

 

In the past we have seen how to open a new project. Open a new project by following the direction of the past. Please choose atmega8 as the device when you open it.

Then you will get a code window like the picture below.

Enter the code below
#include <avr / io.h>
#include <use / delay.h> // for _delay_ms ()

Int main (void)
{
DDRB = 255; // initialize port B
While (1)
{

PORTB = 0b11111111; // Al the pins of PORTB will be high
_delay_ms (3000); // wait 3000 milliseconds

PORTB = 0b00000000; // Al the pins of PORTB will be low
_delay_ms (3000); // wait 3000 milliseconds

}
}

Click Build Solution from the Build menu. Then compile the .hex file to be created.

The .hex file can be found in C: \ Users \ my \ Documents \ AVRStudio 5.1 \ avrtutorial2 \ avrtutorial2 \ Debug

We will load this .hex file in microcontroller.
How to design simulation hardware at PROTEUS, take a look

Open the PROTEUS ISIS and click on Pick from Libraries as shown below.

Follow the instructions below. Search by keywords at atmega8, then select, finally click on the OK button.

The mouse pointer will hold the pencil size. Bring one click to the atmega8 design window.

Now double click on the microcontroller and show the location of the .hex file.

Click Play button. Follow the pictures below.

Then the code written by us will run.

In the above animation, we see that the pins that have PB0 to PB7 on the left are logical, then waiting for three seconds, then waiting for three seconds for logic load.
Review the program
#include <avr / io.h>
#include <use / delay.h> // for _delay_ms ()

Int main (void)
{
DDRB = 255; // initialize port B
While (1)
{

PORTB = 0b11111111; // Al the pins of PORTB will be high
_delay_ms (3000); // wait 3000 milliseconds

PORTB = 0b00000000; // Al the pins of PORTB will be low
_delay_ms (3000); // wait 3000 milliseconds

}
}
A library file has been called through #include <avr / io.h>, which is used in the program to work using the microcontroller’s input output port.
A library file has been called via #include <ut / delay.h>, which is used in the program to create time intervals with the _delay_ms () function.
Int main (void) {} ​​Since we have written a program using Programming C, so in order to write programs using traditional C, all code has to be included in the main () function. We did the same.

DDRB = 255; Here is the DDRB register for data port for B port. DDRB registers an 8-bit. 255 is given as the value of the DDRB registrar ie 1111 1111 in Binary, in this situation, all the pins output of Port B will be done. If port bit is to be used as some pin input, then all the places should be written as 0, in 1111 0000, pins from PA0 to PA3 will act as input and pins from PA4 to PA7 will act as output.
An infinite loop has been created through while (1) {}, which is conditioned in 1, ie this condition of the loop will remain true as long as our microcontroller works and what is written in this loop will be repeatedly re-cycled.

PORTB = 0b11111111; PORTB is a register used for B port, indicating the output status of that port. PORTB = 0b11111111 If all the ports of PORTB will be logic high, and the pins will be ignited when adding LEDs.

PORTB = 0b00000000; PORTB has all the logic logos of PORTB

_delay_ms (3000); It has been created in 3 seconds time.

 

18 thoughts on “AVR microcontroller basic-2.

  • That is the proper weblog for anyone who needs to search out out about this topic. You understand so much its almost exhausting to argue with you (not that I truly would want匟aHa). You undoubtedly put a brand new spin on a topic thats been written about for years. Great stuff, just nice!

  • I precisely needed to thank you very much again. I do not know the things I could possibly have accomplished without the type of tips and hints discussed by you regarding such industry. It absolutely was an absolute challenging issue in my view, but taking a look at a new skilled mode you solved it took me to leap for delight. I’m happier for your information and hope you really know what a great job you’re undertaking educating people using a blog. I am certain you haven’t met all of us.

  • Hiya! I simply would like to give a huge thumbs up for the great info you might have right here on this post. I might be coming again to your blog for extra soon.

  • It抯 hard to seek out educated individuals on this subject, but you sound like you understand what you抮e talking about! Thanks

  • Thank you for your whole hard work on this web page. My daughter takes pleasure in engaging in research and it is easy to see why. I notice all regarding the dynamic method you produce helpful guides via the web blog and as well as improve participation from other individuals on that area and our favorite princess is undoubtedly becoming educated a great deal. Take advantage of the remaining portion of the year. Your doing a great job.

  • Aw, this was a very nice post. In idea I would like to put in writing like this additionally ?taking time and actual effort to make a very good article?but what can I say?I procrastinate alot and on no account seem to get something done.

  • I and also my buddies came going through the best thoughts found on your web blog then immediately I got an awful suspicion I had not thanked the website owner for those strategies. The guys became for that reason passionate to learn all of them and now have undoubtedly been tapping into those things. Appreciate your getting so accommodating and for picking some wonderful issues most people are really desirous to learn about. Our own honest apologies for not expressing appreciation to you earlier.

  • A powerful share, I just given this onto a colleague who was doing a little analysis on this. And he in truth purchased me breakfast as a result of I discovered it for him.. smile. So let me reword that: Thnx for the deal with! However yeah Thnkx for spending the time to discuss this, I feel strongly about it and love reading more on this topic. If attainable, as you turn into expertise, would you thoughts updating your weblog with extra details? It’s highly helpful for me. Large thumb up for this weblog publish!

  • I have to express my respect for your generosity for folks that actually need guidance on this particular theme. Your very own dedication to getting the solution all-around had been amazingly significant and have all the time empowered some individuals like me to attain their goals. The important guideline signifies this much to me and especially to my peers. Thanks a lot; from each one of us.

  • I would like to get across my passion for your generosity giving support to those people that must have help on this one question. Your real dedication to getting the solution around appeared to be exceptionally useful and has regularly empowered some individuals much like me to attain their targets. The warm and helpful publication denotes so much to me and much more to my fellow workers. Regards; from everyone of us.

  • I simply wished to say thanks again. I am not sure the things that I could possibly have tried without the type of suggestions documented by you directly on such subject matter. It was actually a frustrating crisis in my view, nevertheless finding out this professional way you processed it made me to jump with gladness. I’m happier for this help and even hope that you really know what a powerful job you are always carrying out instructing men and women through your blog. I know that you’ve never come across any of us.

  • I wanted to put you a very little word so as to say thanks a lot over again regarding the great principles you’ve contributed in this case. It is so unbelievably generous of people like you to offer extensively all that some people could have offered for sale as an electronic book to help with making some cash for themselves, chiefly seeing that you might have done it if you decided. The solutions in addition acted to become a great way to be certain that many people have a similar keenness the same as mine to learn more with regard to this problem. I’m sure there are lots of more pleasant opportunities up front for people who read through your site.

  • I must voice my appreciation for your kindness supporting those people that should have help with your matter. Your real commitment to getting the message up and down appeared to be remarkably useful and has truly enabled others just like me to get to their aims. This invaluable guidelines indicates this much a person like me and even further to my peers. Best wishes; from each one of us.

  • I am glad for commenting to let you know what a terrific discovery my friend’s girl went through viewing your web site. She mastered a good number of issues, with the inclusion of what it is like to have an ideal coaching style to make folks without hassle gain knowledge of some very confusing matters. You undoubtedly exceeded readers’ expectations. Thank you for producing the effective, trustworthy, informative and in addition fun tips about that topic to Gloria.

  • There are actually quite a lot of particulars like that to take into consideration. That may be a great point to bring up. I offer the ideas above as basic inspiration however clearly there are questions like the one you deliver up the place a very powerful factor will probably be working in sincere good faith. I don?t know if finest practices have emerged round issues like that, but I am positive that your job is clearly identified as a fair game. Both girls and boys really feel the impact of just a second抯 pleasure, for the remainder of their lives.

  • I simply wanted to post a simple comment to express gratitude to you for some of the precious hints you are showing on this website. My considerable internet lookup has at the end been recognized with excellent suggestions to go over with my good friends. I would express that we site visitors actually are really lucky to live in a notable community with many wonderful individuals with valuable things. I feel quite lucky to have discovered your site and look forward to tons of more enjoyable moments reading here. Thanks a lot again for everything.

Leave a Reply to atlanta falcons jersey Cancel reply

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