Introduction: Programming ATmega16A Using Arduino IDE

Assalamualaikum warahmatullahi wabarakatuh

Hi,my name is Ekky Hermestian IW from Indonesia

This tutorial will show you how to program an ATmega16 using Arduino IDE

We can use syntax like

pinMode()

digitalWrite()

digitalRead()

and many more using non-Arduino AVR microcontrollers.

I usually program ATmega16 using CodeVisionAVR and i must define PORT and DDR, but in Arduino will automatically define the PORT and DDR using pinMode() syntax and when we want to set pin to high in CVAVR we must write PORTB.5=1 but in arduino is more simply just like digitalWrite(13, HIGH).

Step 1: Pin_arduino.h

arduino uno is using ATmegaxx8 and define the port using numer so we can easily use it

that proses is stored in Pin_arduino.h

we can find the file in this path C:\Program Files\Arduino\hardware\arduino\avr\variants\standard

open Pin_arduino.h and we will see how arduino convert PORT and DDR

then we need to change the following things before we can use arduino on ATmega16.

  • The number of digital pins
  • The number of analog pins
  • Analog pin mappings and const for Analog pins (actual values for A0, A1)
  • Digital pin to PCICR mapping
  • Pin to port (PORTA, PORTB etc) mapping
  • Pin to timer mapping

Most of these are straight forward and we can get the correct values from the target AVR chips datasheet.

Step 2: Board.txt

To let the Arduino IDE, know about our new microcontroller, we need to create a newboards.txt file which has the following information about the microcontroller.

  • Upload protocol
  • Upload speed (baudrate)
  • Upload fusesClock frequency
  • Maximum flash memory size
  • Which variant (pins_arduino.h) file to use

Like the pins_arduino.h file

Step 3: Put It Together

Put the pin_arduino.h in C:\Program Files\Arduino\hardware\arduino\avr\variant\mega16

and copy board.txt to C:\Program Files\Arduino\hardware\arduino\avr

now we put board.txt and pin_arduino.h to arduino instalation folder and we already to use our arduino code to ATmega16

Step 4: Lets Try

Now we can use example like blink led

i connect led to pin 16 (PORTC.0) and ground and i use USBASP to upload the program

i still didnt understand why delay take so long,but i think because i use crystal 12Mhz while in Arduino UNO using 16Mhz

i attach my Minimumsystem schematic

sorry for my bad english

i made this instructable from this Hardwarefun-Use Arduino code in non-Arduino AVR microcontrollers

and i really thanks to Sudar as post author at hardwarefun,Raka Fahriza as Cameraman

Thanks for your attention