old-www/HOWTO/html_single/Avr-Microcontrollers-in-Lin.../index.html

1297 lines
20 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Avr-Microcontrollers-in-Linux-Howto</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"></HEAD
><BODY
CLASS="article"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="ARTICLE"
><DIV
CLASS="TITLEPAGE"
><H1
CLASS="title"
><A
NAME="AEN2"
></A
>Avr-Microcontrollers-in-Linux-Howto</H1
><DIV
CLASS="revhistory"
><TABLE
WIDTH="100%"
BORDER="0"
><TR
><TH
ALIGN="LEFT"
VALIGN="TOP"
COLSPAN="3"
><B
>Revision History</B
></TH
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 44</TD
><TD
ALIGN="LEFT"
>2009-04-20 17:13:07</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>obfuscate e-mail at the author demand</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 43</TD
><TD
ALIGN="LEFT"
>2009-03-29 20:49:12</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 42</TD
><TD
ALIGN="LEFT"
>2009-03-29 20:45:09</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>reverting after publication</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 41</TD
><TD
ALIGN="LEFT"
>2009-03-29 20:41:59</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>edit to export docbook</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 40</TD
><TD
ALIGN="LEFT"
>2009-03-28 21:07:57</TD
><TD
ALIGN="LEFT"
>Revised by: RickMoen</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Adjust style of mailto link to author's original preference.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 39</TD
><TD
ALIGN="LEFT"
>2009-03-28 21:05:45</TD
><TD
ALIGN="LEFT"
>Revised by: RickMoen</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Revert e-mail obfuscation, supply some missing punctuation, [re-]fix capitalisation, fix and clarify new run-on sentence.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 38</TD
><TD
ALIGN="LEFT"
>2009-03-23 18:21:24</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 37</TD
><TD
ALIGN="LEFT"
>2009-03-23 18:19:51</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 36</TD
><TD
ALIGN="LEFT"
>2009-03-23 17:20:32</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 35</TD
><TD
ALIGN="LEFT"
>2009-03-23 17:19:47</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 34</TD
><TD
ALIGN="LEFT"
>2009-03-23 10:26:00</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>publishing tests</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 33</TD
><TD
ALIGN="LEFT"
>2009-03-23 10:25:06</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 32</TD
><TD
ALIGN="LEFT"
>2009-03-23 10:24:24</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>use of macro to obfuscate e-mail</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 31</TD
><TD
ALIGN="LEFT"
>2009-03-23 10:11:47</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>change was only to export docbook without admonitions</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 30</TD
><TD
ALIGN="LEFT"
>2009-03-23 10:09:15</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 29</TD
><TD
ALIGN="LEFT"
>2009-03-23 10:05:07</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 28</TD
><TD
ALIGN="LEFT"
>2009-03-23 09:58:40</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>adding the wiki as link</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 27</TD
><TD
ALIGN="LEFT"
>2009-03-23 09:53:28</TD
><TD
ALIGN="LEFT"
>Revised by: RickMoen</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Insert needed space characters into "pin9", "pin10", "pin25" constructs</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 26</TD
><TD
ALIGN="LEFT"
>2009-03-23 09:49:05</TD
><TD
ALIGN="LEFT"
>Revised by: RickMoen</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Make markup of all the software items mentioned be consistent</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 25</TD
><TD
ALIGN="LEFT"
>2009-03-23 09:43:40</TD
><TD
ALIGN="LEFT"
>Revised by: RickMoen</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Remove a couple of stray commas.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 24</TD
><TD
ALIGN="LEFT"
>2009-03-23 09:41:30</TD
><TD
ALIGN="LEFT"
>Revised by: RickMoen</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Polishing up a few last bits of punctuation</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 23</TD
><TD
ALIGN="LEFT"
>2009-03-23 04:11:31</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 22</TD
><TD
ALIGN="LEFT"
>2009-03-23 04:10:34</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 21</TD
><TD
ALIGN="LEFT"
>2009-03-23 04:09:07</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 20</TD
><TD
ALIGN="LEFT"
>2009-03-17 16:20:27</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 19</TD
><TD
ALIGN="LEFT"
>2009-03-17 16:18:33</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 18</TD
><TD
ALIGN="LEFT"
>2009-03-16 19:10:30</TD
><TD
ALIGN="LEFT"
>Revised by: RickMoen</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Fix hyperlink, fix English diction of new sentence.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 17</TD
><TD
ALIGN="LEFT"
>2009-03-16 18:50:19</TD
><TD
ALIGN="LEFT"
>Revised by: ranjeeth</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 16</TD
><TD
ALIGN="LEFT"
>2009-03-16 11:36:49</TD
><TD
ALIGN="LEFT"
>Revised by: RickMoen</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>A couple of punctuation nits</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 15</TD
><TD
ALIGN="LEFT"
>2009-03-16 11:21:14</TD
><TD
ALIGN="LEFT"
>Revised by: RickMoen</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Corrected numerous run-on sentences, punctuation and grammar errors, and questionable idiom.</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 14</TD
><TD
ALIGN="LEFT"
>2009-03-15 10:27:24</TD
><TD
ALIGN="LEFT"
>Revised by: BordenRhodes</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Cleaned up basic grammar and spelling</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 13</TD
><TD
ALIGN="LEFT"
>2009-03-15 09:52:41</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 12</TD
><TD
ALIGN="LEFT"
>2009-03-15 09:51:37</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>add link to the manual of avr-libc</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 11</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:47:18</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>end of basic conversion</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 10</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:40:18</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 9</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:39:26</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 8</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:33:04</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>add the image</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 7</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:27:59</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 6</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:26:48</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 5</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:25:13</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
>Firts step - conversion fro html by jdd and basic format edition</TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 4</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:22:37</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 3</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:18:25</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 2</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:13:09</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
><TR
><TD
ALIGN="LEFT"
>Revision 1</TD
><TD
ALIGN="LEFT"
>2009-03-14 21:10:33</TD
><TD
ALIGN="LEFT"
>Revised by: jdd</TD
></TR
><TR
><TD
ALIGN="LEFT"
COLSPAN="3"
></TD
></TR
></TABLE
></DIV
><HR></DIV
><DIV
CLASS="TOC"
><DL
><DT
><B
>Table of Contents</B
></DT
><DT
>1. <A
HREF="#AEN202"
>HOWTO</A
></DT
><DT
>2. <A
HREF="#AEN207"
>AVR Microcontrollers in Linux HOWTO</A
></DT
><DD
><DL
><DT
>2.1. <A
HREF="#AEN209"
>Licence</A
></DT
><DT
>2.2. <A
HREF="#AEN214"
>What Is a Microcontroller?</A
></DT
><DT
>2.3. <A
HREF="#AEN217"
>Software Required</A
></DT
><DT
>2.4. <A
HREF="#AEN249"
>Hello World</A
></DT
><DT
>2.5. <A
HREF="#AEN309"
>Author</A
></DT
><DT
>2.6. <A
HREF="#AEN317"
>Last version</A
></DT
></DL
></DD
></DL
></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="AEN202"
></A
>1. HOWTO</H1
><P
><STRONG
>AVR Microcontrollers in Linux HOWTO</STRONG
>, Copyright (C) 2009 Ranjeeth p t (ranjeeth_gecmail[at]yahoo[dot]com) </P
><P
>This HOWTO is for readers wishing to program an AVR microcontroller using a GNU/Linux machine. For burning your code, we will be using a parallel port. You may need other electronics components (like a few resistors, capacitors, parallel port connector, etc.), which can be bought from any electronics shop. </P
></DIV
><DIV
CLASS="section"
><HR><H1
CLASS="section"
><A
NAME="AEN207"
></A
>2. AVR Microcontrollers in Linux HOWTO</H1
><DIV
CLASS="section"
><H2
CLASS="section"
><A
NAME="AEN209"
></A
>2.1. Licence</H2
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
> Permission is granted to copy, distribute, and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.2, or any later version published by the Free Software
Foundation; with no Invariant Sections, no Front-Cover Texts, and
no Back-Cover Texts. A copy of the license is included in the
section entitled "GNU Free Documentation License".</PRE
></FONT
></TD
></TR
></TABLE
><P
><A
HREF="http://wiki.tldp.org/LdpWikiDefaultLicence#GNUFreeDocumentationLicense"
TARGET="_top"
>GNU Free Documentation License</A
> </P
></DIV
><DIV
CLASS="section"
><HR><H2
CLASS="section"
><A
NAME="AEN214"
></A
>2.2. What Is a Microcontroller?</H2
><P
>A microcontroller is a single-chip computer. It has internal RAM, ROM, timers, counters, interrupt circuitry, I/O ports, analog comparators, serial USARTs, analog to digital converters, watchdog timers, and a RISC architecture. When you are using a microprocessor, you cannot program it alone. You need other components, like RAM, ROM, timers, etc. For programming, you should know its architecture thoroughly: You must read the datasheet for your microcontroller. </P
></DIV
><DIV
CLASS="section"
><HR><H2
CLASS="section"
><A
NAME="AEN217"
></A
>2.3. Software Required</H2
><P
><STRONG
>binutils:</STRONG
> Tools like the assembler, linker, etc. </P
><P
><STRONG
>gcc-avr:</STRONG
> The GNU C compiler (cross-compiler for avr). </P
><P
><STRONG
>avr-libc:</STRONG
> Package for the AVR C library, containing many utility functions. </P
><P
><STRONG
>uisp:</STRONG
> A Micro In-System Programmer for Atmel's AVR MCUs (for burning code to MCUs' memory). </P
><P
>The following Atmel microcontrollers are supported by avr-gcc in Linux: </P
><P
><STRONG
>at90s Type Devices</STRONG
> </P
><P
>at90s2313, at90s2323, at90s2333, at90s2343, at90s4414, at90s4433, at90s4434, at90s8515, at90s8515, at90s8515, at90s8535, at90s1200. </P
><P
><STRONG
>atmega Type Devices</STRONG
> </P
><P
>atmega103, atmega603, atmega8, atmega48, atmega88, atmega8515, atmega8535, atmega16, atmega161, atmega162, atmega163, atmega165, atmega168, atmega169, atmega32, atmega323, atmega325, atmega3250, atmega64, atmega645, atmega6450, atmega128. </P
><P
><STRONG
>attiny Type Devices</STRONG
> </P
><P
>attiny22, attiny26, attiny26, attiny13, attiny13, attiny13, attiny13, attiny2313, attiny11, attiny12, attiny15, attiny28. </P
><P
><STRONG
>Other AVR Devices</STRONG
> </P
><P
>avr2, at90c8534, at86rf401, avr3, at43usb320, at43usb355, at76c711, avr4, avr5, at90can128, at94k, avr1. </P
><P
><STRONG
>binutils:</STRONG
> Programs to manipulate binary and object files that may have been created for Atmel's AVR architecture. This package is primarily for AVR developers and cross-compilers. </P
><P
><STRONG
>gcc-avr:</STRONG
> The GNU C compiler, a fairly portable optimising compiler that supports multiple languages. This package includes C language support. </P
><P
><STRONG
>avr-libc:</STRONG
> Standard library used for developing C programs for Atmel AVR microcontrollers. This package contains static libraries, as well as needed header files. </P
><P
><STRONG
>uisp:</STRONG
> Utility to program AVR chips with object code created by gcc-avr. It supports in-system programming. </P
><P
>You download the above packages untar, configure, and install it. If you are using Debian or Ubuntu, these packages are available in your distribution: Install them using apt or synaptic package manager. </P
></DIV
><DIV
CLASS="section"
><HR><H2
CLASS="section"
><A
NAME="AEN249"
></A
>2.4. Hello World</H2
><P
>We are writing <STRONG
>hello world</STRONG
> for the atmega8 microcontroller, which has a 28-pin, 8-bit, RISC architecture. </P
><P
>Before proceeding, have a look at <A
HREF="http://www.nongnu.org/avr-libc/user-manual/"
TARGET="_top"
>this manual about __avr-libc__</A
>, which will help you program better, and understand. Also, refer to the datasheets for the various AVR microcontrollers. </P
><P
>Here is our first program: </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>/* ledblink.c, an LED blinking program */
#include&#60;avr/io.h&#62;
#include&#60;util/delay.h&#62;
void sleep(uint8_t millisec)
{
while(millisec)
{
_delay_ms(1);/* 1 ms delay */
millisec--;
}
}
main()
{
DDRC |=1&#60;&#60;PC2; /* PC2 will now be the output pin */
while(1)
{
PORTC &#38;= ~(1&#60;&#60;PC2);/* PC2 LOW */
sleep(100);/* 100 ms delay */
PORTC |=(1&#60;&#60;PC2); /* PC2 HIGH */
sleep(100);/* 100 ms delay */
}
}</PRE
></FONT
></TD
></TR
></TABLE
><DIV
CLASS="section"
><HR><H3
CLASS="section"
><A
NAME="AEN257"
></A
>2.4.1. Code Explanation</H3
><P
>The GNU C compiler for the Atmel family identifies all functional units within the microcontroller with meaningful names. Thus, writing `PORTC=0xff' will result in the compiler generating machine code that writes 0xff to I/O port C, which will set all port C pins to logic high. Because ports are bidirectional, we must decide whether each pin should act as input or output. If the i'th bit of a register called DDRC (data direction register C) is 1, then the i'th pin of PORTC's i'th pin will be an output. Otherwise, it will act as an input pin. (Note that pin and bit numbers start at zero.) To make an LED blink, you have to make a pin high, then low. (Here, we use PORTC's 2<SUP
>nd</SUP
> port. That is, PC2 will be the 25<SUP
>th</SUP
> pin.) There should be a delay between the two. This is what the rest of the code does. For the delay, we use built-in function <EM
>_delay_ms(1)</EM
>, which causes a 1 ms delay. </P
></DIV
><DIV
CLASS="section"
><HR><H3
CLASS="section"
><A
NAME="AEN263"
></A
>2.4.2. Compilation</H3
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>avr-gcc -mmcu=atmega8 Os ledblink.c o ledblink.o</PRE
></FONT
></TD
></TR
></TABLE
><P
>which will result in object file ledblink.o. Now, we will covert it to hex file, suitable for burning to the microcontroller's memory. </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>avr-objcopy -j .text -j .data -O ihex ledblink.o ledblink.hex</PRE
></FONT
></TD
></TR
></TABLE
><P
>We are converting it to a hex file because, for burning the code to atmega8, we will use uisp, whose input file must be a .hex file. </P
><P
>Notice that you can <EM
>less</EM
> the ledblink.hex file. </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>:1000000012C02BC02AC029C028C027C026C025C0C6
:1000100024C023C022C021C020C01FC01EC01DC0DC
:100020001CC01BC01AC011241FBECFE5D4E0DEBF28
:10003000CDBF10E0A0E6B0E0EAE8F0E002C0059035
:100040000D92A036B107D9F710E0A0E6B0E001C0EC
:100050001D92A036B107E1F70CC0D2CF282FE4ECF7
:10006000F9E004C0CF010197F1F721502223D1F725
:100070000895CFE5D4E0DEBFCDBFA29AAA9884E66A
:0A008000EDDFAA9A84E6EADFF9CF6B
:00000001FF</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="section"
><HR><H3
CLASS="section"
><A
NAME="AEN272"
></A
>2.4.3. Burning the Code</H3
><DIV
CLASS="section"
><H4
CLASS="section"
><A
NAME="AEN274"
></A
>2.4.3.1. Hardware</H4
><P
>We will be using the parallel port for burning. First, we have to develop a burning circuit for it. </P
><P
><SPAN
CLASS="inlinemediaobject"
><IMG
SRC="avr_html_m7e400112-2.jpg"></SPAN
> </P
><P
>This is the circuit for the atmega8 microcontroller. Pin 9 &#38; pin 10 are connected by a 4 MHz crystal oscillator, which is the external clock. The bottom right connector is for a parallel port. </P
><P
>If you are using any other microcontroller, as mentioned above, you should change accordingly. }}} </P
><P
>You should watch for <EM
>RESET,XTAL1,XTAL2,SCK,MISO,MOSI pins</EM
>, <EM
> </EM
>and connect.<EM
> </EM
> </P
></DIV
><DIV
CLASS="section"
><HR><H4
CLASS="section"
><A
NAME="AEN289"
></A
>2.4.3.2. Software</H4
><P
>Now, we will burn ledblink.hex to the microcontroller. </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>uisp -dprog=dapa -dlpt=0x378</PRE
></FONT
></TD
></TR
></TABLE
><P
>You should get message <EM
>Atmega8 Found</EM
>. </P
><P
><EM
><EM
>dprog</EM
></EM
> is the programming method specifier, which in this case is <EM
>dapa</EM
>, i.e., Direct AVR Parallel Access. <EM
><EM
>dlpt</EM
></EM
> is for the parallel device setting, which is 0x378, the parallel port's device address. </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>uisp -dprog=dapa -dlpt=0x378 --erase</PRE
></FONT
></TD
></TR
></TABLE
><P
>Will erase the microcontroller's code. </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
>uisp -dprog=dapa -dlpt=0x378 --upload if=ledblink.hex</PRE
></FONT
></TD
></TR
></TABLE
><P
>Will <EM
>upload</EM
> the <EM
>I</EM
>nput <EM
>F</EM
>ile ledblink.hex </P
><P
>Notice that you can see the LED at pin 25 blinking. </P
></DIV
></DIV
></DIV
><DIV
CLASS="section"
><HR><H2
CLASS="section"
><A
NAME="AEN309"
></A
>2.5. Author</H2
><P
>Comments to: <A
HREF="mailto:ranjeeth_gecmail[at]yahoo[dot]com"
TARGET="_top"
>mailto:ranjeeth_gecmail[at]yahoo[dot]com</A
> </P
><P
><A
HREF="http://ranjeethpt.wordpress.com"
TARGET="_top"
>Ranjeeth Weblog</A
> </P
><P
>Govt Engg College Sreekrishnapuram, </P
><P
>Palakkad,Kerala India. </P
></DIV
><DIV
CLASS="section"
><HR><H2
CLASS="section"
><A
NAME="AEN317"
></A
>2.6. Last version</H2
><P
>You may find the last up-to-date version of this HOWTO <A
HREF="http://wiki.tldp.org/Avr-Microcontrollers-in-Linux-Howto"
TARGET="_top"
>on the LDP wiki</A
>. </P
></DIV
></DIV
></DIV
></BODY
></HTML
>