2017-2018 TEI4M AVR Assembly Challenges

Challenge 5. TBA

Challenge 4. TBA

Challenge 3.TBA

Challenge 2. Rotary Encoder: Gray Code. You have been provided with a mechanical rotary encoder that places its 4-bit Gray Code on four pins (8-4-2-1) each routed through a fifth common pin (C). In this challenge you are to develop AVR Assembly code that will read and display the four bit output of the encoder on your Double Dabble prototype. Note: You MUST use the Convert>Display blocks that we developed in class together last Thursday. This Challenge requires that you add an Input block to complete the trio.


  1. Wire the output of your encoder into the Arduino digital pins 1-4 (avoiding pin 0 as it complicates matters) such that encoder weights 8-4-2-1 map to the Ardiuino's digital pins 4-3-2-1 (PORTD). Since there is only a single common pin on the encoder, pull down or pull up resistors (your choice) ARE required so the output doesn't float.
  2. Create an ATMEL Studio 7 Project entitled GrayCodeChallenge and the GrayCodeChallenge.asm source file that reads the encoder's output, sends it through your DoubleDabble algorithm, and continously displays the output on your seven-segment display.
  3. Rather than try to implement a Gray Code to Binary Conversion algorithm, for the purpose of this single period challenge, you are encouraged to place the binary equivalents of the Gray Codes in a table (array) at the start of your code (much the same as we did for the Hex Animation Project practice exercise) and simply look up the equivalent binary value before sending it through to the rest of your Double Dabble algorithm. (If you are sufficiently motivated in the days ahead, take on the additional challenges of Binary↔Gray Code conversions)
  4. At the end of the 60-minute period, attach your source code only (GrayCodeChallenge.asm) to an email to handin under the Subject Line: Gray Code Challenge (Code). I'm going to run it through my circuit to evaluate this stage.
  5. By this Saturday (January 20), develop and submit a comprehensive ER summary entitled Gray Code Challenge. Submit to handin under the Subject Line: Gray Code Challenge (ER).

Challenge 1. Rotary Switch Monitor. For your first assembly language challenge you are to CONTINUOUSLY monitor a BCD rotary switch in the manner described. If there are an EVEN number of set bits in the BCD value read, your bicolor LED should show red, otherwise it will show green. You will use the ATtiny85 for this challenge. To simplify the matter somewhat you are only required to monitor the BCD values from 0 to 7 inclusive.The BCD value is to be read on pins 0-2 and your bicolor LED will span pins 3 and 4, with the longer lead in pin 3.


  1. Familiarize yourself with the rotary switch provided (https://www.digikey.ca/products/en?keywords=428527420910-ND)
  2. Breadboard the circuit using parts from your toolkit and any extra components supplied.
  3. You may wish to grab a DMM if it would help.
  4. Within the file RotaryMonitor.S, develop, test, and document pure AVR assembly code (no Arduino C code) to meet the requirements above.
  5. Use your phone to capture images and video of your circuit in action for your ER.
  6. At the end of the challenge period, attach RotaryMonitor.S to an email to handin under the Subject Line: Challenge 1 (Code) and leave your circuit in the box on the center table.
  7. By midnight tomorrow night (Saturday December 2), develop and submit a comprehensive ER report (don't forget to include your fully documented Code) under the Subject Line: Challenge 1 (ER).
ATtiny85 10 Position BCD Rotary DIP Switch