CSE466 Lab 1: “One-Minute Timer”

Objectives

Create a device that will count from 00 to 59 on two 7-segment led displays at a rate of 1Hz. When the end of the count is reached, it should wrap around and start counting from the beginning. There will be an example setup in the lab that you can use as a reference.

In this lab you will learn the following:

Reading

Helpful Hints

Resources

Part 1: Wiring up the breadboard

  1. Wire the circuit in the schematic on your breadboard. Make sure the power is disconnected when wiring up your breadboard.
  2. The 7-segment LEDs displays are not connected to the ATmega16 in the schematic. You and your partner will need to decide how to connect the 8 wires from the ATmega16 to the 7-segment LED displays. The wiring pattern used should be exactly the same for both of the 7-segment displays allowing the same constant to be used when displaying numbers. Also note that the 7-segment LED displays combine to make the number (one will represent the tens digit and the other will represent the ones digit). To make the actual value of the counter easy to read it would be nice if the 7-segment LEDs were either next to each other or aligned so the bottom of the 7-segment LEDs were parallel.
  3. The resistors values have been purposefully left off the schematic. You will need to consult the datasheet to find the chip’s electrical characteristics to determine the appropriate values of the reset pull-up resistor and the current limiting resistors for the LEDs. For decent brightness the 7-segment LEDs should have around 5mA of current.

Question 1: What is the appropriate range of values for the reset pull-up resistor? (Refer to datasheet)

Question 2: Calculate the theoretical amount of current flowing through a single segment of the 7-segment LEDs when it is illuminated.  In your calculation use only values from datasheets or labels. Do not use any measured values in your calculation.

  1. Before powering on the breadboard, verify with a multimeter that there are no shorts between power and ground, and that power and ground are actually hooked up to the chips' pins.
  2. Power on your breadboard and connect the serial cable from your computer.
  3. To verify your hardware is working properly program your wired up breadboard with flash.hex. (This program should cause your 7-sement LEDs to flash “88”)
  4. The ATMega16 is programmed via an application called MegaLoad. When the ATMega16 is reset, it attempts to communicate with MegaLoad over the serial port to upload the specified hex file. NOTE: This communication can cause a delay when resetting the ATmega16 as it will attempt to communicate with MegaLoad before executing your program. (the delay is especially long when MegaLoad is not running because of the timeout)
    To upload a program to the ATmega16:
    1. Open MegaLoad (c:\program files\microsyl) and select the hex file you want to upload to the flash of the ATmega16.
    2. Reset the ATmega16 (this will cause the communication to begin).

Part 2: Create a simple program in Assembly

  1. Open AVRStudio 4 and follow these instructions to setup a new project:

 

  1. Click on the “Create New Project” button that is on the window that appears when it opens.

 

  1. The Project Type is “AVR Assembler”. Give the project a name and change the location to a lab partner’s network share. Then hit next.


 

  1. Select “AVR Simulator” as the Debug Platform and “ATmega16” as the Device then hit finished.



  1. You should also verify that you output will be in .hex so go to the Project menu and select AVR Assembler Setup. The Additional Output file format should be set to “Intel intellec 8/MDS (Intel hex)”.

 

  1. Copy the following code to the assembly file. (The code should display an “8” on one of the 7-segment LEDs)

 

.include "C:\Program Files\Atmel\AVR Tools\AvrAssembler\Appnotes\m16def.inc"

.cseg

ldi r16, 0xff

out DDRB, r16

ldi r16, 0x00

out PORTB, r16

loop:

jmp loop

 

  1. Build the hex file and upload it to the ATMega16 via MegaLoad.

 

  1. Modify the code to determine the constants needed to generate the other 9 numbers on the 7-segment LED displays.

Part 3: Create a BCD Counter in Assembly

Write a program in assembly that will count from 00 to 59 on two 7-segment led displays (one will be the tens digit and the other will be the ones digit). Implement a lookup table in program memory to convert a 4-bit nibble (in binary) to a decimal number.  Use this skeleton program as a starting point.

Requirements:

  1. Use a lookup table in program memory to store the constants needed to generate the 10 digits (‘0’-‘9’) on a 7-sement LED. You will need to use the LPM instruction to load the constant from program memory. NOTE: The ATmega16 uses 16-bit instructions even though it is an 8-bit processor; therefore, the 256th instruction is actually located at memory address 512 and 513. Keep this in mind when declaring your constants in program memory. The code/instructions are two bytes wide (16 bits) but when the program accesses the program memory it can only access one byte (8 bits) at a time causing the number of addresses to be doubled.
  2. The decimal point segment should toggle on every change of counter value.
  3. Counting should happen at 1 Hz.

  4. Question 3: Prove that you are counting at a rate of 1Hz through calculations by using the number of cycles each instruction takes. Please show your work.

Deliverables

Demonstrate your working system to a TA. You can either do this during this lab, or during the first
1/2 hour of the next lab. Counting should happen at 1 Hz.
 

Turn in the answers to the three lab questions and a hardcopy of your commented assembly code.