Saturday, October 11, 2008

AVR Learning - Blink a LED

For beginners the first thing to try on a new system or in a new programming language is to print out "hello world". The equivalent for microcontrollers and other embedded systems is to blink a LED. When even the target circuit and the programmer are freshly put together it is wise to start even lower, with a blink-a-LED program written by someone else that is known to be working.

On this page you will find a 1 Hz blink-a-LED test programs for the Tiny12 and the AT2313 targets chips and circuits. You can build the circuits on a breadboard or use the AT2313 ISP board. The programs are made in assembler with AVR Studio 4 for the ATTiny12 and with the BASCOM complilor for the AT2313. Look on the AVR Programming Hardware pages for how to make a programming cable and on the AVR Programming Software pages for the software to get the hex file into your device.

Because the ports of the AVR chips can draw 20mA current, only a resistor to limit the current is neccesary to connect a LED to one of the ports. In both the circuits the LED is connected to PortB.0. In the circuit for the ATTiny12 the internal 1.2 MHz oscillator is used, because of that you don't need an external oscillator, but it can be configured also for an external crystal.

here the source code:

Config Portb = Outputout       'set port B as output

Do ' eternal loop
Portb.0 = 1 ' make portB.0 high
Waitms 500 ' wait 500ms
Portb.0 = 0 ' make Portb.0 Low
Waitms 500 'wait 500ms
Loop

The HEX file:

:020000020000FC
:100000000FEF07BBC09802D0C09AFCCF1FE027E3D8
:1000100039EC3A95F1F72A95D9F71A95C1F711E01D
:0A0020001A95F1F7000000000895A2

:00000001FF

No comments: