Getting Started with Atmel AVR and BASCOM

 by askjerry
instructables26.jpg

I have seen plenty of Instructables showing how to work with microprocessors, but they all assume that you have worked with them before and know what you are doing. I have not seen an Instructable that takes you from nothing and builds on each step.

What we will do here is to start with a bare breadboard and build each connection and each component until we have everything we need to program a microcontroller to do something. In this Instructable we will blink some LEDs in sequence... then if you build this circuit... your first project can be to change the code slightly to make it into a traffic light.

I picked an older Atmel chip, the Tiny-26 to get started. It is a smaller microprocessor, very inexpensive, and easy to understand. Once you understand what we are doing here, you may want to try a more powerful chip like the Mega-328P which has more pins and more memory.

Note: The Tiny-261, Tiny-461, and Tiny-861 are pin compatible newer versions of the Tiny-26. They have 2K, 4K, and 8K of memory. If used, simply change the header by selecting the appropriate chip and recompile the program to use the newer version. The new chips have more functions that can be assigned to each pin. See the datasheets for more details.
Tiny 261, 461, 861 Datasheet (PDF)
Tiny 26 Datasheet (PDF)

Below is an image with the pins for the chip we will be using... we will be connecting the power and ground... in this case 5v. So where do we get 5 volts? We will build a power supply from a 9v battery.

Let's get started!

Video posted in a larger size at: http://www.youtube.com/watch?v=Jxica6Yenh8


 
Remove these adsRemove these ads by Signing Up

Step 1: Breadboards and building circuits.

Below you can see a breadboard... they come in many sizes depending on how complex the circuit you want to build will be. We will use a medium sized breadboard with enough room for our power supply, the microprocessor, and the LEDs we want to control.
Qtechknow says: Sep 17, 2011. 8:57 AM
Which program should c/c++ programmers use for the atmega 328?
askjerry (author) in reply to QtechknowAug 31, 2012. 11:06 AM
You can use the AVR Studio, the current build is Version 5.
http://www.atmel.com/microsite/avr_studio_5/
Qtechknow in reply to askjerrySep 1, 2012. 7:57 AM
Thanks! Is it compatible with Mac OSX?
jamilm9 in reply to QtechknowSep 7, 2012. 9:10 PM
Use Eclipse for Mac
askjerry (author) in reply to QtechknowSep 1, 2012. 8:41 AM
This is the download page: http://www.atmel.com/tools/ATMELSTUDIO.aspx

I did not see anything that referenced Linux nor MAC OS, sorry.
Mic100 says: Jan 19, 2012. 1:00 PM
Good system with the 9Volts Battery
Tanks :)
askjerry (author) in reply to Mic100Jan 19, 2012. 1:27 PM
I have been doing it that way for a very long time. There are other more efficient chips out there... but this uses the least components and is easy for everyone to understand.

Many components today use 3 volts, two AA type batteries provide this (1.5v each) but if you use rechargables they can be 1.2v each or 2.4v total... so you need to watch that. Sometimes I'll use 3 of the AAA rechargables... 3.6v... that seems to work... then use a ZENNER diode to clamp it at 3.0v.

...probably another Instructable!
frank26080115 says: Feb 9, 2011. 7:57 PM
What would you say is the advantage of using BASIC over C?
heatseeker96 in reply to frank26080115Feb 28, 2011. 11:24 AM
It's more easy to learn, use and debug. The problem with basic is that you can't do evrything with it.
askjerry (author) in reply to frank26080115Feb 9, 2011. 8:17 PM
Speaking strictly of the language, it's whatever you are familiar with. From the standpoint of the IDE (programming software) the BASCOM is much easier to install and implement than something like the AVR Studio.

I installed BASCOM, typed in a demo program, hit compile, hit program, and it worked the first time. I installed AVR Studio, took about 40 minutes to configure it, another 20 to figure out how to load the software, then never really did figure out how to compile it, which files needed to be included, etc.

