loading

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

<p>Assalaamu 'Alaikum Wa Rahmatullah,</p><p>i have no question i am new to this. i have AVR dragon with ATmega 16 and i was wondering if i can use Arduino RFID reader which i also have . just need guidance to get started </p>
<p>good job mr</p>
<p>Arduino: 1.6.10 (Windows 10), Board: &quot;Arduino Y&uacute;n&quot;</p><p>Warning: Board arduino:avr:atmega16-8 doesn't define a 'build.board' preference. Auto-set to: AVR_ATMEGA16-8</p><p>&lt;command-line&gt;:0:21: warning: missing whitespace after the macro name</p><p>C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp: In function 'void serialEventRun()':</p><p>C:\Program Files\Arduino\hardware\arduino\avr\cores\arduino\HardwareSerial.cpp:72:2: error: 'config' was not declared in this scope</p><p> config |= 0x80; // select UCSRC register (shared with UBRRH) </p><p> ^</p><p>exit status 1</p><p>Error compiling for board Atmega16 (internal 8MHz clock).</p><p>This report would have more information with</p><p>&quot;Show verbose output during compilation&quot;</p><p>option enabled in File -&gt; Preferences.</p>
<p>how to don this process on ubuntu ?????</p>
<p>Gan Ekhiw</p><p>Mau tanya, Kenapa proses upload nya error, padahal saya sudah ikutin dari <a href="http://hardwarefun.com/tutorials/use-arduino-as-an-isp-programmer-to-program-non-arduino-avr-microcontrollers." rel="nofollow">http://hardwarefun.com/tutorials/use-arduino-as-an...</a> error nya seperti ini avrdude: stk500_recv(): programmer is not responding</p><p>avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x03<br>avrdude: stk500_recv(): programmer is not responding<br>avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x03<br>avrdude: stk500_recv(): programmer is not responding<br>avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x03<br>avrdude: stk500_recv(): programmer is not responding<br>avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x03<br>avrdude: stk500_recv(): programmer is not responding<br>avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x03<br>avrdude: stk500_recv(): programmer is not responding<br>avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x03<br>avrdude: stk500_recv(): programmer is not responding<br>avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x03<br>avrdude: stk500_recv(): programmer is not responding<br>avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x03<br>avrdude: stk500_recv(): programmer is not responding.</p><p>mohon solusi nya gan</p>
<p>Thank you! </p>
<p>Hi, I tried to upload the blink LED code and getting this error</p><p><strong>&quot;Error while uploading: missing 'upload.tool' configuration parameter&quot;</strong></p><p>What to do?</p>
What programer do you use?USBASP or arduino as programer?<br>if you use usbasp make sure you already install the driver,you can get the driver in here http://www.fischl.de/usbasp/ <br>if you already install the driver make sure in the board.txt has <br>atmega16-12.upload.tool=arduino write in it<br>or atmega16-12.upload.tool=avrdude(if you use usbasp)<br>and dont forget to choose upload using programer in Arduino IDE
<p>Thanks for the reply.</p><p>I took help form http://openhardware.ro/using-atmega16-with-arduino-ide/ and now I can upload any sketch to Atmega16.</p>
<p>good..<br>thanks for sharing smandal13</p>
<p>om, di videonya ada atmga16 12mhz. itu yang dimodifikasi apanya? </p>
itu cuma diganti fusebitnya<br>coba pake <br>lowfuse=0xFF<br>highfuse=0xDF
Good job dude
makasih gan
<p>Very nice coding job, this project has some great possiblities! </p>
<p>thanks,now we can have a DIY Arduino board :) </p>

About This Instructable

22,077views

28favorites

More by ekhiw:IoT : Androino Doorlock Programming ATmega16A using arduino IDE 
Add instructable to: