Example: stock market

Tuxgraphics AVR C-programming tutorial

AVR C-programming tutorialAbstract:This is an in introduction to programming of AVR microcontrollers using C as alanguage. The avr-gcc was originally developed for Unix systems. Today it isavailable for almost any system and very widely used. This article will therefore alsocover Windows. The setup on a Mac is almost identical to _____ _____Hardware becomes softwareComputers become smaller and more powerful. This has lead to an ongoing revolutionin the world of analog and digital electronics. Not so long ago we were buildingcircuits with dozens of TTL chips and many analog circuits don't look like that anymore. They have just a few analog or digitalcomponents at the input or output ( an amplifier) and then there is one chip withmany pins.

Tuxgraphics AVR C-programming tutorial Abstract: This is an in introduction to programming of AVR microcontrollers using C as a language.

Tags:

  Programming, Language, Tutorials, Programming tutorial

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Tuxgraphics AVR C-programming tutorial

1 AVR C-programming tutorialAbstract:This is an in introduction to programming of AVR microcontrollers using C as alanguage. The avr-gcc was originally developed for Unix systems. Today it isavailable for almost any system and very widely used. This article will therefore alsocover Windows. The setup on a Mac is almost identical to _____ _____Hardware becomes softwareComputers become smaller and more powerful. This has lead to an ongoing revolutionin the world of analog and digital electronics. Not so long ago we were buildingcircuits with dozens of TTL chips and many analog circuits don't look like that anymore. They have just a few analog or digitalcomponents at the input or output ( an amplifier) and then there is one chip withmany pins.

2 Those chips are however not application specific ICs. Those are usuallygeneric microcontrollers. More and more components are just replaced by analgorithm and that algorithm runs probably inside a are at the heart of this electronic revolution. It is a very excitingrevolution and it is fun to play with those microcontrollers. Come and have a look! What are Microcontrollers?A microcontroller is a small single chip computer. It has CPU, Ram and permanentdata storage on one small chip. They als have build-in counters and analog to digitalconverters (ADCs) on chip. This makes it possible to replace analog circuits with amicrocontroller and some software. What are AVR microcontrollers?

3 AVR microcontrollers are named after two Norvegian students (Alf-Egil Bogen andVegard Wollan) who invented them. AVR stands for Alf and Vegard's Risc the AVR microcontrollers are produced by Atmel ( ), a US company. This AVR architecture makes it quite easyto program the chip in C. The avr-gcc development environment is available as freesoftware. Learning by doing is probably the best way to learn. So let's start with astraight forward and easy to understand circuit. Let's start with a simple circuitYou might have heard about Astable Multivibrators. It's an analog circuit that can beused to get a LED to blink. Let's replace it by a microcontroller. It's the "hello worldprogram" equivalent in the microcontroller world.

4 To replace an Astable Multivibratoris of course not a big advantage because the complexity of an Astable Multivibrator isnot much higher than the equivalent microcontroller circuit but the microcontrollercircuit can easily be extended with more LEDs. You can easily get all those LEDs toflash in different patterns, something that would be difficult and complex with ananalog LED circuit, click for a PDF versionYou can build this circuit on a dot-matrix board or even a breadboard. AVRmicrocontrollers have a built in clock. They don't necessarily need an external can be used for most microcontroller circuits that do not require anexternal the microcontrollerProgramming involves basically 3 steps.

5 Writing the software (1). Compiling it(2) intomachine loadable format and loading it (3) into the microcontroller. The software forour test circuit is already written. Therefore let's first focus on how to get it into themicrocontroller and later we discuss how to write programmer is needed to program a microcontroller that comes fresh from thefactory. This programmer consists of both software and hardware. The hardwareinterconnects your PC with the microcontroller. The programmer software that wewill use is called avrdude and it is available for Linux, Mac and Windows. It is acommand line controlled programmer but if you prefer mouse clicks then you can justwrite a script (batch file) and include the command there.

6 Double click on the batchfile and the programmer loads the software into the you have a PC which still has a parallel port and runs Linux then you can just buildyour own programmer out of a simple cable and three protection onpcbpin onAVRprotectionresistorPin onparallel port5 Reset(1)--Init (16)4 MOSI(17)220 OhmD0 (2)3 MISO(18)220 OhmBusy (11)2 SCK(19)220 OhmStrobe (1)1 GND--GND (18)The cable should not be longer than programmer has the limitation that you can use it only on circuits which run with5V but otherwise it is fully functional. The option in avrdude that let's avrdude knowthat you will use this type of programmer is called "-c dapa". The full command line toload software ( ) into an atmega8 chip with this parallel portprogrammer would be:avrdude -p m8 -c dapa -P /dev/parport0 -e -U flash: people would probably like to use something that works with any operatingsystem, connects via USB and works also with circuits that run not on 5V.

7 Manymicrocontroller circuits run on The Tuxgraphics avrusb500 is such aprogrammer. The command line option to let avrdude know that you will use this typeof programmer is called "-c stk500v2" and you have to specify with the option "-P"which is the equivalent com-port (or device in /dev for Mac and Linux). It's very easyand there will be more details further have now discussed the programmer hardware and I mentioned already that thereis a programmer software called avrdude. Both hardware and software work togetherto get the code into the to install C-compiler and this programmer software is described in the articleBuilding your own avr-gcc environment with atmega328p capabilities, Linux.

8 Thisarticle has also a section at the end for Windows and Mac. Ready to use packages areavailable for Windows and Mac. It's just a matter of downloading and installing the avrledtest software at the end of this up the circuit with the atmega8 (Interestingly many people tend to forget circuits that work without electricity are not invented yet ;-).Unpack the avrledtest file and go into the directory that was created during theunpacking. From there you issue the command:Linux (Mac is similar):avrdude -p m8 -c stk500v2 -P /dev/ttyUSB0 -e -U flash: :avrdude -p m8 -c stk500v2 -P COM4 -e -U flash: would be the equivalent comport emulated via USB. You get this informationfrom the hardware device manager under and Linux will tell you in the kernel messages what devices to use when you plugin the avrusb500 into the usb port.

9 To find the right /dev device after the avrusb500was just plugged in you run the command dmesg and you see the kernel use Linux and I prefer the command line as it is faster but I understand that theWindows dos shell is a different story. To not type the command every time and dothis with a mouse click you can write a script (batch file):@echo -------- begin --------set PATH=c:\avrgcc\bin;c:\avrgcc\utils\binRE M change the com-port as needed:set CHIP=m8avrdude -p %CHIP% -c stk500v2 -P COM4 -e -U flash: @echo -------- end --------pauseYou can also include the device name into the file and then you do nothave to specify it on the command line. Look for an option called "default_serial".

10 Of course it does not harm to use a script under Mac or Linux if you like. You couldalso include the command in a makefile (we get to that later).#!/bin/sh -x# script to load code into a atmega8 (for Linux and Mac)#chip=m8avrdude -p $chip -c stk500v2 -P /dev/ttyUSB0 -e -U flash: # if you want to start it by double click in the file manager# then uncomment the following line to keep the window open until# you hit return:# readDuring the loading of the software with avrdude you will see a printout like this:avrdude -p m8 -c stk500v2 -e -U flash: : AVR device initialized and ready to accept instructionsReading | ######################################## ########## | 100% : Device signature = 0x1e9307avrdude: erasing chipavrdude: reading input file " "avrdude: input file auto detected as Intel Hexavrdude.


Related search queries