Assignment
read a microcontroller data sheet
program your board to do something, with as many different programming languages
and programming environments as possible
photo / video
This week, I did
1. programming the board with FabISP via Arduino IDE to make the LED blinking. (Mac)
2. programming the board with FabISP in C using GCC and avrdude to echo keyboard input. (Mac)
3. rewriting the program in C and programming the board with FabISP using GCC and avrdude to turn on/off the LED with the switch. (Mac)
4. programming an ATmega 328P with FabISP in C using GCC and avrdude to make an LED blinking. (Mac)
In my case, the cable should be connected like this below. The direction of the cable of course will be changed according to your board design and pin setting.
An AVR micro-controller you just bought will not work on your Arduino board.
It needs to be bootloaded for Arduino IDE.
The tutorial explains how to do it on your ATtiny44A.
Points you may be confused with
Type 'const' before the variable 'message' in hello.ftdi.44.echo.c if you got an error message like this below.
▼ Type 'const' at the beginning of the line including the variable 'message'.
Programmer Setting
Serial Port Setting
By the way, if you are new to Arduino and if you can read Japanese, I really recommend you this website. 建築発明工作ゼミ2008 -Arduino関係
▼ After finishing the tutorial, the board should respond like this.
Program the board with FabISP in C using GCC and avrdude
You need to have avrdude and GCC in order to program your board.
Make sure you went through this tutorial during the week on Electronics Production.
If not, see "Install the Necessary Software for AVR Programming" in the tutorial to get them.
(*This tutorial shows installing ways only for Mac and Ubuntu, if you are using Windows, search a way by yourself or see "Program the board with FT232RL in C using WINAVR and avrdude-GUI (yuki-lab.jp Version)" below on this page.
▼ After finishing the tutorial, the board echoes letters you type.
Write a program in C
Download these files which you just used in the previous section "Program the board with FabISP in C using GCC and avrdude" and make a directory then put them in it.
#define F_CPU 20E6
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRA = 0x80; /* make the LED pin an output */
//DDRA = 1 << 7; /* make the LED pin an output */
for(;;){
if((PINA & (1 << 3)) == 0){
PORTA = 0x80; /* turn on the LED */
//PORTA = 1 << 7; /* same to 0x80 */
}
else{
PORTA = 0x00; /* turn off the LED*/
//PORTA = 0 << 7; /* same to 0x00 */
}
}
}
Line 1 of the .c file
Probably you don't need the Line 1 '#define F_CPU 20E6', which defines the micro-controller's clock frequency, because the .make file also has this definition. (I'm not sure.)
20E6 means 20 * (the 6th power of 10) == 20000000Hz == 20MHz.
Line 7 of the .c file
0x80 means that 80 is a hexadecimal number(16進数). For instance, 0x20 means 20 is a hexadecimal number.
80 in hexadecimal number is 10000000 in binary number(2進数).
DDRA = 0x80; means that pin 7 of port A is 1(output) and the other pins are 0(input).
The binary number corresponds to the pins in the direction big -> small number.
In this case, 10000000 means that
pin 7: 1 (output)
pin 6: 0 (input)
pin 5: 0 (input)
pin 4: 0 (input)
pin 3: 0 (input)
pin 2: 0 (input)
pin 1: 0 (input)
pin 0: 0 (input)
For examble, 0x24 is 100100, this means 00100100, then corresponds to the pins like this below.
pin 7: 0 (input)
pin 6: 0 (input)
pin 5: 1 (output)
pin 4: 0 (input)
pin 3: 0 (input)
pin 2: 1 (output)
pin 1: 0 (input)
pin 0: 0 (input)
DDR means Data Direction Register and DDRA means Data Direction Register for port A.
When you set pins of Port B, it will be 'DDRB'.
It means absolutely the same to the Line 7.
It is now commented out, you can use this code instead of the Line7.
1 << 7 shifts 1 for 7 bits to the left. This means like this below.▼
shift for 0 bit to the left
00000001
shift for 1 bit to the left
00000010
shift for 2 bits to the left
00000100
shift for 3 bits to the left
00001000
shift for 4 bits to the left
00010000
shift for 5 bits to the left
00100000
shift for 6 bits to the left
01000000
shift for 7 bits to the left
10000000
Line 11 of the .c file
To output, use 'PORTx'.
If you want to output '1' (e.g. 5V) via pin 7 of Port A and output '0' (0V) via the other pins of Port A, you need to write 'PORTA = 0x80'.
0x80 means, as I mentioned above, 10000000 then means 1 to pin 7.
So 'PORTA = 1 << 7' will also work. (I have not tried though.)
Line 15 of the .c file
0x00 is 00000000.
All the pins output 0.
Line 10 of the .c file
To input, use 'PINx'.
If you want to read inputs from Port A, you need to write 'PINA'.
But this is for 8 bits.
Program an ATmega328P with FabISP in C using GCC and avrdude
This section is in progress, sorry.
Program the board with FT232RL in C using WINAVR and avrdude-GUI (yuki-lab.jp Version)