Main.AVRProgramming2 History
Hide minor edits - Show changes to markup
A simple and free editing program for Windows is Notepad++.
A simple and free editing program for Windows is Notepad++.
Let's look at the fabric PCB circuit to see why this piece of code would cause the LED on our boards to light up. Here's what the circuit looks like (view from above):\\\
Let's look at the fabric PCB circuit to see why this piece of code would cause the LED on our board to light up. Here's what the circuit looks like (view from above):\\\
Notice how the + side of the LED is attached to b0 and the - side of the LED is attached to ground through a resistor. -'
Notice how the + side of the LED is attached to b0 and the - side of the LED is attached to ground through a resistor. When b0 is High, at +5V, current runs through the LED, causing it to turn on. When b0 is Low, at 0V, both sides of the LED are attached to ground, so no current flows and the LED turns off.-'
On a Mac, type the following command in Terminal: make && make install
On a PC, type the following command: make && make installPC-' \\
Type the following command in Terminal: make && make install \\
_delay_ms(1000); this statement tells the ATtiny to do nothing for 1 second (1000 milliseconds)-' \\
_delay_ms(1000); this statement tells the ATtiny to do nothing for 1 second (1000 milliseconds)
Let's look at the fabric PCB circuit to see why this piece of code would cause the LED on our boards to light up. Here's what the circuit looks like (view from above):
Notice how the + side of the LED is attached to b0 and the - side of the LED is attached to ground through a resistor. -'
5. Use alligator clips to attach a switch to pin b2 and edit the code so that the LED attached to b0 comes on when the switch is pressed
5. Use alligator clips to attach a switch to pin b1 and edit the code so that the LED attached to b0 comes on when the switch is pressed
For the official AVR C programming language reference see: AVR libc documentation-' \\
For the official AVR C programming language reference see: AVR libc documentation
4. Use alligator clips to attach a second LED to pin b1 and edit the code to get that LED to blink.
4. Use alligator clips to attach a second LED to pin b3 and edit the code to get that LED to blink.


For the official AVR C programming language reference see: AVR libc documentation-' \\
\\
This program is written in the C programming language.
This program is written in the C programming language.
_delay_ms(1000); this statement tells the ATtiny to do nothing for 1 second (1000 milliseconds)-'
_delay_ms(1000); this statement tells the ATtiny to do nothing for 1 second (1000 milliseconds)-' \\
On a PC, type the following command: make && make installPC-'
On a PC, type the following command: make && make installPC-'
\\


3. Edit the code to get the LED to blink at a different speed.
On a Mac, type the following command in Terminal: make && make install
On a PC, type the following command: make && make installPC
4. Use alligator clips to attach a second LED to pin b1 and edit the code to get that LED to blink.
5. Use alligator clips to attach a switch to pin b2 and edit the code so that the LED attached to b0 comes on when the switch is pressed

b0High();
_delay_ms(1000);
b0Low();
_delay_ms(1000);-'
b0High(); this statement sets pin b0 to 5 volts. For our circuit this turns the LED attached to b0 ON.
_delay_ms(1000); this statement tells the ATtiny to do nothing for 1 second (1000 milliseconds)
b0Low(); this statement sets pin b0 to 0 volts or ground. For our circuit this turns the LED OFF.
_delay_ms(1000); this statement tells the ATtiny to do nothing for 1 second (1000 milliseconds)-'
_delay_ms(1000); -'
_delay_ms(1000);-'
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like:-' \\
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like:-' \\\
b3Input(); this statement sets up pin b3 to read information from a switch\\\-'
b3Input(); this statement sets up pin b3 to read information from a switch-'\\\
'- b1Output(); this statement sets up pin b1 to control an output like a light or motor
b3Input(); this statement sets up pin b3 to read information from a switch
Main Action Area\\
b1Output(); this statement sets up pin b1 to control an output like a light or motor
b3Input(); this statement sets up pin b3 to read information from a switch\\\
'-Main Action Area\\
'- b1Output(); this statement sets up pin b1 to control an output like a light or motor\\
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like:
b1Output(); this statement sets up pin b1 to control an output like a light or motor\\
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like:-'
->'- b1Output(); this statement sets up pin b1 to control an output like a light or motor\\
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like: \\-' '-b1Output(); this statement sets up pin b1 to control an output like a light or motor\\
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like:
b1Output(); this statement sets up pin b1 to control an output like a light or motor\\
b1Output(); this statement sets up pin b1 to control an output like a light or motor\\
'-b1Output(); this statement sets up pin b1 to control an output like a light or motor\\


