Question about the differences between AVR and Arduino code instructions

Thread Starter

Snowfish

Joined May 11, 2017
42
Hi

I am new with micro controllers. I would like to know if we can use the same exact C code from an Arduino to program an AVR micro controller from AVR Studio? Do they use the same C language instructions in their ‘’Studio sofware’’ ? If not, how much different are the code instructions between those 2?

Thank you
 

freak101

Joined Aug 7, 2017
37
AVR-GCC lacks the libraries that arduino has. However you can program a non-arduino microcontroller by arduino IDE with some tweaks.
 

DickCappels

Joined Aug 21, 2008
6,655
Not exactly. You can program an AVR with the hex file complied under Arduino as long as it is the same kind of AVR controller targeted by the origional program.
 

be80be

Joined Jul 5, 2008
2,049
Kind of funny but atmel studio The latest one lets you import arduino code.

But you can use arduino without the cores and code just as you would with avr-gcc=4.9.2

Like this
Code:
/* Arduino Uno Blink sketch for use with the empty core */

#include <avr/io.h>
#include <stdint.h>

int led = 5; // In port B

void setup() {               
DDRB = DDRB | 1<<led;         // Define PB5 as an output
}

volatile long Counter;

void delay (long n) {          // Delay by n milliseconds
Counter = 469 * n;
  do Counter--; while (Counter != 0);
}

// The loop routine runs over and over again forever:
void loop() {
  PORTB = PORTB | 1<<led;      // Take PB5 high
  delay(1000);                 // Wait for a second
  PORTB = PORTB & ~(1<<led);   // Take PB5 low
  delay(1000);                 // Wait for a second
}

// We need main()
int main() {
  setup();
  for(;;) loop();
}
 

philba

Joined Aug 17, 2017
960
that's good to know about atmel studio. .

One point to remember, each library will need to be inspected to see if it will work on the target avr. Probably most will be fine with maybe some pin redefinitions but some may need significant rework.

It would be wonderful if there was an arduino "core generator". Especially for the ARM chips...
 
Thread starter Similar threads Forum Replies Date
L Homework Help 9
RamboCircuits2020 General Electronics Chat 6
N Test & Measurement 36
G Homework Help 7
elway Homework Help 3
Top