Atmel AVR ATmega16 Programmer
Atmel AVR ATmega16 Programmer
This is one of the simplest low cost programmers for the Atmel ATmega series.
If a Flash program memory PIC like the PIC16F876 is not enough (RAM size, I/O port
pins etc.), the Atmel ATmega microcontrollers are really handy - especially the
ATmega16 with 40pins (I2C, SPI, USART, A/D, 2 external interrupts, PWM etc.). The
hardware is pretty straightforward. It is based on the "DAPA - Direct AVR Parallel
Access" idea - you can use any programmer software as long as DAPA is supported.
It's tested with the ATmega16 and "uisp" on Linux, but it should work with any Atmel
uC which supports SPI based in-circuit software programming and any programmer
software which supports the DAPA interface. This programmer should work with the
pin-compatible ATmega32 without any modifications, but I have not tested that.
Hardware:
Software:
Software development can be done in either assembly language or with a C
compiler. I prefer C, even for microcontrollers, and the excellent news is that there is
support for the AVR devices in GCC. There are packages for most linux distros, just
look for avr-gcc. It is also available for windows, see below.
The software for programming the ATmega16 with this programmer on Linux is
"uisp" (packages available for most linux distros) - there is also a windows version
of "uisp". It is included in the "windows version of avr-gcc".
As soon as you've connected your programmer to the parallel port and switched on
power, you can test the hardware with:
# uisp -dprog=dapa
Atmel AVR ATmega16 is found.
Make sure you have a current version of uisp. If the output is like "Atmel AVR similar
to the ATmega161 is found." or it doesn't recognize the device at all, install a new
version of uisp. "testing" for Debian is just fine. See troubleshooting for more error
messages.
As you recognized, there is also a LED in the programmer schematic. It is only used
for testing the programmer with this simple program - avrledtest.c:
#include <avr/io.h>
while (outer1) {
outer2 = 1000;
while (outer2) {
while ( ms ) ms--;
outer2--;
}
outer1--;
}
}
int main(void)
{
/* enable PD5 as output */
sbi(DDRD,PD5);
while (1) {
/* led on, pin=0 */
cbi(PORTD,PD5);
delay_ms(500);
/* set output to 5V, LED off */
sbi(PORTD,PD5);
delay_ms(500);
}
return 0;
}
all: avrledtest.hex
avrledtest.hex : avrledtest.out
$(OBJCOPY) -R .eeprom -O ihex avrledtest.out avrledtest.hex
avrledtest.out : avrledtest.o
$(CC) $(CFLAGS) -o avrledtest.out -Wl,-Map,avrledtest.map avrledtest.o
avrledtest.o : avrledtest.c
$(CC) $(CFLAGS) -Os -c avrledtest.c
clean:
rm -f *.o *.map *.out
Issue "make" to compile and "make load" to program the uC with uisp.
avrledtest.c and Makefile based on avrledtest by Guido Socher - Programming the
AVR Microcontroller with GCC.
TROUBLESHOOTING:
If /dev/parport0 is not found
# uisp -dlpt=/dev/parport0 -dprog=dapa -dpart=ATmega16 --rd_fuses
/dev/parport0: No such file or directory
Failed to open ppdev.
My choice: 1 1 1 1 1 1 1 1 = 0xFF
Fuse High Byte Bit No. Description Default Value
OCDEN 7 Enable OCD 1 (unprogrammed, OCD
disabled)
JTAGEN 6 Enable JTAG 0 (programmed, JTAG
enabled)
SPIEN 5 Enable SPI Downloading 0 (programmed, SPI prog.
enabled)
CKOPT 4 Oscillator options 1 (unprogrammed)
EESAVE 3 EEPROM memory is preserved 1 (unprogrammed, EEPROM
not preserved)
BOOTSZ1 2 Select Boot Size 0 (programmed)(3)
BOOTSZ0 1 Select Boot Size 0 (programmed)(3)
BOOTRST 0 Select reset vector 1 (unprogrammed)
My choice: 1 1 0 0 1 0 0 1 = 0xC9
Troubleshooting uisp:
If you get