Unformatted text preview:

Page 1 of 6 E 332L Microprocessors Lab (Fall 2007) – Lab 3 (Week 4)– Objective: In this lab, you will develop a display system. This display system interfaces to switches, LEDs, buttons, and seven-segment LEDs. Note 1: Use Lab 2’s sof and ptf files. Refer to last week’s Part 1 instruction to download the sof to Altera DE2 board. Note 2: key0 is processor’s reset. Part 1: Requirements and System Description This display system will take the value to be displayed from “Value Switches” (as shown in the following figure) and display to one of the seven-segment LEDs. The position of the “Select Switches” (SW17-SW15) decides which seven-segment LED digit will receive the number generated by “Value Switches” (SW14-SW11). The number can be displayed in hexadecimal or decimal format. This feature is controlled by the “Hex/Dec Switch” (SW0). The process to upload the number (generated by “Value Switches”) is controlled by a button as shown. A button push (KEY1) will upload the value to the designated seven-segment LED. The current value of the Select switches should be displayed on LEDR4-LEDR2, the current value of Value Switches should be displayed on LEDG7-LEDG4, and the HEX/DEC should be displayed on LEDR0. Part 2: Background To prepare for this lab you might want to find out a little more about the hardware that you will be dealing with. The devices that we will be dealing with in this lab fall into the category of PIO (parallel input/output) devices. You can read more about them in the “Quartus II Version 7.1 Handbook – Volume 5: Embedded Peripherals”. Section V – Chapter 13 covers the PIO Core. Reviewing this documentation and paying special attention to the Register Map section (page 13-7) should provide more insight into the operation of these devices. Since the individual LEDs, switches, and buttons are merged into 32-bit addresses with other like devices, one of the problems will be isolating the specific device that we are interested. Another issue will be sharing a common output port with multiple devices and changing the values without undoing states for surrounding devices. Output Select Switches Value Switches Hex/Dec Switch Button to Latch ValuePage 2 of 6 ports are write only so reading from them to merge new states for some devices without changing the states for other devices is a problem. All Nios II devices are mapped to 32-bit addresses (the process to determine device addresses and Nios II processor’s characteristics were shown in Lab 2.). Switches, buttons, LEDs, and seven-segment LEDs are mapped the same way. In the DE2 board, there are eighteen switches that are mapped to a 32-bit address (this means that bits 18 to 31 are unused). How do you extract just switches SW15 to SW17 (bits 15 to 17) from the switches’ 32-bit address and ignore everything else? The method to do this is getbits as shown in Lab 2. A similar technique is applied to buttons. (Buttons can be edge or level sensitive. In this lab’s Nios II processor setup, the button has been set up for level sensitive). For LEDs and seven-segment LEDs, putbits is used. Part 3: Getting Organized You have learned in the previous lab how to create macros and subroutines (functions). In order for you to develop and use these in this and future projects, we will start by creating separate files and directories for them. Since the device files are specific to each project we will put them into a directory called “.\dev\”, and create a separate directory “.\lib\” for routines such as strcpy, memcpy, itoa, etc. that do not change with each project. Your top level routine will go in the “.\src\’ directory. This project will require that you create a lot of files (8+) so we will create the following file system structure. When you place the lab2.sof and lab2.ptf files in the Lab3 directory and configure the Altera Debug Client, the app_software\include directories are created for you. You will need to create the other directories (dev, lib and src) manually. Below is a list of files that are involved in this lab. C:\ ... \Lab3\lab2.sof provided C:\ ... \Lab3\lab2.ptf provided C:\ ... \Lab3\app_software\src\lab3main.s Top level C:\ ... \Lab3\app_software\dev\BUTTONS.s C:\ ... \Lab3\app_software\dev\LEDG.s C:\ ... \Lab3\app_software\dev\LEDR.s C:\ ... \Lab3\app_software\dev\SEG7.s C:\ ... \Lab3\app_software\dev\SWITCHES.s C:\ ... \Lab3\app_software\include\lab2_config.s same as lab2 C:\ ... \Lab3\app_software\include\mymacros.s Following is how you will need to associate these files with the Altera Debug Client. (The path up to Lab3 is of your choice) Make sure that lab3main.s is at the top of list.Page 3 of 6 Part 4: Getting Started Following is a skeleton implementation for the top level of your project. It does not contain all of the required functionality. Do not assume that this represents good documentation style. Code provided to you is intentionally brief. When you use provided code you are required to provide documentation and maintain or improve the coding style.Page 4 of 6 C:\ ... \Lab3\app_software\src\lab3main.s .include "../include/lab2_config.s" .include "../include/mymacros.s" .text .global _start _start: br PROGRAM_START .org 0x100 PROGRAM_START: movia r4,0x12345678 call SEG7_Set loop: call get_newhex # SWITCHES.s mov r4,r2 mov r16,r2 call show_newhex # LEDR.s call get_index # SWITCHES.s mov r4,r2 mov r17,r2 call disp_index # LEDG.s call get_set # BUTTONS.s beq r2,r0,loop mov r4,r16 mov r5,r17 call SEG7_Set_Digit # SEG7.s br loop loop_end: END: break br END .end Note that parameters to function calls are passed via registers r4 and r5, and returned values are passed back via register r2. Also note that at the top level we are not directly referencing any specific ports. By putting all of the code to deal with a port into a separate device module, we are providing a level of abstraction that allows us to more easily retarget code to another platform. Making calls directly between device modules is generally not a good practice. As demonstrated in this top level module, queries for the index setting are requested from the switches module and then passed to the green LEDs module. In other words, no hidden backdoor functionality is performed for basic operations. The general format for each of the device modules is to place all of the code


View Full Document

BOISE STATE ECE 332L - Lab 3

Documents in this Course
Load more
Download Lab 3
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lab 3 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lab 3 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?