Hands On AVR: Difference between revisions

From SGMK-SSAM-WIKI
Jump to navigation Jump to search
Line 1: Line 1:
=ArduinoISP=
=ArduinoISP=


[[File:ArduinoISP_Steckplatine.png]]
[[File:ArduinoISP_Steckplatine.png|500px]]


more soon.
Arduino In-system programming (ISP) interface for the attiny13.
 
Step-by-step instructions:
 
* On the Arduino, the ArduinoISP code must be running. Open the Arduino IDE -> examples -> ArduinoISP and write.
* Install AVR toolchain: [http://winavr.sourceforge.net Windows], [http://tinkerlog.com/2007/09/29/programming-avr-with-a-macbook Mac]
* Compile this code:
 
<syntaxhighlight lang="c">
#define F_CPU 9600000 // Define software reference clock for delay duration
#include <avr/io.h>
#include <util/delay.h>
#define LED PB4 // Define led output on PB4
uint16_t d;
void delay_ms(uint16_t ms)
{
for (uint16_t i = 0 ; i < ms ; i++) {
_delay_ms (1); // Loop delay
}
}
int main()
{
d = 250; // delay time in ms
 
DDRB |= (1 << LED); // Set direction to output for LED
for (;;) { // forever
 
PORTB ^= (1 << LED);
delay_ms(d);
}
return 0;
}
</syntaxhighlight>
 
* run avrdude, make sure you choose the correct USB port and speed, i gave the program the name 'led.hex':
<code>avrdude -P COM9 -b 19200 -c avrisp -p t13 -U flash:w:led.hex:i</code>
 
=AVR=
 
more on AVR soon.

Revision as of 14:11, 5 October 2011

ArduinoISP

Arduino In-system programming (ISP) interface for the attiny13.

Step-by-step instructions:

  • On the Arduino, the ArduinoISP code must be running. Open the Arduino IDE -> examples -> ArduinoISP and write.
  • Install AVR toolchain: Windows, Mac
  • Compile this code:
#define F_CPU 9600000	// Define software reference clock for delay duration
#include <avr/io.h>
#include <util/delay.h>
#define LED PB4 // Define led output on PB4
uint16_t d;
void delay_ms(uint16_t ms)
{
	for (uint16_t i = 0 ; i < ms ; i++) {
 		_delay_ms (1); // Loop delay
 	}
}
int main()
{
	d = 250; // delay time in ms

	DDRB |= (1 << LED); // Set direction to output for LED
	
	for (;;) {	// forever

		PORTB ^= (1 << LED);
		delay_ms(d);
	}
	return 0;
}
  • run avrdude, make sure you choose the correct USB port and speed, i gave the program the name 'led.hex':

avrdude -P COM9 -b 19200 -c avrisp -p t13 -U flash:w:led.hex:i

AVR

more on AVR soon.