SaltForTheThirsty

RawDawg'nTheArduino()

Lesson 0

Shows you how to get Atmel Studio set up on your computer. Blinks an LED to show everything is set up properly. You will 2 Arduinos. One of them will be your ISP (In System Programer). This lessons expects to have familiarity with the Arduino.

Raw Dawg'n the Arduino - Lesson 0

Download Files.
    
/* Raw Dawg'n the Arduino Lesson 0 Tools and Software Download and install Atmel Studio 7 web installer http://studio.download.atmel.com/7.0.2397/as-installer-7.0.2397-web.exe offline installer http://studio.download.atmel.com/7.0.2397/as-installer-7.0.2397-full.exe Download and install (unzip) avrdude https://sourceforge.net/projects/avrdudegui/files/latest/download I'm assuming you have the Arduino IDE already installed. You will need two Arduinos. One you will be your ISP (In System Programmer). The other will be the one you are working/playing with. The Arduino IDE includes a sketch called ArduinoISP (File -> Examples -> ArduinoISP). Upload this sketch to one of the Arduino's. This will be the ISP, i.e what you use to program the other Arduino. Open Atmel studio and select new project (File -> New -> Project). Select GCC C Executable Project from the popup window. Name the project Lesson0 and click OK. Select the microcontoller that is installed in your Arduino. ATMEGA2560 for the mega or ATMEGA328P for the UNO. Click OK. This creates a file called main.c It will already have some stuff in it. replace it with the following: */ #include <avr/io.h> // this file contains all the human readable names for the registers/ports #include <util/delay.h> // this is the header file for the _delay_ms() function // all c programs must include the main() function int main(){ /* DDRD Data Direction Register PORTD setting the bits to 1 makes the corresponding pins an output. Setting to 0 makes them an input. 0xFF = 0b11111111, we are setting all 8 pins on PORTD as output. You can connect and LED to any pin on PORTD and watch it blink. DON'T FORGET THE CURRENT LIMIT RESISTOR */ DDRD = 0xFF; while(1){ PORTD = 0xFF; _delay_ms(250); PORTD = 0x00; _delay_ms(250); } } /* while(1): while evaluates an the expression inside of (). If true (ie not 0) the while loop will execute. If false (0) the while loop will not execute. Microcontrollers typically perform the same tasks over and over and never terminate from the main loop. Since the expression (1) will never be 0 or false this while loop will always get executed. This is equilivant to the Loop() in the Arduino sketches. writing a 1 to an output port puts the voltage high, writing a 0 pulls the voltage low. */ /* Select Project -> Lesson0a Properties. This will bring up Properties. Change Configuration from debug to release. You will now have to tell the compliler the CPU frequency. The Arduino has a 16 MHz clock. Select Toolchain from the left hand side and then click symbols from the middle column. Click on the '+' icon on the right hand side of Define symbols (-D) and type "F_CPU=16000000UL" in the pop up. Click OK. Save main.c. Now build the project. Build -> Build Solution. The build process should create a file called main.hex. This is the file you will upload into the Arduino. Open up AVRDUDE. Select ATMEGA2560 as the target device. Select Lesson0a.hex for the FLASH file. It is probably located at: Documents -> Atmel Studio -> 7.0 -> Lesson0a -> Lesson0a -> Release -> Lesson0a.hex. The Arduino web site shows how to physically connecto the ISP to the Arduino. https://www.arduino.cc/en/Tutorial/ArduinoISP.