AVRing
Posted on 12.23.09 3:28 PM under Electronics, Microcontrollers
Softrock is behaving well, but propagation has been poor. So naturally I’ve turned my attention elsewhere…. for now!
I’ve always been into microcontrollers and have played with the arduino line of open source prototype platforms quite a bit. The problem is, I always feel like I am not really programing the AVR atmega chips – instead there is another layer of abstraction (the arduino programming language).
I bought a few atmega168 chips a while back and a USBtinyISP programmer kit from LadyAda. I got to building the programmer which was really easy – it took about 30-40 minutes. I also followed the instructions on LadyAda’s site to get the compiler and programmer software (avrdude) working on my Mac laptop – again, very easy, at least for me.
Remarkably I found it tricky to hook up the programmer to the chip – which is surprising since the atmega chips are in circuit programmable. Evilmadscientist has a nice page up though, which explained how to connect the programmer pin outs to the chip pins. The picture below might help anyone else who is confused. LadyAda should really document this on her site!

Now, when I checked the pinout on my cable it seemed to be backwards from the one above. That is, colmns 1 and 2 were flipped. I probably installed the ribbon cable wrong on Ladyada’s programmer. Anyway, I suggest others check before programming a chip. Just check where you have 5V and ground.
#include
int main (void)
{
DDRB |= 0b00000011; // Set LED as output
TCCR1B |= (1 << CS10); // Set up timer
PORTB = 0b00000010; // turn PB1 on, turn PB0 off
uint8_t i = 0;
for (;;) {
// Check timer value in if statement, true when count matches 1/20 of a second
if (TCNT1 >= 49999) // 49999 normal -- 20 Hz flash
{
if ( i >= 10 )
{
PORTB ^= 0b00000011; // Toggle the LEDs: 0 -> 1 or 1 -> 0 through the
// xor statement
i = 0;
}
else
{
i++;
}
TCNT1 = 0;
}
}
}

Post Comments
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
* Required. Your email will never be displayed in public.