For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like: \\
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like: \\-'
b3Input(); this statement sets up pin b3 to read information from a switch
b3Input(); this statement sets up pin b3 to read information from a switch\\\
_delay_ms(1000);-'
_delay_ms(1000); -'
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like:
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like: \\
b3Input(); this statement sets up pin b3 to read information from a switch\\-'
b3Input(); this statement sets up pin b3 to read information from a switch
'-This section is where the main action of our program takes place. In this piece of code we have 4 lines: \\\
This section is where the main action of our program takes place. In this piece of code we have 4 lines: \\\
b3Input(); this statement sets up pin b3 to read information from a switch
b3Input(); this statement sets up pin b3 to read information from a switch\\-'
This section is where the main action of our program takes place. In this piece of code we have 4 lines: \\\
'-This section is where the main action of our program takes place. In this piece of code we have 4 lines: \\\
Identify pin b0 on the diagram. Notice that in addition to b0 there are b1, b2, b3, b4, and b5. We can use b1-b4 in our programs. We will not be using b5 in any of our programs. We need to do a special kind of programming to use b5.\\\
Identify pin b0 on the diagram. Notice that in addition to b0 there are b1, b2, b3, b4, and b5. We can use b1-b4 in our programs. We will not be using b5 in any of our programs. We need to do a special kind of programming to use b5.
For every program that you create, you need to include a statement like b0Output() for every pin you would like to use to read information from a switch or to control an output device. Here's what those statements look like:
b1Output(); this statement sets up pin b1 to control an output like a light or motor
b3Input(); this statement sets up pin b3 to read information from a switch
'-Comment Area\\
'-Comments Area\\
Setup Area 1\\
Setup Area 1\\
Setup Area 2\\
Setup Area 2\\
Main Action Area\\
Identify pin b0 on the diagram. Notice that in addition to b0 there are b1, b2, b3, b4, and b5. We can use b1-b4 in our programs. We will not be using b5 in any of our programs. We need to do a special kind of programming to use b5.
Main Action Area\\
'-Comment Section\\
'-Comment Area\\
_delay_ms(1000);\\\-'
_delay_ms(1000);-'
Comment Section\\
'-Comment Section\\
This section is where we tell our ATtiny13 which legs we'll be using for which purpose. In our code the line b0Output() tells the ATtiny that an output (like an LED or a motor) will be attached to pin b0. Each pin on the ATtiny13 has a name like b0. To know which pin is which, you can refer to the pin diagram from the ATtiny's datasheet. Here's what that looks like: Attach: ATtiny13PinOut.png\\\
This section is where we tell our ATtiny13 which legs we'll be using for which purpose. In our code the line b0Output() tells the ATtiny that an output (like an LED or a motor) will be attached to pin b0. Each pin on the ATtiny13 has a name like b0. To know which pin is which, you can refer to the pin diagram from the ATtiny's datasheet. Here's what that looks like: \\\
This section is were the main action of our program takes place. In this piece of code we have 4 lines: \\
This section is where the main action of our program takes place. In this piece of code we have 4 lines:
b0High();
_delay_ms(1000);
b0Low();
_delay_ms(1000);\\\-'
At the top of the page there is a comment section that gives some basic information about the program. This section is ignored by the computer. It's just there to give us humans some information about the file. In general, a comment is a piece of text that is ignored by the computer. Comments can be anywhere in your program. There are two different ways to create comments: \\
At the top of the page there is a comment section that gives some basic information about the program. This section is ignored by the computer. It's just there to give us humans some information about the file. In general, a comment is a piece of text that is ignored by the computer. Comments can be anywhere in your program. There are two different ways to create comments: \\\
Setup Area 1
This section is where we tell our program what other files it will need and set some basic parameters. We'll be ignoring this section for now.
Setup Area 2
This section is where we tell our ATtiny13 which legs we'll be using for which purpose. In our code the line b0Output() tells the ATtiny that an output (like an LED or a motor) will be attached to pin b0. Each pin on the ATtiny13 has a name like b0. To know which pin is which, you can refer to the pin diagram from the ATtiny's datasheet. Here's what that looks like:
Attach: ATtiny13PinOut.png
Main Action Area
This section is were the main action of our program takes place. In this piece of code we have 4 lines:
\\


This program is written in the C programming language.

\* Anything in between a slash and an asterik and then an asterik and
a slash, like this statement *\ OR
'\\ A sigle line of text that follow two slashes like this line.

Comment Section
At the top of the page there is a comment section that gives some basic information about the program. This section is ignored by the computer. It's just there to give us humans some information about the file. In general, a comment is a piece of text that is ignored by the computer. Comments can be anywhere in your program. There are two different ways to create comments:
\* Anything in between a slash and an asterisk and then
an asterisk and a slash, like this statement is a comment *\
OR
\\ A sigle line of text that follows two slashes like this line is also a comment.
\* purpleAnything in between a slash and an asterik and then an asterik and \\
\* Anything in between a slash and an asterik and then an asterik and \\
'\\ purpleA sigle line of text that follow two slashes like this line.
'\\ A sigle line of text that follow two slashes like this line.
purple \* Anything in between a slash and an asterik and then an asterik and \\
\* purpleAnything in between a slash and an asterik and then an asterik and \\
'\\ A sigle line of text that follow two slashes like this line.
'\\ purpleA sigle line of text that follow two slashes like this line.
purple \* Anything in between a slash and an asterik and then an asterik and
a slash, like this statement *\ OR
'\\ A sigle line of text that follow two slashes like this line.



Attach: AVRCodeRegions.jpg

Attach: AVRCodeExecution.jpg

AVR Programming Tutorial: Writing Programs
0. Open the blink.c program file.
1. The program is broken up in to a few different regions. Here are the ones we care about: Attach: AVRCodeRegions.jpg
2. Understanding program structure.
Attach: AVRCodeExecution.jpg