Question about the differences between AVR and Arduino code instructions

Discussion in 'Embedded Systems and Microcontrollers' started by Snowfish, Aug 25, 2017.

  1. Snowfish

    Thread Starter Member

    May 11, 2017
    42
    1
    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
     
  2. freak101

    Member

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

    Moderator

    Aug 21, 2008
    5,487
    1,709
    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.
     
  4. simozz

    Member

    Jul 23, 2017
    99
    26
    Hello,
    No, use avrlibc instead.
    simozz
     
    Last edited: Aug 25, 2017
  5. be80be

    AAC Fanatic!

    Jul 5, 2008
    1,770
    348
    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 (Text):
    1. /* Arduino Uno Blink sketch for use with the empty core */
    2.  
    3. #include <avr/io.h>
    4. #include <stdint.h>
    5.  
    6. int led = 5; // In port B
    7.  
    8. void setup() {              
    9. DDRB = DDRB | 1<<led;         // Define PB5 as an output
    10. }
    11.  
    12. volatile long Counter;
    13.  
    14. void delay (long n) {          // Delay by n milliseconds
    15. Counter = 469 * n;
    16.   do Counter--; while (Counter != 0);
    17. }
    18.  
    19. // The loop routine runs over and over again forever:
    20. void loop() {
    21.   PORTB = PORTB | 1<<led;      // Take PB5 high
    22.   delay(1000);                 // Wait for a second
    23.   PORTB = PORTB & ~(1<<led);   // Take PB5 low
    24.   delay(1000);                 // Wait for a second
    25. }
    26.  
    27. // We need main()
    28. int main() {
    29.   setup();
    30.   for(;;) loop();
    31. }
     
    DickCappels likes this.
  6. DickCappels

    Moderator

    Aug 21, 2008
    5,487
    1,709
    One of the great things about this forum is that there is a chance to learn something every day.
     
  7. philba

    Active Member

    Aug 17, 2017
    959
    302
    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...
     
Loading...