Instructions

Now it is time to program your Arduino in Assembly! Follow these steps to get started:

  1. Start a new sketch.
  2. Delete (or comment out) all content in the .ino file.
  3. Above your code, you should see the name of the .ino file on the left side. Go to the right side and you should see three dots. Click those dots and select “New Tab”.
  4. You name the new tab “main.S”. NOTE: the S must be capital!
  5. Begin your assembly file (main.S) with:
    #include <avr/io.h>
    .global main
    main:
  6. Now you can write your own code below “main:”.

The following deliverables should be completed entirely in assembly.

The datasheet for the ATMega2560 used in the Arduino Mega is here: https://www.microchip.com/en-us/product/atmega2560. If you have another version, you will need to make sure you find the correct datasheet.

The ATMega2560 to Arduino Mega pinout is here: https://docs.arduino.cc/retired/hacking/hardware/PinMapping2560/ Again, if you have something besides an Arduino Mega, you will need to find the appropriate pinout.

And the AVR assembly instruction manual is here: https://ww1.microchip.com/downloads/en/devicedoc/atmel-0856-avr-instruction-set-manual.pdf

Deliverable A

Write assembly code to turn an LED on when a button is pressed and off when the button is not pressed. You do NOT need to use interrupts for this deliverable unless you want to.

Deliverable B

Connect a potentiometer to an Analog pin on the Arduino. Write code that uses the potentiometer input to the Arduino to control the LED’s brightness from 0% to 100%. Note: this most be done in software, you cannot connect the LED directly to the potentiometer. It is acceptable is the LED dims but does not turn off at the lowest setting.

If you complete both deliverables, you only need to demonstrate B.

Turn in to Blackboard

A zip file with all code. This could be one sketch for each deliverable. (30 points)

Demo Rubric

5 points – Assembly code builds for Arduino
5 points – LED output
5 points – Any input (button or potentiometer)
5 points – Potentiometer input
5 points – LED brightness dependent on potentiometer
5 points – LED brightness smoothly transitions from dim to bright