<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ATtiny13 and some hacking...</title>
	<atom:link href="http://attiny13.lars.stonerocket.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://attiny13.lars.stonerocket.co.uk</link>
	<description>Exploring electronics with ATtiny&#039;s and hacking.</description>
	<lastBuildDate>Tue, 27 Apr 2010 22:15:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Programming ATtiny13 with USBtinyISP &#8211; Ubuntu</title>
		<link>http://attiny13.lars.stonerocket.co.uk/2010/04/programming-attiny13-with-usbtinyisp-ubuntu/</link>
		<comments>http://attiny13.lars.stonerocket.co.uk/2010/04/programming-attiny13-with-usbtinyisp-ubuntu/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 20:09:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[The Attiny13]]></category>

		<guid isPermaLink="false">http://attiny13.lars.stonerocket.co.uk/?p=358</guid>
		<description><![CDATA[I made a tutorial on how to program your ATtiny13 (or other ATtiny)  on windows with USBtinyISP, here. This post will be a quick tutorial on how to do it on Ubuntu (9.10).
For me it was a lot of work, because it took a while before I knew what for programs to install (and how [...]]]></description>
			<content:encoded><![CDATA[<p>I made a tutorial on how to program your ATtiny13 (or other ATtiny)  on windows with USBtinyISP, <a href="http://attiny13.lars.stonerocket.co.uk/2009/11/programming-attiny13-with-usbtinyisp/" target="_blank">here</a>. This post will be a quick tutorial on how to do it on Ubuntu (9.10).<br />
For me it was a lot of work, because it took a while before I knew what for programs to install (and how to do that). Anyway, this is how you can do it.</p>
<p>First we need a program to convert your code (C-code in this case) to hex. For this I use avr-gcc, to get this working we need to install three things:</p>
<ul>
<li>gcc-avr</li>
<li> binutils-avr</li>
<li> avr-libc</li>
</ul>
<p>The easiest way to install this on Ubuntu is below. Put these commands in the terminal. You can find that under the programs list, then pocketknife and then it looks like a punched eye on a rectangle face, haha:</p>
<pre><code class="dos">sudo apt-get install gcc-avr
sudo apt-get install binutils-avr
sudo apt-get install avr-libc
</code></pre>
<p>To make a hex file (that your micro-controller can "read")  from your C-code we need to feed avr-gcc three instructions (don't ask me why for installing it is called gcc-avr and now avr-gcc). These instructions look like so (adjust to your need, in this case the C-code is demo.c):</p>
<pre><code class="dos">avr-gcc -g -Os -mmcu=attiny13 -c demo.c
avr-gcc -g -mmcu=attiny13 -o demo.elf demo.o
avr-objcopy -j .text -j .data -O ihex demo.elf demo.hex
</code></pre>
<p>To get the hex code onto the micro-controller we will use avrdude that can work with USBtinyISP. Pretty simple to install it:</p>
<pre><code class="dos">sudo apt-get install avrdude
</code></pre>
<p>To really get the hex on the chip we need to send the following instruction (still using demo as name):</p>
<pre><code class="dos">sudo avrdude -c usbtiny -p attiny13 -U flash:w:demo.hex</code></pre>
<p>There is sudo in front of this terminal command because else it simply won't work.</p>
<p>Pufff.... All this typing/copying every time to program is a lot of work, fortunately it can be automated. I think you can do this with makefiles on Ubuntu, but I don't understand those, so I do it with bash (.bat files).</p>
<p>This is how my bash file looks. Just make a new file in the same folder as your C-code and name it whatever-you-like.bat, give it this text, save it and run it with <em>bash whatever-you-like.bat</em> in the terminal <img src='http://attiny13.lars.stonerocket.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre><code class="dos">project="demo"
chip="attiny13" 

clear
echo Hi, ...working on the stuff

avr-gcc -g -Os -mmcu=$chip -c $project.c
avr-gcc -g -mmcu=$chip -o $project.elf $project.o
avr-objcopy -j .text -j .data -O ihex $project.elf $project.hex
sudo avrdude -c usbtiny -p $chip -U flash:w:$project.hex

rm $project.elf
rm $project.o
</code></pre>
<p>The first two lines are variables, you can change them to your needs. For example, if your C-code file is named blink.c, you just change demo to blink. Please keep in mind that there may never be spaces between the is-sign. So this: <em>project = "blink"</em> is wrong and should be <em>project="blink". </em></p>
<p>The last two lines delete the .elf and .o files, I believe these contain information on how the compiling/converting went (the code in assembly), but I so far never used them.</p>
<p><strong>That's it!</strong></p>
<p>Perhaps you want some test C-code to see if it works? Sure, below is a blink / blinking / pulsing / oscillator that you can use with a LED:</p>
<pre><code class="avrasm">
#define F_CPU 1200000UL
#include &lt;avr/io.h&gt;
#include &lt;util/delay.h&gt;

#define output_low(port,pin) port &amp;= ~(1&lt;&lt;pin)
#define output_high(port,pin) port |= (1&lt;&lt;pin)
#define set_input(portdir,pin) portdir &amp;= ~(1&lt;&lt;pin)
#define set_output(portdir,pin) portdir |= (1&lt;&lt;pin)

#define LED PB4

void delay_ms(uint16_t millis) {
 uint16_t loop;
 while ( millis ) {
 _delay_ms(1);
 millis--;
 }
}

int main(void) {
 DDRB |= 1&lt;&lt; LED; // PB4 output
 while(1) {
 // turn on the LED for 200ms
 output_high(PORTB, LED);
 delay_ms(200);
 // now turn off the LED for another 200ms
 output_low(PORTB, LED);
 delay_ms(200);
 }
 return 0;
}
</code></pre>
<p>You can download all the files from above <a href="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2010/04/demo-blink-whatever-you-like.zip" target="_blank">here</a>.</p>
<p>Some small tips:</p>
<ul>
<li>Once you have entered the command to use the bash file (<em>bash name-of-bash.bat</em>) and you programmed the chip, but noticed a mistake, you don't need to retype the line in the terminal, just press the up-arrow key.</li>
<li>If you use the ATtiny2313 instead of the 13, you probably need to change PB4 (or another port number) to PD4.</li>
<li>The ATtiny13 can run faster than 1200000UL (1.2 MHz), but this is the factory default.</li>
<li>The USBtinyISP can be deliver the required power to run the blinking (of the LED). That is where the jumper is for. <img src='http://attiny13.lars.stonerocket.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://attiny13.lars.stonerocket.co.uk/2010/04/programming-attiny13-with-usbtinyisp-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Differences</title>
		<link>http://attiny13.lars.stonerocket.co.uk/2010/01/differences/</link>
		<comments>http://attiny13.lars.stonerocket.co.uk/2010/01/differences/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 10:09:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[The Attiny13]]></category>

		<guid isPermaLink="false">http://attiny13.lars.stonerocket.co.uk/?p=235</guid>
		<description><![CDATA[Often you find a transistor, IC or other electronic part and there are some small naming differences, like ATtiny13 and ATtiny13a. You start to wonder what differences are and go to google it. On this page I'm going to post most of the differences I encounter for easy access. Got something to add?, please comment.
ATtiny's
ATtiny13    [...]]]></description>
			<content:encoded><![CDATA[<p>Often you find a transistor, IC or other electronic part and there are some small naming differences, like ATtiny13 and ATtiny13a. You start to wonder what differences are and go to google it. On this page I'm going to post most of the differences I encounter for easy access. Got something to add?, please comment.</p>
<h2>ATtiny's</h2>
<p>ATtiny13        -<br />
ATtiny13v    - Like the 13, but max. 10Mhz and can run on 1.8 Volt instead of 2.7 Volt;<br />
ATtiny13a    - Replaces ATtiny13 and ATtiny13v, can run on 1.8 Volt and 20Mhz.</p>
<p>See this image below for an overview with the differences between the Attiny13, Attiny2313, Attiny24, Attiny25, Attiny26, Attiny45, Attiny84 and Attiny85.<em> (data from Feb. 2009)</em></p>
<p><a href="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2010/01/overview.png"><img class="aligncenter size-medium wp-image-345" title="Overview ATtiny series" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2010/01/overview-300x170.png" alt="" width="300" height="170" /></a></p>
<h2>Transistors</h2>
<p><strong>NPN</strong> - <strong>n</strong>ot <strong>p</strong>ointing i<strong>n<br />
PNP</strong> - <strong>p</strong>ointing <strong>i</strong>n</p>
<p>In front of the transistor means (like <em>BC549</em>):<br />
<strong>B </strong>- Silicon<strong><br />
BC - </strong>Small signal transistor ("allround")<br />
<strong>BF</strong> - High frequency, many MHz (low power)<br />
<strong>BD</strong> - Withstands higher current and power</p>
<p>SMD transistors, see this code book: <a href="http://www.marsport.org.uk/smd/mainframe.htm" target="_blank">http://www.marsport.org.uk/smd/mainframe.htm</a></p>
<h2>Resistors</h2>
<p><img class="aligncenter size-full wp-image-348" title="resistor color codes" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2010/01/resistor_color_codes.gif" alt="" width="449" height="359" /></p>
<p>SMT/SMD Resistors work on three digits or four digits. The last one is always the power to amount. One with a zero is just a connector (no resistance). Resistances less than 10 ohms have 'R' to indicate the position of the decimal point.<br />
Like so:<br />
1R2 is 1.2 ohms<br />
330 is 33 x 1 =  33 ohms <span style="color: #808080;">(not 330 ohms)<br />
</span>221 is 22 x 10 = 220 ohms<br />
474 is 47 x 10000 = 470.000 ohms</p>
<address>Sources:<br />
http://en.wikipedia.org/wiki/Transistor  |  http://en.wikipedia.org/wiki/Resistor   |  Quick Reference Guide ATMEL, February 2009   |  http://www.intellecta.net/ (resistor code image)<br />
</address>
]]></content:encoded>
			<wfw:commentRss>http://attiny13.lars.stonerocket.co.uk/2010/01/differences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>De-soldering</title>
		<link>http://attiny13.lars.stonerocket.co.uk/2009/12/de-soldering/</link>
		<comments>http://attiny13.lars.stonerocket.co.uk/2009/12/de-soldering/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 10:11:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[The Attiny13]]></category>

		<guid isPermaLink="false">http://attiny13.lars.stonerocket.co.uk/?p=211</guid>
		<description><![CDATA[Yesterday I have been de-soldering (or desoldering) a lot. I use for this a special soldering iron with a pump in it. I really advise you to buy one too when you do a lot of de-soldering. It is so much easier with such a tool. You have a 'free hand' to hold the circuit-board [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I have been de-soldering (or desoldering) a lot. I use for this a special soldering iron with a pump in it. I really advise you to buy one too when you do a lot of de-soldering. It is so much easier with such a tool. You have a 'free hand' to hold the circuit-board which you else need to use to hold the pump and they simply 'suck' better, haha, because the tin is still fluid. These de-soldering irons don't have to be expensive. Mine was like 10 euro (with shipping).</p>
<p>A free hint from me is that you wait 1-2 seconds so all the tin is fluid and then suck it away. To know if it is all fluid I press against the pins in one direction until it moves. I mostly use this technique with IC's. Althought the de-solder iron is awesome it does not work on all circuit-boards. Some of the newer circuit-boards have very precise holes and so little room between the pins and the board, it is difficult to get the tin away from there when you fail the first time. Perhaps a reader has a hint how to do that?, please comment.</p>
<p>So say goodbye to this one:</p>
<p><img class="aligncenter size-full wp-image-212" title="De-solder pump" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/desolder_pump_blue.jpg" alt="" width="400" height="98" /></p>
<p>And say hello to your new friend when it comes to de-soldering:</p>
<p><img class="aligncenter size-full wp-image-213" title="De-solder Iron" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/desolder_iron-yellow.jpg" alt="" width="400" height="216" />The electronic items that I collected are a lot and some are very nice. I took them from old phone circuit-boards, old computer mice and some other things. Here is the most of it (click-able):</p>
<p><a href="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/collected-electronic-items.jpg"><img class="aligncenter size-medium wp-image-214" title="Collected electronic items" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/collected-electronic-items-300x155.jpg" alt="" width="300" height="155" /></a></p>
<p>During the de-soldering I broke some parts, which isn't nice, but it is a nice chance to see how the components look from the inside. <img src='http://attiny13.lars.stonerocket.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Here is a diode (click-able):</p>
<p><a href="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/diode-inside.jpg"><img class="aligncenter size-medium wp-image-215" title="Diode inside" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/diode-inside-300x141.jpg" alt="" width="300" height="141" /></a>And here is a relay from the inside (click-able):<a href="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/relay-inside.jpg"><img class="aligncenter size-medium wp-image-216" title="Relay inside" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/relay-inside-285x300.jpg" alt="" width="285" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://attiny13.lars.stonerocket.co.uk/2009/12/de-soldering/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Nikon D40 infrared remote DIY</title>
		<link>http://attiny13.lars.stonerocket.co.uk/2009/12/nikon-d40-infrared-remote-diy/</link>
		<comments>http://attiny13.lars.stonerocket.co.uk/2009/12/nikon-d40-infrared-remote-diy/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 18:37:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[The Attiny13]]></category>

		<guid isPermaLink="false">http://attiny13.lars.stonerocket.co.uk/?p=198</guid>
		<description><![CDATA[For my images I use the Nikon D40, but never used the infrared remote function. After google'ing I found some websites on the subject. Here and here. Thanks to these great detailed websites I went to work to make my own Nikon ML-L3 remote control.
The code for getting the triggering to work took some time. [...]]]></description>
			<content:encoded><![CDATA[<p>For my images I use the Nikon D40, but never used the infrared remote function. After google'ing I found some websites on the subject. <a href="http://www.xs4all.nl/~dicks/avr/nikon/index.html" target="_blank">Here</a> and <a href="http://www.bigmike.it/ircontrol/" target="_blank">here</a>. Thanks to these great detailed websites I went to work to make my own Nikon ML-L3 remote control.</p>
<p>The code for getting the triggering to work took some time. The problem eventually was the wrong calculated timings by me. Fortunately, VMLAB showed me the mistakes and I got it working. There is also a short tutorial on VMLAB on this website.</p>
<p>The complete code is below. Note that this is only for the triggering part (no waiting on button or stuff like that) and repeats constantly.</p>
<p>Sorry for little commenting on the code, but those other websites already explain a lot. The code is written in Assembly, perhaps if I did it in C I finished it faster, but where is the fun in that. <img src='http://attiny13.lars.stonerocket.co.uk/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  Maybe I'll post a C version later on.</p>
<p>You can also download a zipped version here, <a href="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/d40_ir_remote.zip">D40 IR Remote</a></p>
<pre><code class="avrasm">; Hello - warning dutch
; Attempt for D40 IR Control

; 2000 us 	ON
; 27830 us 	OFF
; 390 us 	ON
; 1580 us	OFF
; 410 us	ON
; 3580 us 	OFF
; 400 us 	ON
; repeat after 63200 us (OFF)

; bij 9.6Mhz / 8 is 0,83333.... us per tik.

.include "tn13def.inc"

.def mp = r16
.def t1 = r17
.def t2 = r18
.def blinktime = r19

RJMP   	main

delay130:
nop
nop
nop
nop
nop
ret									; 4 tik + rcall 3

main:
	ldi   	mp,0b00001101
   	out   	DDRB,mp

loop:

;(Start pulse) 2000 us	ON
ldi blinktime,77      		; (13.0 uS * 2 ) * 77 = 2002 uS
startpulse1:
		LDI   mp,0x00    			; Led on
		OUT   PORTB,mp
rcall delay130  			; Wait 13 uS
		LDI   mp,0xFF     			; Led off
		OUT   PORTB,mp
rcall delay130  			; wait 13 uS

dec blinktime
brne startpulse1

;27830 us OFF
clr t1
ldi t2, 44
pauze1:
	dec t1
	brne pauze1
	dec t2
	brne pauze1

; 390 us 	ON
ldi blinktime,15
startpulse2:
		LDI   mp,0x00    			; Led on
		OUT   PORTB,mp
rcall delay130  			; Wait 13 uS
		LDI   mp,0xFF     			; Led off
		OUT   PORTB,mp
rcall delay130  			; wait 13 uS

dec blinktime
brne startpulse2

; 1580 us	OFF
clr t1
ldi t2, 3
pauze2:
	dec t1
	brne pauze2
	dec t2
	brne pauze2

; 410 us	ON
ldi blinktime,15
startpulse3:
		LDI   mp,0x00    			; Led on
		OUT   PORTB,mp
rcall delay130  			; Wait 13 uS
		LDI   mp,0xFF     			; Led off
		OUT   PORTB,mp
rcall delay130  			; wait 13 uS

dec blinktime
brne startpulse3

; 3580 us 	OFF
clr t1
ldi t2, 6
pauze3:
	dec t1
	brne pauze3
	dec t2
	brne pauze3

; 400 us 	ON
ldi blinktime,15
startpulse4:
		LDI   mp,0x00    			; Led on
		OUT   PORTB,mp
rcall delay130  			; Wait 13 uS
		LDI   mp,0xFF     			; Led off
		OUT   PORTB,mp
rcall delay130  			; wait 13 uS

dec blinktime
brne startpulse4

; repeat after 63200 us (OFF)
clr t1
ldi t2, 99
pauze4:
	dec t1
	brne pauze4
	dec t2
	brne pauze4

 rjmp loop
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://attiny13.lars.stonerocket.co.uk/2009/12/nikon-d40-infrared-remote-diy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Basics Programming ATtiny13</title>
		<link>http://attiny13.lars.stonerocket.co.uk/2009/12/basics-programming-attiny13/</link>
		<comments>http://attiny13.lars.stonerocket.co.uk/2009/12/basics-programming-attiny13/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 14:49:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[The Attiny13]]></category>

		<guid isPermaLink="false">http://attiny13.lars.stonerocket.co.uk/?p=97</guid>
		<description><![CDATA[When you want to program a microcontroller like the ATtiny13 there are some basic things you need to know. I will discuss them here. If I forgot something, please post in the comments. This page is a tutorial slash reference page.
Please make sure you have downloaded the datasheet of the ATtiny13. You can download it [...]]]></description>
			<content:encoded><![CDATA[<p>When you want to program a microcontroller like the ATtiny13 there are some basic things you need to know. I will discuss them here. If I forgot something, please post in the comments. This page is a tutorial slash reference page.</p>
<p>Please make sure you have downloaded the datasheet of the ATtiny13. You can download it from the Atmel website: <a href="http://www.atmel.com/dyn/products/Product_card.asp?part_id=3175" target="_blank">download first link (176 pages)</a></p>
<p>The ATtiny13 has three types of memory. Flash memory, SRAM and EEPROM. The Flash memory is where you put the code for the microcontroller (like the HDD in a PC) and has a maximum of 1K Bytes. The ATtiny45 has 4K of memory. SRAM and EEPROM are like little boxes where the microcontroller works from and with, also called registers. You could compare those with the RAM in a PC. If you turn the microcontroller off the data in SRAM is gone, but Flash and EEPROM not. Why different types of memory? This is because of the differences in maximum rewrites, costs, speed and power consumption. Flash for example cannot handle that much rewrites as SRAM or EEPROM. More info on <a href="http://en.wikipedia.org/wiki/Computer_memory" target="_blank">wiki</a>.</p>
<p><img class="alignright size-full wp-image-139" title="0101110101" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/010101-ic.jpg" alt="0101110101" width="150" height="152" />A microcontroller works on 0101101001, called binary, and because this is hard to remember we make use of a programming language. For microcontrollers there are two main languages you can pick from; '<a title="Wikipedia article" href="http://en.wikipedia.org/wiki/C_%28programming_language%29" target="_blank">C</a>' and '<a title="Wikipedia article" href="http://en.wikipedia.org/wiki/Assembly_language" target="_self">Assembly</a>'. There are some important differences between these two. The biggest difference is that C is more 'general', this means you can also run it, often with little adjustment, on other microcontrollers.  Assembly will really only work on the specific microcontroller. The disadvantage of this more general approach of C is that the code is often unnecessary big(ger) than Assembly. Microcontrollers don't have that much memory so that could cause problems.</p>
<p>Which language is better is hard to say, some people prefer one above the other. I would suggest to know them both, this is because on the web you will be looking for example code and sometimes that is in Assembly and other times in C. In this tutorial I will first use Assembly (later on C), because I do think it will give a better understanding of how the microcontroller works.</p>
<p>Before we begin, it is important to know that the ATtiny works with 8-bit. This means that the zero's and ones that the microcontroller uses are stored in 8 numbers of only an 0 or a 1. Like so: 00000000 or 11111111 or any combination in between. This also means that the maximum real number/decimal is 256 (2 to the power 8). You could sometimes use two 8 bit registers in the memory for a 16 bit number (max 65536), but you often just work in the 0 <strong>to</strong> 256 range. Note that I say <strong>to</strong> and not including 256. You see, zero als counts for something. So to say it correctly, you can use the decimal numbers from 0 up to and including 255. Also for the microcontroller 255+1 = 0. Huh? Yeah, after you reached/got to 256 the microcontroller will start at 0 again, because it can't go higher. This starting over at 0 can be very useful for counters in delays, I will discuss that later on.</p>
<p>The 8-bit is also used to enable or disable certain parts of the microcontroller. Let's get the datasheet, go to page 56 and I'll show you what I mean. On this page you will see at the bottom this:</p>
<p style="text-align: left;"><img class="aligncenter size-full wp-image-105" title="ddrb" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/ddrb.png" alt="ddrb" width="572" height="91" />Often your first program will be flashing a LED and to let this work you need to make sure the microcontroller knows which pins will be used for sending the pulse/flash. To do this you need to change the DDRB register in the register of the chip, which *happens* to be an 8-bit register. It says 0 to 7, that is 8 in total of course. So when you make DDRB into 00000001, only DDB0 will be able to send the pulse. Often you write this as 0b00000001, where 0b stands for binary. What is DDB0? That is your PORTB pin, also in short that is PB. You can find your PORTB pin on your microcontroller in the datasheet on page 2 (or look here below). In this case it is PB0 because it is DDB0 and that is pin 5.  This pin can also do other things as you can see, like PCINT0, I will discuss this another time.<img class="aligncenter size-full wp-image-107" title="pins-attiny13" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/pins-attiny13.png" alt="pins-attiny13" width="492" height="146" />To make a LED flash we are not done yet, we only told the microcontroller which pin will be used for sending, we are not sending anything yet. To do this we need to change another register in the microcontroller, the PORT B Data register. You can find this also on page 56. When you set this bit to 0b00000001, you will generate a signal/voltage across PB0, which is pin 5. If you change it back to 0b00000000 there will be no signal, so it is OFF. This is a start for a flash/blink program with a LED.</p>
<p>Okay, I'll post some Assembly code here and than explain what it does. (Please note that this code won't let your LED flash, because the delay time is too short.)</p>
<pre><code class="avrasm">.include "tn13def.inc" 

.def mp = r16

rjmp main			

main:
	ldi   	mp,0b00001000 ;this is PB3
   	out   	DDRB,mp		

loop:
LDI   mp,0x00
OUT   PORTB,mp		

nop

LDI   mp,0xFF
OUT   PORTB,mp		

nop ; this is a comment

rjmp loop</code></pre>
<p>The <strong>include </strong>line is always there, it links to a file where the compiler (the one that changes Assembly to 011001, binary) gets information to translate everything correctly. In this case it's "tn13def.inc", which is for the ATtiny13.</p>
<p>The microcontroller has 32 registers in the memory (if you don't believe me see page 1 in datasheet) and these can be used to store numbers (remember max is 255). These registers are actually called general purpose registers, because they are quickly accessible for the microcontroller. These 32 registers also each have a name, like R6 or R20, but because this isn't very clear when making a program, you can define a different name. That is where the ".def mp = r16" stands for. It says, mp is register 16. This part of the code does nothing yet, it is only for the compiler again. Why r16 and not r1 you might ask. This is because r1 up to and including r15 are different type of registers. Later on I'll tell what the difference is.</p>
<p><strong>rjmp main</strong>, ah yes, our first real command to the microcontroller. These things are actually called instructions and the microcontroller knows around 120 of them. There is .pdf or an online page from Atmel where you can find them all, <a href="http://support.atmel.no/knowledgebase/avrstudiohelp/mergedProjects/AVRASM/AVRASM.htm" target="_blank">here</a>, I suggest to bookmark this page. One thing you need to remember right away is that an instruction takes up a 'cycle'. This cycle is like a 'tick' or 'tock' from the microcontroller and takes time to perform. How much time? This depends on the speed of the microcontroller.</p>
<p><img class="alignleft size-full wp-image-162" title="That's fast..." src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/miliseconds-bullet.jpg" alt="That's fast..." width="150" height="106" />The factory default is 9.6 Mhz for the ATtiny13 (ATtiny2313 is 8Mhz). You can change this speed. Hz means how often something happens in a second. So 1 Hz means, for example, 1 tick in a second. 3 Hz means 3 ticks in second. This also means that: 1 second / 3 ticks = 0.333... seconds for each tick. So now get our 9.6 Mhz (where M stands for Million), we get 1 / 9600000 = 1.04e-7 seconds for one cycle. That is very fast, to be precise, 0.10416 <strong>µ</strong>s (micro seconds, <a href="http://en.wikipedia.org/wiki/Micro-" target="_blank">more info</a>) for a cycle. Too bad this is not correct. The microcontroller also has a divider, which is default on 8. So 9.6Mhz / 8 = 1.2 Mhz. Which is 1 / 1.2 = 0.83333... µs for one cycle.</p>
<p>So this 'rjmp main' instruction takes 0.83 µs to perform, right? No sorry, if you look at the online instructions page you can find that it takes 2 cycles to perform, which mean 1.67 µs. These timings might look unimportant now, but when you for example want to make an infrared remote, they need to be very precise, which you luckily now can calculate. <img src='http://attiny13.lars.stonerocket.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>On the online instruction page you might also have found what the instruction 'rjmp main' does, it is very simple. It jumps to the label 'main', which is a bit further down in the program code and looks like "main:". Oh wait, it is right below it... haha. That's no really useful, because the code when run by the microcontroller goes from top to bottom, so it automatically gets to label main. You can safely remove rjmp main. However you will see later on that rjmp is a very useful instruction.</p>
<p>"<strong>main:</strong>" is just a label where the microcontroller can jump to when running the code. You can name these labels how you like, but only use normal words. In this main label we will find the line "<strong>ldi mp, 0b00001000</strong>". You might by now recognize the 8 bit here with the 0b (for binary) in front of it. The ldi means to store the value after the comma (,) to the register mp (which is actually r16). So after this line is run by the microcontroller (which takes one cycle, 0.83 µs) your little microcontroller memory register has a new value of 00001000. Yeah!</p>
<p>The next line is where we meet our DDRB again. "<strong>out DDRB, mp</strong>" means put the value mp (00001000) in DDRB register. As you notice, instruction for ATtiny go from right to left. The right value or register (after the comma ,) goes to the left register. Why not directly put 00001000 into DDRB? Like "ldi DDRB, 00001000"?, because it just cannot work. Your little microcontroller first needs to 'know' this value before it can use it. 00001000 means DDB3, which is PB3, just check page 56 in the datasheet.</p>
<p>We arrived at the next label "<strong>loop</strong>". In this label we meet a new friend the ldi. However this time it's written as LDI, this is no problem for the compiler, you can use lower or higher case. What this line does is giving the register mp (r16) a new value of 0x00. What is that? The 0x means hex and stands for hexadecimal notation. Which is a bit too much to explain <a href="http://en.wikipedia.org/wiki/Hexadecimal" target="_blank">here</a>. However I do want to mention that we now have had two ways of giving a value to a register. With binary and with hex. There is however a third one, simply with a number from 0 - 255. To convert a value from hex to decimal or the other way around, you can use the Windows calculator. Make sure that scientific option is turned on in the menu and after you entered a value (like 95) you press hex. Which gives you 5F. Cool, I just found out that it can do binary also. It is called bin on the calculator. Try it! Also try to change 255 and 256 (decimal) to binary and see what happens.</p>
<p>The next line "<strong>out portb, mp</strong>" makes the line before it more clearly. We are going to write the value of register mp (in binary, hex, decimal - 0b0000000, 0x00, 0) to PORTB. This means actually zero or that nothing will happen at all, haha. What a *great* instruction you might think, but this is required to make the LED blink. Turn on and off, this is the off part. If you see the next line "nop" and after that the other two instructions you will see that the PORTB will be put ON (high value). 0xff is 255.</p>
<p>The "<strong>nop</strong>" instruction is like what it sounds like, 'nope', 'nothing'. The microcontroller does nothing for a whole cycle. You wasted 0.83 µs of the microcontrollers time, al thought in timers it can sometimes be useful. Later on I will discuss a way to make a delay here instead of the nop and make the LED really blink.</p>
<p>The last nop has "<strong>; this is a comment</strong>" behind it. Whenever you use this character (;) everything behind it on the same line will be skipped by the compiler. Please use this often, if you don't comment your code and look at it again a month later on it won't make sense any more.</p>
<p>"<strong>rjmp loop</strong>" is the same as the "rjmp main" but now it is more useful, it will actually put the microcontroller in a loop by jumping to label loop, as you can see.</p>
<p>Readers that are paying good attention will notice that giving PORTB a value of 0xff (0b11111111 or 255) is a bit unnecessary. Only 0b00001000 is necessary, because this responds to port 3, which we also set in DDRB register. Well done! <img src='http://attiny13.lars.stonerocket.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now let's replace those nop delays with a real delay that will give you a clear blink. To do this, we need to let the microcontroller do something else, for few (mili)seconds, when the LED is turned on or off to get a nice blink. We could place thousands of nop's in the code, but that is not really smart and takes way too much Flash memory. We will create another loop, but this time the microcontroller will just count. You need to place this code at the top, but under .<em>def. </em>Also you need to replace the nop's with <strong>rcall delay</strong>. Which brings me  to quickly explaining the rcall instruction. What it does is the same as rjump, but it will return to where it jumped from after reading <strong>ret</strong>. However it won't work good, because now the microcontroller will start at delay, you need to add the line <em>rjmp main</em> back in the code. I think you can figure out where it needs to be put.</p>
<pre><code class="avrasm">delay:
	clr t1
	clr t2
	ldi temp, 100
delaywalk:
	;dec t2		;
	;brne delaywalk	; uncomment these for longer delay
	dec t1		; 256 x 100 x 3 = 76800 cycles
	brne delaywalk	; standard ATtiny13 clock is 9.6Mhz
	dec temp	; 9.6Mhz/8 (divider) = 1.2Mhz a cycle
	brne delaywalk	; total delay time = +/- 6 ms (with temp on 10)
	ret		; go back to where you came from</code></pre>
<p><strong>clr </strong>is short for clear and all it does is clear the register to zero. But wait, what is t1 or t2? That's just a name I made up for a register, but I haven't defined it yet. So what you need to do is add the following line at the top of your code, under the other <em>.def.</em></p>
<pre><code class="avrasm">.def t1 = r17
.def t2 = r18
.def temp = r19
</code></pre>
<p>You can search the other instruction if you don't understand them, but I do want to tell you what happens in the delay code. First the registers are cleared and register temp gets a value of 100, next we go to label delaywalk and there we decrease the register t1 with one (not t2, because it's commented out). The register was cleared, which means it is zero and if you subtract one of zero you get 255. <strong>brne </strong>means 'branch if not equal' and that means if the previous instruction is not equal (or zero) it branches. Branches means it goes to the label defined after brne and that is delaywalk. The instruction <em>dec</em> takes 1 cycle and <em>brne </em>when true (not a zero as result) it will take 2 cycles, so a total of 3 cycles. This means in total 256 x 100 x 3 = 76800 cycles. With 0.83 µs per cycle that is 63.744 µs, that is 64 ms. Of course this is not completely correct, because <em>ldi</em>, <em>out </em>and <em>rcall </em>also take up cycles, but not that much time.</p>
<p>You can get the total Assembly code here, <a href="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/the_code.zip">The Code</a></p>
<h1 style="text-align: center;">C</h1>
<p>Work in progress...</p>
]]></content:encoded>
			<wfw:commentRss>http://attiny13.lars.stonerocket.co.uk/2009/12/basics-programming-attiny13/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>VMLAB with ATtiny13</title>
		<link>http://attiny13.lars.stonerocket.co.uk/2009/12/vmlab-with-attiny13/</link>
		<comments>http://attiny13.lars.stonerocket.co.uk/2009/12/vmlab-with-attiny13/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 13:35:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[The Attiny13]]></category>

		<guid isPermaLink="false">http://attiny13.lars.stonerocket.co.uk/?p=169</guid>
		<description><![CDATA[VMLAB is a free tool that you can use to test your code virtually. Official website: http://www.amctools.com/vmlab.htm
VMLAB does not support the ATtiny13 official, but you can use the ATtiny12 as settings when creating a new project.
You also need the tn13def.inc in your project folder to make it work. You can get it here zipped, tn13def.inc
Now [...]]]></description>
			<content:encoded><![CDATA[<p>VMLAB is a free tool that you can use to test your code virtually. Official website: <a href="http://www.amctools.com/vmlab.htm" target="_blank">http://www.amctools.com/vmlab.htm</a></p>
<p>VMLAB does not support the ATtiny13 official, but you can use the ATtiny12 as settings when creating a new project.</p>
<p>You also need the <em>tn13def.inc </em>in your project folder to make it work. You can get it here zipped, <a href="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/tn13def.zip">tn13def.inc</a></p>
<p>Now let's get a simple example running. I will use the Assembly code used in the <em>Basics Programming ATtiny13</em> page on my site. For the fast people, get it here zipped, <a href="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/the_code.zip">The Code</a></p>
<p>The code is a fast ON and OFF signal on the pin PB3 of the ATtiny13.  For example making a LED blink. The pulse is calculated ±64 ms.</p>
<p>I used <a href="http://www.scienceprog.com/using-vmlab-as-virtual-oscilloscope/" target="_blank">this</a> tutorial as reference and adjusted it to my needs. When you made your project, add the following code to the project text.</p>
<pre><code class="dos">D1 VDD D1_NODE

R1 D1_NODE PB3 0.62K

.PLOT V(PB3)
</code></pre>
<p>The first line will make a diode (number 1) on node D1_NODE. The second line will make a resistor of 620 Ω on the same node and connect to pin PB3. The plot line makes sure the signal gets plotted in the scope. Here is how it looks:</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-184" title="layout" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/layout.png" alt="" width="245" height="170" /></p>
<p>Next we press <em>Build</em> and if everything goes OK you get success message and can press the traffic light. If you have no scope window, go to view menu and select it. The scope will show the image below, counting the spots you can see it is around 64 ms:</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-177" title="Scope results. It shows 64 ms ON/OFF." src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/12/scope-vmlab.png" alt="" width="547" height="415" /></p>
<p>When pressing Analyze you get 7.8 Hz. If we change that by 1/7.8 = .128... and divide that by 2, we get 0,06410 seconds. That is 64,1 ms. Right on the spot we calculated. Great!</p>
<p>I still got a lot to learn about VMLAB, but it shows great possibilities.</p>
<p>Thanks for reading. Got any crit or advise, please comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://attiny13.lars.stonerocket.co.uk/2009/12/vmlab-with-attiny13/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Hacking CD-ROM Player Part I</title>
		<link>http://attiny13.lars.stonerocket.co.uk/2009/11/hacking-cd-rom-player-part-i/</link>
		<comments>http://attiny13.lars.stonerocket.co.uk/2009/11/hacking-cd-rom-player-part-i/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 23:10:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[The Attiny13]]></category>

		<guid isPermaLink="false">http://attiny13.lars.stonerocket.co.uk/?p=59</guid>
		<description><![CDATA[The CD-ROM player (or DVD player) is a nice source for electronic parts and hacking. You can also learn a lot by taking a CD-ROM player apart. I do want to warn for the laser. If you have the player open and hook it up to power, make sure you disconnect the cable to the [...]]]></description>
			<content:encoded><![CDATA[<p>The CD-ROM player (or DVD player) is a nice source for electronic parts and hacking. You can also learn a lot by taking a CD-ROM player apart. I do want to warn for the laser. If you have the player open and hook it up to power, make sure you disconnect the cable to the head with the laser. Work on your own risk, I'm not responsible.</p>
<p>Without hacking you can still get some nice parts out of the player, here are some examples:</p>

<a href='http://attiny13.lars.stonerocket.co.uk/2009/11/hacking-cd-rom-player-part-i/small-dc-electric-motor/' title='small-dc-electric-motor'><img width="150" height="150" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/small-dc-electric-motor-150x150.jpg" class="attachment-thumbnail" alt="" title="small-dc-electric-motor" /></a>
<a href='http://attiny13.lars.stonerocket.co.uk/2009/11/hacking-cd-rom-player-part-i/bldc-electric-motor-cd-player/' title='bldc-electric-motor-cd-player'><img width="150" height="150" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/bldc-electric-motor-cd-player-150x150.jpg" class="attachment-thumbnail" alt="" title="bldc-electric-motor-cd-player" /></a>
<a href='http://attiny13.lars.stonerocket.co.uk/2009/11/hacking-cd-rom-player-part-i/buttons-cable-led-2/' title='buttons-cable-led'><img width="150" height="150" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/buttons-cable-led1-150x150.jpg" class="attachment-thumbnail" alt="" title="buttons-cable-led" /></a>
<a href='http://attiny13.lars.stonerocket.co.uk/2009/11/hacking-cd-rom-player-part-i/crystal-40mhz/' title='crystal-40mhz'><img width="150" height="150" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/crystal-40mhz-150x150.jpg" class="attachment-thumbnail" alt="" title="crystal-40mhz" /></a>
<a href='http://attiny13.lars.stonerocket.co.uk/2009/11/hacking-cd-rom-player-part-i/breadbord-pwm-attiny13-pnp/' title='breadbord-pwm-attiny13-pnp'><img width="150" height="150" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/breadbord-pwm-attiny13-pnp-150x150.jpg" class="attachment-thumbnail" alt="" title="breadbord-pwm-attiny13-pnp" /></a>

<p>- DC electric motors. Probably even two of them, one for opening the CD bay/tray, the other for moving the laser head;<br />
- Some small things, like buttons, LED's, cable (and connector). Also jumpers and audio connectors can be found;<br />
- Big electric motor, also BLDC called. It also has a strong magnet on it;<br />
- 40Mhz crystal;<br />
- hall effect sensor.</p>
<p>I have forgotten the laser, but it is dangerous. Damage to the eye cannot be fixed.</p>
<p>Al right, let's hack something. First we begin with something simple. The two DC motors look like fun and don't require much power to turn, you can easily run them directly on an ATtiny13, but I advice to use an extra transistor that gets the beating.  The ATtiny13 can serve as a PWM generator.</p>
<p>I have a nice and simple setup to do this:<br />
<img class="aligncenter size-full wp-image-72" title="breadbord-pwm-attiny13-pnp" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/breadbord-pwm-attiny13-pnp.jpg" alt="breadbord-pwm-attiny13-pnp" width="600" height="216" /></p>
<p>The big cable junk is just to program the ATtiny13. The long green wire goes from pin 2 (PB3 in code) to the NPN transistor base. The transistor is a BC549C, it can hold max. 500mA. There is a small diode at 25 to prevent things going wrong. The two 10 Ohm resistors is where you connect the plus of the DC motor. You can use this schematic also for a LED or buzzer.</p>
<p>Let's get some code to make simple PWM. I'm using Assembler. There will also be a post/tutorial on programming in Assembler.</p>
<pre><code class="avrasm">.include "tn13def.inc" 

.def mp = r16
.def temp = r17
.def t1 = r18
.def t2 = r19

rjmp main			; go to main

delay:
	clr t1			; clear register
	clr t2			; clear register
	ldi temp, 10		; set register temp (r17) to 10
delaywalk:
	;dec T2		; 256 x 3 x 10 = 7680 cycles
	;brne delaywalk	; uncomment these for longer delay (+160 ms)
	dec T1		;
	brne delaywalk	; standard ATtiny13 clock is 9.6Mhz
	dec temp	; 9.6Mhz/8 (divider) = 1.2Mhz a cycle
	brne delaywalk	; total delay time = +/- 6 ms (with temp on 10)
	ret		; go back to where you came from

main:
	ldi   	mp,0b00001000	; set 8 bit binary (note 8 numbers)
   	out   	DDRB,mp		; set pin 2 or PB3 to 'on'

loop:

LDI   mp,0x00     	; set register mp (r16) to value 00
OUT   PORTB,mp		; put 00 (low) value to port, means off		

rcall delay			; jump to/call delay

LDI   mp,0xFF     	; set register mp (r16) to value 255
OUT   PORTB,mp		; put 255 (high) value to port, means on		

rcall delay			; jump to/call delay

rjmp loop			; jump back to loop</code></pre>
<p>To make ON time longer than OFF time, you can simply put 'rcall delay' two times in the code or make a new delay branch.</p>
<p>That's all for part I. <img src='http://attiny13.lars.stonerocket.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://attiny13.lars.stonerocket.co.uk/2009/11/hacking-cd-rom-player-part-i/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Programming ATtiny13 with USBtinyISP</title>
		<link>http://attiny13.lars.stonerocket.co.uk/2009/11/programming-attiny13-with-usbtinyisp/</link>
		<comments>http://attiny13.lars.stonerocket.co.uk/2009/11/programming-attiny13-with-usbtinyisp/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 14:18:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[The Attiny13]]></category>

		<guid isPermaLink="false">http://attiny13.lars.stonerocket.co.uk/?p=9</guid>
		<description><![CDATA[Please note, I say ATtiny13, but this one is replaced with a newer ATtiny13a. There is also an ATtiny13v, this one is the same - only can run on lower voltage. 
To program the ATtiny13 or other AVR tiny microcontrollers I use the USBtinyISP. It is a diy build programmer, you can buy a package [...]]]></description>
			<content:encoded><![CDATA[<p><em>Please note, I say ATtiny13, but this one is replaced with a newer ATtiny13a. There is also an ATtiny13v, this one is the same - only can run on lower voltage. </em></p>
<p>To program the ATtiny13 or other AVR tiny microcontrollers I use the USBtinyISP. It is a diy build programmer, you can buy a package and you only need to solder. The nice thing is that it works with USB and can power the circuit directly. More information about the programmer can be found here: <a href="http://www.ladyada.net/make/usbtinyisp/" target="_blank">http://www.ladyada.net/make/usbtinyisp/<br />
</a><br />
I use Windows Vista for programming. USBtinyISP uses an USB driver to work under Windows. This works good on 32 bit Vista system, but on 64 bit system you need to disable Windows check of unsigned drivers. This can be done by pressing F8 during boot and selecting a boot option at the bottom. This needs to be done every time you want to program the microcontroller. Perhaps a reader knows a solution to that? Please post in the comments.</p>
<p>The USBtinyISP is cheap and works great. Here is an image of my simple set-up:</p>
<p><img class="aligncenter size-full wp-image-10" title="USBtinyISP Set Up" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/USBtinyISP_set_up.jpg" alt="USBtinyISP Set Up" width="400" height="359" /></p>
<p>To generate hex code for the microcontroller I use AVR Studio 4 (<a href="http://www.atmel.com/dyn/Products/tools_card.asp?tool_id=2725" target="_blank">website</a>). If you google, you can perhaps find a link where you don't need to sign up. Just press F7 to build. More on programming in an other post. You don't need to use AVR Studio 4, but I use it because it has projects option and you can simulate the ATtiny13.</p>
<p>To upload the hex code (with the instructions) I use avrdude, like suggested by the creator of USBtinyISP. You can download this program alone or with winavr.  I suggest to do it with winavr.  <a href="http://winavr.sourceforge.net/" target="_blank">http://winavr.sourceforge.net/</a> (On a side note: with winavr you can also generate machine code, hex)</p>
<p>Once you installed winavr, you got to use the command line of Windows to get avrdude working. Ladyada has a nice tutorial on this: <a href="http://www.ladyada.net/learn/avr/avrdude.html" target="_blank">link</a></p>
<p>The Ladyada tutorial covers a lot, but I do got some things to add. The connector/header for connecting ATtiny13 is like this:</p>
<p><img class="aligncenter size-full wp-image-14" title="header-6-pin-connection" src="http://attiny13.lars.stonerocket.co.uk/wp-content/uploads/2009/11/header-6-pin-connection.png" alt="header-6-pin-connection" width="395" height="283" /></p>
<p>If you connect the programmer and the microcontroller like me on a breadboard, you don't need to unplug it every time. Just leave it where it is and you can use the different ports (see above, PB0 to PB5) .</p>
<p>Windows has a nice option to make use of .bat files, which stands for batch. I made a small .bat file that you can use to program the microcontroller without having to type the avrdude command line over and over. The command line is like so:</p>
<pre><code class="dos">avrdude -c usbtiny -p attiny13 -U flash:w:fade.hex</code></pre>
<p>You should rename "fade.hex" to the real name of your .hex file.</p>
<p>To make the .bat file, you need to adjust the lines below and save the text in a notepad.txt file, which you rename to .bat.</p>
<pre><code class="dos">@ECHO OFF
ECHO Welcome Lars!
ECHO.
title Attiny Programming cmd.exe
avrdude -c usbtiny -p attiny13 -U flash:w:fade.hex
ECHO.
pause</code></pre>
<p><strong>What it will do is this:</strong><br />
- Start cmd.exe<br />
- Display the text "Welcome Lars!". (You can change this of course)<br />
- The cmd.exe has the title "Attiny Programming cmd.exe".<br />
- Avrdude is run with options to program<br />
- After avrdude is done you will only need to press enter to exit cmd.exe. By removing "pause", you don't need to press enter, but if there was an error you won't see it.</p>
<p>Make sure you have the .hex file in the same folder as the .bat file, else it won't work.</p>
<p><strong>When you get error from avrdude, you can try this:</strong><br />
- Reconnect the USB cable<br />
- Remove heavy load on the microcontroller</p>
<p>Thanks for reading. If you have questions about the USBtinyISP, you can better use their forums: <a href="http://forums.adafruit.com/index.php" target="_blank">http://forums.adafruit.com/index.php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://attiny13.lars.stonerocket.co.uk/2009/11/programming-attiny13-with-usbtinyisp/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Work in progress</title>
		<link>http://attiny13.lars.stonerocket.co.uk/2009/11/work-in-progress/</link>
		<comments>http://attiny13.lars.stonerocket.co.uk/2009/11/work-in-progress/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 12:03:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[The Attiny13]]></category>

		<guid isPermaLink="false">http://attiny13.lars.stonerocket.co.uk/2009/11/work-in-progress/</guid>
		<description><![CDATA[This website is still work in progress...
Most of it is working, like a good looking theme.
Keywords:
Attiny13
Atttiny13a
Atttiny13v
At tiny 13 a
At tiny 13 v
atiny13
atttiny13
atttiny13a
atttiny13v
tiny13
tiny13a
tiny13v
]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: line-through;">This website is still work in progress...</span></p>
<p>Most of it is working, like a good looking theme.</p>
<p><strong>Keywords:</strong></p>
<p>Attiny13<br />
Atttiny13a<br />
Atttiny13v<br />
At tiny 13 a<br />
At tiny 13 v<br />
atiny13<br />
atttiny13<br />
atttiny13a<br />
atttiny13v<br />
tiny13<br />
tiny13a<br />
tiny13v</p>
]]></content:encoded>
			<wfw:commentRss>http://attiny13.lars.stonerocket.co.uk/2009/11/work-in-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