Frankly, I gave up and went back to programming in BASCOM because I knew that I could use it and complete my projects. So far the only C type IDE that even comes close to being easy to understand is the one for the Arduino. (I'm currently learning how to use that now.)

Someone who started off with C may have a different opinion... but I have taught about 350 to 400 people how to program in BASCOM... the youngest was about 7 at the time. So the advantage... easy to set up and learn while still being powerful. If there is enough interest, I'll do another session showing how to make an LCD run. (That's what I did in my BLOG.)
janw in reply to askjerryFeb 13, 2011. 2:21 AM
+1

BASCOM is so userfriendly and very intuïtive. It only takes about 5 minutes to setup the program for your programmer and off you go.

Bascom also makes working with all kinds of different communicationprotocols very easy. I2C, 1wire,.... they have all their set of easy to use commands.
askjerry (author) in reply to janwFeb 13, 2011. 6:04 AM
I know... I have a compass module that uses I2C, all I need to do is use the I2CSEND and I2CRECEIVE commands... very easy. Likely I'll do more tutorials on this as I don't see very many.

Most people go to the Arduino boards... which are okay, but you need to have a pre-programmed Atmel chip. With BASCOM you just get it from the factory and go. Plus... if you make a project that you want to mas produce, you can order the chips pre-programmed from the factory with your HEX code already in them ready to be installed.
frank26080115 in reply to askjerryFeb 9, 2011. 9:12 PM
Ah, I overcome the bad IDE problem by just writing my own
http://code.google.com/p/avr-project-ide/
Now I use NetBeans too

About "which files needed to be included", check out http://www.nongnu.org/avr-libc/user-manual/modules.html
askjerry (author) in reply to frank26080115Feb 9, 2011. 10:23 PM
A bit over my head at the moment... but I'm going to pass the information along to the folks at the robot group and see what they have to say about it.

Austin - http://therobotgroup.org
St Louis - http://robomo.com

Thanks,
Jerry
janw says: Feb 13, 2011. 2:27 AM
Great instructable!
AgeingHippy says: Feb 9, 2011. 5:59 AM
Hi Jerry

Nice and clear. Thanks.

I am wondering though, PB0-PB7 can only all be input or all be output?

I have a little (very little) experiance with arduino and my inderstanding was that one can define a pin (as apposed to a port = 8 pins) to input or output.

Is this perhaps a diferent type of chip or is defining the port as input /output a shortcut for defining all 8 pins seperately?

Also, what might be usefull would be a circuit diagram to match to your boards.

Thanks
askjerry (author) in reply to AgeingHippyFeb 9, 2011. 9:27 AM
Any pin can be an input or an output. Different chips in the series can also have pins assigned as analog inputs instead of just digital 1 or 0. If you look at the pin connections for this chip, you can see that PORTA has other functions (ADC0 through ADC6) which are analog to digital converters.

I set the whole port for simplicity, but I could have used DDRA and DDRB to configure each pin.

DDRB =&B00000111

"0" is an input, and "1" is an output... in our example "&B00000111" will set PORTB.0, PORTB.1, and PORTB.2 to OUTPUTS, (right to left) the remainder being INPUTS.

Video added... drawing in the works now.

The Arduino is built using an Atmel AVR, but they have loaded software (a bootloader) into the chip already. This defines certain pins and functions for you. We are going a step above that... we are taking a raw chip and programming and defining it the way we want to.
AgeingHippy in reply to AgeingHippyFeb 9, 2011. 6:02 AM
Sorry - also wanted to ask more.

Does the chip already have a bootloader on it when programming it with BASCOM or does it not need one?
askjerry (author) in reply to AgeingHippyFeb 9, 2011. 9:29 AM
No bootloader is needed. We are programming directly into the chip as it comes from the factory. In fact, we could actually load the bootloader HEX file into the proper chip and make our own Arduino chips. (But I prefer to have more control over how each pin and function is used.)
AgeingHippy in reply to askjerryFeb 9, 2011. 10:12 AM
Great.

Thanks for your informative replies :)
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!