GithubHelp home page GithubHelp logo

arduino-with-c-and-asm's Introduction

Miscellaneous Arduino projects in C and ASM

These are notes on how to build and make working projects without involving any IDE magic using only C/C++ compiler, Assembly and flashing.

Toolchain

toolchain

Assembly syntax

There are a few different assembly languages available to choose from:

  • GNU's Assembler (avr-as);
  • Gerd's AVR Assembler (gavrasm)
  • Assember for the Atmel AVR microcontroller family (avra)
  • Atmel's Assembler (part of Atmel Studio)

They each have slightly different syntaxes and command lines for getting the source assembled. Here's a minimal example for each; they turn on pin PB5 (digital pin 13, which had an LED connected to it on the board).

Assembly Code/Command Line Notes
GNU's TODO: GNU's assembler is conveniently included in the CrossPack package for Mac OS X, WinAVR for Windows, and the gcc-avr packages on various Linux distributions. Unfortunately, it has awkward syntax, requiring _SFR_IO_ADDR() around the names of the I/O registers. Confusingly, you'll need to compile your code with avr-gcc, even though it's assembly. If you try avr-as, you'll get a message like "Error: constant value required".
avr-gcc -c -mmcu=atmega328p -o code.o code.S
avr-objcopy -j .text -O ihex code.o code.hex
        
      
avra
;specify the device:
.device ATmega328P
;OR use definition:
;.include "./m328Pdef.inc"
    sbi 0x24, 5
    sbi 0x25, 5
loop:
    rjmp loop  ; pevents running out
Another open-source assembler that is compatible with Atmel's AVRASM32. It has the advantage of being written in C, so you can compile it with the standard development tools (e.g. Xcode on the Mac). There are also Windows binaries available. You will need to download or define yourself macros for your chip (included in AVR Studio). For instance, avra doesn't support newer AVRs like the ATtiny44A that was on our boards this week. To use it, you'll need the .inc file for your microcontroller (e.g. tn45def.inc for the ATtiny45). And then you could use defined macros instead of absolute addresses, for example, in case of ATmega328P, using "m328Pdef.inc", DDRB instead of 0x24.
avra code.asm
        
      
Atmel's Assembler
;specify the device:
.include "m328Pdef.inc"
    sbi DDRB, 5
    sbi PORTB, 5
loop:
    rjmp loop  ; pevents running out
The official (Windows only) AVR assembler from Atmel (avrasm). You should be able to compile your code from within Atmel Studio.

More Reading

arduino-with-c-and-asm's People

Contributors

nad2000 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.