<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Introductory Tutorial</title><link>https://sourceforge.net/p/avr-ada/wiki/Introductory%2520Tutorial/</link><description>Recent changes to Introductory Tutorial</description><atom:link href="https://sourceforge.net/p/avr-ada/wiki/Introductory%20Tutorial/feed" rel="self"/><language>en</language><lastBuildDate>Wed, 22 Aug 2012 07:28:43 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/avr-ada/wiki/Introductory%20Tutorial/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage Introductory Tutorial modified by Rolf Ebert</title><link>https://sourceforge.net/p/avr-ada/wiki/Introductory%2520Tutorial/</link><description>&lt;pre&gt;--- v7
+++ v8
@@ -10,7 +10,7 @@
 ##Prerequisites##
 You need the following hard- and software to write and run your own Ada programs on AVR micros:
 
-[[img src=Butterfly.jpg width=200]]
+[[img src=Butterfly.jpg width=200 style="float:right"]]
 
 * A PCB or breadboard carrying an AVR. Again see AVRFreaks for suggestions of prototyping and development kits. Personally I use the [AVR Butterfly](http://www.atmel.com/products/AVR/butterfly) as it is cheap (&lt; 25€) and has a lot of peripherals. A standard development board is the STK500 from Atmel. Recently the Arduinos became quite popular. You can also solder your own PCB or put the controller directly on a breadboard.
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rolf Ebert</dc:creator><pubDate>Wed, 22 Aug 2012 07:28:43 -0000</pubDate><guid>https://sourceforge.net81756ba9b56c4cbc69d274b84984182444436d2c</guid></item><item><title>WikiPage Introductory Tutorial modified by Rolf Ebert</title><link>https://sourceforge.net/p/avr-ada/wiki/Introductory%2520Tutorial/</link><description>&lt;pre&gt;--- v6
+++ v7
@@ -10,11 +10,11 @@
 ##Prerequisites##
 You need the following hard- and software to write and run your own Ada programs on AVR micros:
 
-[[img src=Butterfly.jpg]]
+[[img src=Butterfly.jpg width=200]]
 
 * A PCB or breadboard carrying an AVR. Again see AVRFreaks for suggestions of prototyping and development kits. Personally I use the [AVR Butterfly](http://www.atmel.com/products/AVR/butterfly) as it is cheap (&lt; 25€) and has a lot of peripherals. A standard development board is the STK500 from Atmel. Recently the Arduinos became quite popular. You can also solder your own PCB or put the controller directly on a breadboard.
 
-[[img src=Arduino.jpg]]
+[[img src=Arduino.jpg width=200]]
 
 * AVR-gcc compiler including avr-libc, AVR-Ada, and the avr-binutils. If you run MS-Windows I strongly recommend to get the latest WinAVR distribution. It has all the necessary tools nicely packaged. Some Linux distros also provide AVR development tools (Ubuntu, Suse). They probably do not contain the latest bug fixes and patches. I therefore recommend to build your own tool-chain using our build script "build-avr-ada.sh". It completely automates the download of all source packages and the latest patches and it builds and installs everything.
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rolf Ebert</dc:creator><pubDate>Wed, 22 Aug 2012 07:05:31 -0000</pubDate><guid>https://sourceforge.net8bd60088330528b3967a69e45a5d7cf637080489</guid></item><item><title>WikiPage Introductory Tutorial modified by Rolf Ebert</title><link>https://sourceforge.net/p/avr-ada/wiki/Introductory%2520Tutorial/</link><description>&lt;pre&gt;--- v5
+++ v6
@@ -10,11 +10,11 @@
 ##Prerequisites##
 You need the following hard- and software to write and run your own Ada programs on AVR micros:
 
-[img src=Butterfly.jpg]
+[[img src=Butterfly.jpg]]
 
 * A PCB or breadboard carrying an AVR. Again see AVRFreaks for suggestions of prototyping and development kits. Personally I use the [AVR Butterfly](http://www.atmel.com/products/AVR/butterfly) as it is cheap (&lt; 25€) and has a lot of peripherals. A standard development board is the STK500 from Atmel. Recently the Arduinos became quite popular. You can also solder your own PCB or put the controller directly on a breadboard.
 
-[img src=Arduino.jpg]
+[[img src=Arduino.jpg]]
 
 * AVR-gcc compiler including avr-libc, AVR-Ada, and the avr-binutils. If you run MS-Windows I strongly recommend to get the latest WinAVR distribution. It has all the necessary tools nicely packaged. Some Linux distros also provide AVR development tools (Ubuntu, Suse). They probably do not contain the latest bug fixes and patches. I therefore recommend to build your own tool-chain using our build script "build-avr-ada.sh". It completely automates the download of all source packages and the latest patches and it builds and installs everything.
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rolf Ebert</dc:creator><pubDate>Wed, 22 Aug 2012 07:02:45 -0000</pubDate><guid>https://sourceforge.netc841cceaae7550f907a9aa68aa3a0c9682ccb154</guid></item><item><title>WikiPage Introductory Tutorial modified by Rolf Ebert</title><link>https://sourceforge.net/p/avr-ada/wiki/Introductory%2520Tutorial/</link><description>&lt;pre&gt;--- v4
+++ v5
@@ -16,7 +16,7 @@
 
 [img src=Arduino.jpg]
 
-* AVR-gcc compiler including avr-libc, AVR-Ada, and the avr-binutils. If you run MS-Windows I strongly recommend to get the latest WinAVR distribution. It has all the necessary tools nicely packaged. Some Linux distros also provide AVR development tools (Ubuntu, Suse). They probably do not contain the latest bug fixes and patches. I therefore recommend to build your own tool-chain using our build script "build-avr-ada-gcc-4.3.x.sh". It completely automates the download of all source packages and the latest patches and it inbuilds and installs everything.
+* AVR-gcc compiler including avr-libc, AVR-Ada, and the avr-binutils. If you run MS-Windows I strongly recommend to get the latest WinAVR distribution. It has all the necessary tools nicely packaged. Some Linux distros also provide AVR development tools (Ubuntu, Suse). They probably do not contain the latest bug fixes and patches. I therefore recommend to build your own tool-chain using our build script "build-avr-ada.sh". It completely automates the download of all source packages and the latest patches and it builds and installs everything.
 
 * A programming device and corresponding software. If you use an AVR-Butterfly or the popular Arduino hardware you only need a serial or USB cable. For all other development kits you need something like PonyProg or AVRDUDE. Atmel's STK500 also works very well (you'll need their AVR-Studio on MS-Windows).
 
@@ -60,25 +60,19 @@
 We also need a GNAT project file (GPR) that contains all the Ada specific settings and a list of required source files.  Create a file called &lt;code&gt;build.gpr&lt;/code&gt;.
 
     :::Ada
-    with "avr.gpr";                         -- 1: enable access to the standard AVR library
-    project Build is                        -- 2: the name of the project has to match the file name
+                                            -- 1: enable access to the standard AVR library by extending
+    project Build extends "avr_app.gpr" is  -- 2: the name of the project has to match the file name
 
        for Main use ("led_on");             -- 4: the name of the main program
 
-       for Languages use ("Ada");           -- 6: of course, we program in Ada
-       for Object_Dir use "obj";            -- 7: hide the generated file in a subdir
-       for Exec_Dir use ".";                -- 8: keep the main files in the current directory
+       for Object_Dir use "obj";            -- 6: hide the generated files in a subdir
+       for Exec_Dir use ".";                -- 7: keep the main files in the current directory
 
-       package Builder renames AVR.Builder; -- 10: apply the standard settings
-       package Compiler renames AVR.Compiler;
-       package Binder renames AVR.Binder;
-       package Linker renames AVR.Linker;
-
-       for Source_Files use ("led_on.adb"); -- 15: the list of required source files
+       for Source_Files use ("led_on.adb"); -- 9: the list of required source files
 
     end Build;
 
-At the end we also need a Makefiles that glues all the commands together. Copy the Makefile from the exampels of your AVR-Ada installation. There are some parameters that have to be set in the Makefile.
+At the end we also need a Makefile that glues all the commands together. Copy the Makefile from the exampels of your AVR-Ada installation. There are some parameters that have to be set in the Makefile.
 
 * MCU, the name of the processor, that is atmega8 here
 * ADA_TARGETS, the name of the main program, led_on
@@ -92,7 +86,7 @@
 
 and you will see a bunch of commands and their respective output coming by.  The last command will display the use of the different memory sections and the percentage of free space.
 
-Your program is now stored in a file named "led_on.elf". This file has to be transfered to your micro-controler.  the exact handling depends on your hardware equipment. We assume an ISP-programmer like the mkII or the STK-500 driven by avrdude. Review the settings in your Makefile: you have to specify the port that you use, e.g. com4, and the type of the programmer, e.g. stk500v2.  Read the help output of avrdude to see what other options are available.
+Your program is now stored in a file named "led_on.elf". This file has to be transfered to your micro-controler.  The exact handling depends on your hardware equipment. We assume an ISP-programmer like the mkII or the STK-500 driven by avrdude. Review the settings in your Makefile: you have to specify the port that you use, e.g. com4, and the type of the programmer, e.g. stk500v2.  Read the help output of avrdude to see what other options are available.
 
 ## Accessing Registers ##
 
@@ -150,3 +144,27 @@
 
 
 See also the page about [SimpleIO].
+
+##Specify AVR Device##
+
+Atmel has released more than 50 different AVR micrcontrollers in different memory sizes, different internal capabilities, different instrunctions, etc. The user has to provide this information to the compiler to refer to the correct ports and to make use of the correct instruction set. The standard way of providing this information is by setting the option `-mmcu=`.
+
+    avr-gcc -c -mmcu=atmega328p ...
+
+If you want to refer to the symbolic names of the different ports and registers in your Ada code, you have to "with" the corresponding package specification. You also have to "use" it depending on your programming style.
+
+    :::Ada
+    with AVR.ATMEGA328p; use AVR.ATMEGA328p;
+
+When you write potentially reusable packages, you want to stay independant of a specific MCU. Otherwise the users have to change the with and use clauses in all files that they use. The preferred programming style in this case is to refer to `AVR.MCU` in your application code.
+
+    :::Ada
+    with AVR.MCU; use AVR.MCU;
+
+A corresponding file was automatically created in the AVR library directory of your device at the installation. It contains a renaming of the part specific definitions of the used MCU.
+
+    :::Ada
+    with AVR.ATMEGA328P;
+    package AVR.MCU renames AVR.ATMEGA328P;
+
+If you use the Makefile and gpr file provided by AVR-Ada you don't have to set that file manually. Simply set the device name in the top of the Makefile. You can refer to AVR.MCU everywhere in your code. When you change the microcontroller in the project it is sufficient to change only the corresponding definition at the top of your makefile.
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rolf Ebert</dc:creator><pubDate>Tue, 14 Aug 2012 12:28:13 -0000</pubDate><guid>https://sourceforge.netadd01499fb869820af901b6046cebd74b226ade3</guid></item><item><title>WikiPage Introductory Tutorial modified by Rolf Ebert</title><link>https://sourceforge.net/p/avr-ada/wiki/Introductory%2520Tutorial/</link><description>&lt;pre&gt;--- v3
+++ v4
@@ -3,7 +3,7 @@
 ##Introduction##
 The tutorial should lower the entrance difficulties of programming Atmel's AVR microcontrollers using the Ada compiler AVR-GCC, aka AVR-GNAT. GNAT is the free GNU Ada compiler, which is part of the [GNU Compiler Collection](http://en.wikipedia.org/wiki/GNU_Compiler_Collection). We assume basic knowledge of programming microcontrollers in general and also some basic knowledge of Ada.
 
-There are tutorials at avrfreaks.net about the AVR controllers and at &lt;http://en.wikibooks.org/wiki/Ada_Programming about Ada&gt;.
+There are tutorials at avrfreaks.net about the AVR controllers and at &lt;http://en.wikibooks.org/wiki/Ada_Programming&gt; about Ada.
 
 Although I originally come from a Unix background I do most of my work now in a MS-Windows environment. The tutorial aims to leave out the details of the hosting OS as much as possible.
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rolf Ebert</dc:creator><pubDate>Tue, 24 Jul 2012 19:24:33 -0000</pubDate><guid>https://sourceforge.net5ed96185c914c74ecc8740ed81b10b145bbe73ff</guid></item><item><title>WikiPage Introductory Tutorial modified by Rolf Ebert</title><link>https://sourceforge.net/p/avr-ada/wiki/Introductory%2520Tutorial/</link><description>&lt;pre&gt;--- v2
+++ v3
@@ -1,4 +1,4 @@
-'''Tutorial for Programming AVR Devices in Ada'''
+#Tutorial for Programming AVR Devices in Ada#
 
 ##Introduction##
 The tutorial should lower the entrance difficulties of programming Atmel's AVR microcontrollers using the Ada compiler AVR-GCC, aka AVR-GNAT. GNAT is the free GNU Ada compiler, which is part of the [GNU Compiler Collection](http://en.wikipedia.org/wiki/GNU_Compiler_Collection). We assume basic knowledge of programming microcontrollers in general and also some basic knowledge of Ada.
@@ -45,36 +45,38 @@
 
 The source code of the program is in a file called led_on.adb
 
+    :::Ada
     with AVR;      use AVR;   -- 1: make available general type definitions and names
     with AVR.MCU;             -- 2: make use of the controller specific ports and pins
                               -- 3:
     procedure LED_On is       -- 4:
-        LED : Boolean renames MCU.PortB_Bits (3); -- 5: rename controller pin 3 of port B to a name of
-                                                  -- 6: the problem domain
-    begin                                         -- 7:
-       MCU.DDRB_Bits := (&lt;b&gt;others&lt;/b&gt; =&gt; DD_Output);  -- 8: set data direction of all pins of port B to output
-       LED := Low;                                -- 9: draw output pin to low level, which turns on the LED
-    end LED_On;                                   -- 10:
+       LED : Boolean renames MCU.PortB_Bits (3); -- 5: rename controller pin 3 of port B to a name of
+                                                 -- 6: the problem domain
+    begin                                        -- 7:
+       MCU.DDRB_Bits := (others =&gt; DD_Output);   -- 8: set data direction of all pins of port B to output
+       LED := Low;                               -- 9: draw output pin to low level, which turns on the LED
+    end LED_On;                                  -- 10:
 
 We also need a GNAT project file (GPR) that contains all the Ada specific settings and a list of required source files.  Create a file called &lt;code&gt;build.gpr&lt;/code&gt;.
 
-    with "avr.gpr";                      -- 1: enable access to the standard AVR library
-    project Build is                     -- 2: the name of the project has to match the file name
+    :::Ada
+    with "avr.gpr";                         -- 1: enable access to the standard AVR library
+    project Build is                        -- 2: the name of the project has to match the file name
 
-    for Main use ("led_on");             -- 4: the name of the main program
+       for Main use ("led_on");             -- 4: the name of the main program
 
-    for Languages use ("Ada");           -- 6: of course, we program in Ada
-    for Object_Dir use "obj";            -- 7: hide the generated file in a subdir
-    for Exec_Dir use ".";                -- 8: keep the main files in the current directory
+       for Languages use ("Ada");           -- 6: of course, we program in Ada
+       for Object_Dir use "obj";            -- 7: hide the generated file in a subdir
+       for Exec_Dir use ".";                -- 8: keep the main files in the current directory
 
-    package Builder renames AVR.Builder; -- 10: apply the standard settings
-    package Compiler renames AVR.Compiler;
-    package Binder renames AVR.Binder;
-    package Linker renames AVR.Linker;
+       package Builder renames AVR.Builder; -- 10: apply the standard settings
+       package Compiler renames AVR.Compiler;
+       package Binder renames AVR.Binder;
+       package Linker renames AVR.Linker;
 
-    for Source_Files use ("led_on.adb"); -- 15: the list of required source files
+       for Source_Files use ("led_on.adb"); -- 15: the list of required source files
 
-    endBuild;
+    end Build;
 
 At the end we also need a Makefiles that glues all the commands together. Copy the Makefile from the exampels of your AVR-Ada installation. There are some parameters that have to be set in the Makefile.
 
@@ -96,6 +98,7 @@
 
 Most of the processor's registers are 8 bits wide, some have 16 bits.  All registers can be read and written like a normal variable of the same width.
 
+    :::Ada
        A : Unsigned_8;
        B : Unsigned_8;
     begin
@@ -107,6 +110,7 @@
 
 Additionally all 8-bit registers are also declared as arrays of 8 booleans.  The name of the register as a boolean array is the standard name with the suffix _Bits.
 
+    :::Ada
     --  Bit_Number indexes the single bits in a byte
     type Bit_Number   is new Nat8 range 0 .. 7;
     --  Give access to every single bit in a byte as a boolean.
@@ -114,6 +118,7 @@
 
 That permits to set or to clear single bits within a register.
 
+    :::Ada
     MCU.DDRB_Bits (3) := DD_Output;
     MCU.DDRB_Bits (2) := DD_Input;
     MCU.PortB_Bits (3) := True;
@@ -121,6 +126,7 @@
 
 The preferred coding style is a Boolean renaming of the selected pin.
 
+    :::Ada
     declare
        Key : Boolean renames MCU.PinB (2)
     begin
@@ -137,6 +143,7 @@
 
 If a port pin is configured as input, an internal pull-up resistor can be activated by writing to the output register. See the Atmel data sheets about the architecture of the microprocessor that you use.
 
+    :::Ada
     MCU.DDRB       -- the data direction register of port B
     MCU.PortB      -- the output register of port B (or pull-up configuration for inputs) 
     MCU.PinB       -- the input register of port B
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Rolf Ebert</dc:creator><pubDate>Tue, 24 Jul 2012 19:20:51 -0000</pubDate><guid>https://sourceforge.net48aa21481e9d5ebb8e1c36fe4e28de661f4f00c0</guid></item><item><title>WikiPage Introductory Tutorial modified by Warren W. Gay VE3WWG</title><link>https://sourceforge.net/p/avr-ada/wiki/Introductory%2520Tutorial/</link><description>&lt;pre&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Warren W. Gay VE3WWG</dc:creator><pubDate>Tue, 24 Jul 2012 05:10:27 -0000</pubDate><guid>https://sourceforge.net839fcafe4ebccedf12f45f060978166c617b3ae2</guid></item><item><title>WikiPage Introductory_Tutorial modified by Warren W. Gay VE3WWG</title><link>https://sourceforge.net/p/avr-ada/wiki/Introductory_Tutorial/</link><description>'''Tutorial for Programming AVR Devices in Ada'''

##Introduction##
The tutorial should lower the entrance difficulties of programming Atmel's AVR microcontrollers using the Ada compiler AVR-GCC, aka AVR-GNAT. GNAT is the free GNU Ada compiler, which is part of the [GNU Compiler Collection](http://en.wikipedia.org/wiki/GNU_Compiler_Collection). We assume basic knowledge of programming microcontrollers in general and also some basic knowledge of Ada.

There are tutorials at avrfreaks.net about the AVR controllers and at &lt;http://en.wikibooks.org/wiki/Ada_Programming about Ada&gt;.

Although I originally come from a Unix background I do most of my work now in a MS-Windows environment. The tutorial aims to leave out the details of the hosting OS as much as possible.

##Prerequisites##
You need the following hard- and software to write and run your own Ada programs on AVR micros:

[img src=Butterfly.jpg]

* A PCB or breadboard carrying an AVR. Again see AVRFreaks for suggestions of prototyping and development kits. Personally I use the [AVR Butterfly](http://www.atmel.com/products/AVR/butterfly) as it is cheap (&lt; 25€) and has a lot of peripherals. A standard development board is the STK500 from Atmel. Recently the Arduinos became quite popular. You can also solder your own PCB or put the controller directly on a breadboard.

[img src=Arduino.jpg]

* AVR-gcc compiler including avr-libc, AVR-Ada, and the avr-binutils. If you run MS-Windows I strongly recommend to get the latest WinAVR distribution. It has all the necessary tools nicely packaged. Some Linux distros also provide AVR development tools (Ubuntu, Suse). They probably do not contain the latest bug fixes and patches. I therefore recommend to build your own tool-chain using our build script "build-avr-ada-gcc-4.3.x.sh". It completely automates the download of all source packages and the latest patches and it inbuilds and installs everything.

* A programming device and corresponding software. If you use an AVR-Butterfly or the popular Arduino hardware you only need a serial or USB cable. For all other development kits you need something like PonyProg or AVRDUDE. Atmel's STK500 also works very well (you'll need their AVR-Studio on MS-Windows).

* A development environment, i.e. a text editor for writing your programs. I am a hardcore [Emacs](http://www.gnu.org/software/emacs/) user, don't expect any other recommendations from my part. WinAVR comes with PN (programmer's notepad), other people use Notepad++, Eclipse or AVR-Studio.

##Generating Target Code##
The compiler generates AVR object code based on your Ada code.  The AVR-Ada tool-chain is based on the general GNAT tools from GCC and the Binutils. The tool-chain includes the compiler itself and some helper programs:

* project manager (avr-gnatmake)
* preprocessor (avr-gnatprep)
* compiler (avr-gcc)
* assembler (avr-as)
* binder (avr-gnatbind)
* link manager (avr-gnatlink)
* linker (avr-ld)

All these tools either come from the GCC or Binutils packages.  A typical user does not have to care about the separate tools.  The only interface that one uses is the project manager and the corresponding project files.  The project manager avr-gnatmake knows about the helper programs and invokes them appropriately.

Some other programs are outside the proper tool-chain.  They are best managed by the Unix make program and the corresponding Makefile.

''There should be a page about the intrinsics of the build process.''

##Simple Example##

Let's start with a simple example.  Consider an ATmega168 (or any other AVR part) that is on a bread board or in the STK500 development board.  The example program should switch one port of the controller to output. One of the port pins is connected to a LED.  The other pin of the LED is connected via a resistor to Vcc, i.e. 5V.  To switch on the LED the corresponding pin must be set to low or ground level, i.e. 0V.

The source code of the program is in a file called led_on.adb

    with AVR;      use AVR;   -- 1: make available general type definitions and names
    with AVR.MCU;             -- 2: make use of the controller specific ports and pins
                              -- 3:
    procedure LED_On is       -- 4:
        LED : Boolean renames MCU.PortB_Bits (3); -- 5: rename controller pin 3 of port B to a name of
                                                  -- 6: the problem domain
    begin                                         -- 7:
       MCU.DDRB_Bits := (&lt;b&gt;others&lt;/b&gt; =&gt; DD_Output);  -- 8: set data direction of all pins of port B to output
       LED := Low;                                -- 9: draw output pin to low level, which turns on the LED
    end LED_On;                                   -- 10:

We also need a GNAT project file (GPR) that contains all the Ada specific settings and a list of required source files.  Create a file called &lt;code&gt;build.gpr&lt;/code&gt;.

    with "avr.gpr";                      -- 1: enable access to the standard AVR library
    project Build is                     -- 2: the name of the project has to match the file name

    for Main use ("led_on");             -- 4: the name of the main program

    for Languages use ("Ada");           -- 6: of course, we program in Ada
    for Object_Dir use "obj";            -- 7: hide the generated file in a subdir
    for Exec_Dir use ".";                -- 8: keep the main files in the current directory

    package Builder renames AVR.Builder; -- 10: apply the standard settings
    package Compiler renames AVR.Compiler;
    package Binder renames AVR.Binder;
    package Linker renames AVR.Linker;

    for Source_Files use ("led_on.adb"); -- 15: the list of required source files

    endBuild;

At the end we also need a Makefiles that glues all the commands together. Copy the Makefile from the exampels of your AVR-Ada installation. There are some parameters that have to be set in the Makefile.

* MCU, the name of the processor, that is atmega8 here
* ADA_TARGETS, the name of the main program, led_on
* GPR, the name of the GNAT project file, here: build.gpr

you can leave the rest as it is.

Now in a command window (shell, DOS-Box, xterm, etc.) you type

    make

and you will see a bunch of commands and their respective output coming by.  The last command will display the use of the different memory sections and the percentage of free space.

Your program is now stored in a file named "led_on.elf". This file has to be transfered to your micro-controler.  the exact handling depends on your hardware equipment. We assume an ISP-programmer like the mkII or the STK-500 driven by avrdude. Review the settings in your Makefile: you have to specify the port that you use, e.g. com4, and the type of the programmer, e.g. stk500v2.  Read the help output of avrdude to see what other options are available.

## Accessing Registers ##

Most of the processor's registers are 8 bits wide, some have 16 bits.  All registers can be read and written like a normal variable of the same width.

       A : Unsigned_8;
       B : Unsigned_8;
    begin
       ...
       A := MCU.PinA;
       MCU.PortB := B;

All registers are declared in the Ada specification AVR.MCU as of type Interfaces.Unsigned_8 or Interfaces.Unsigned_16 respectively.  The name of a register in the Ada specification matchs the name in the corresponding data-sheet.

Additionally all 8-bit registers are also declared as arrays of 8 booleans.  The name of the register as a boolean array is the standard name with the suffix _Bits.

    --  Bit_Number indexes the single bits in a byte
    type Bit_Number   is new Nat8 range 0 .. 7;
    --  Give access to every single bit in a byte as a boolean.
    type Bits_In_Byte is array (Bit_Number) of Boolean;

That permits to set or to clear single bits within a register.

    MCU.DDRB_Bits (3) := DD_Output;
    MCU.DDRB_Bits (2) := DD_Input;
    MCU.PortB_Bits (3) := True;
    Key_Is_Open := MCU.PinB (2);

The preferred coding style is a Boolean renaming of the selected pin.

    declare
       Key : Boolean renames MCU.PinB (2)
    begin
       if Key = Low then
          ...

## IO Ports ##

All the AVR micro-processors have one or several general purpose input / output (GPIO) ports.  The ports are typically named by single letters, eg. port B.  Each port consists of three registers,

* a data direction register
* an input register
* an output register

If a port pin is configured as input, an internal pull-up resistor can be activated by writing to the output register. See the Atmel data sheets about the architecture of the microprocessor that you use.

    MCU.DDRB       -- the data direction register of port B
    MCU.PortB      -- the output register of port B (or pull-up configuration for inputs) 
    MCU.PinB       -- the input register of port B


See also the page about [SimpleIO].
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Warren W. Gay VE3WWG</dc:creator><pubDate>Tue, 24 Jul 2012 04:41:39 -0000</pubDate><guid>https://sourceforge.netc13aaaf8b51d0c0f7670718f3a0dff9086c67c32</guid></item></channel></rss>