Experiment Objectives. 2. Tasks

Similar documents
How to use AVR Studio for Assembler Programming

AVR Butterfly Training. Atmel Norway, AVR Applications Group

ET-BASE AVR ATmega64/128

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

3. Programming the STM32F4-Discovery

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

CHAPTER 11: Flip Flops

Lab Experiment 1: The LPC 2148 Education Board

ezsystem elab16m Project 1F: Alarm System (Full Project description)

isppac-powr1220at8 I 2 C Hardware Verification Utility User s Guide

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

EE289 Lab Fall LAB 4. Ambient Noise Reduction. 1 Introduction. 2 Simulation in Matlab Simulink

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

ENGI E1112 Departmental Project Report: Computer Science/Computer Engineering

An Introduction to MPLAB Integrated Development Environment

Board also Supports MicroBridge

INTRODUCTION TO SERIAL ARM

Introduction to LogixPro - Lab

PRODUCTIVITY THROUGH INNOVATION 600 CONTROL DIRECT DRIVE TECHNICAL/OPERATION MANUAL

How to read this guide

Mobius 3 Circuit Board Programming Instructions

Table of Contents Getting Started... 3 The Motors... 4 The Control Board... 5 Setting up the Computer with Mach Starting up the Equipment...

FlowKit in-circuit debug system

Christopher Steiner. Dr. Janusz Zalewski. CEN 3213 Fall Embedded Systems Programming. Florida Gulf Coast University. Fort Myers, Florida

2. Scope of the DE0 Board and Supporting Material

QUICK START GUIDE. SG2 Client - Programming Software SG2 Series Programmable Logic Relay

USBSPYDER08 Discovery Kit for Freescale MC9RS08KA, MC9S08QD and MC9S08QG Microcontrollers User s Manual

Multi-Touch Ring Encoder Software Development Kit User s Guide

Switch board datasheet EB

AIM SOFTWARE AND USB DRIVER INSTALLATION PROCEDURE

DRV8312-C2-KIT How to Run Guide

ViviCam 25 Digital Camera User s Manual

INDEX. Trademarks All name and product s trademarks mentioned below are the property of their respective companies.

E-Blocks Easy Internet Bundle

STEP 7 MICRO/WIN TUTORIAL. Step-1: How to open Step 7 Micro/WIN

Arduino Lesson 1. Blink

EvB 5.1 v5 User s Guide

SA-9600 Surface Area Software Manual

Programming the On-Chip Flash on a phycore-xc161 phycore-xc167

Start A New Project with Keil Microcontroller Development Kit Version 5 and Freescale FRDM-KL25Z

The CW Machine Hardware

The Programming Interface

Computer Networks I Laboratory Exercise 1

Introducing AVR Dragon

DRIVER INSTALLATION PROCEDURE WINDOWS 7 (32 or 64 BIT) N-Com Wizard 2.0 (and higher)

Ultra Thin Client TC-401 TC-402. Users s Guide

Special Lecture. Basic Stamp 2 Programming. (Presented on popular demand)

Audacity. For use with MFL Speaking Tests. User Guide (Microsoft Windows version)

Keep it Simple Timing

Configuring the Siemens TC35 modems for use with the MI2292

How To Use A Watt Saver On A Microcontroller (Watt Saver) On A Cell Phone Or Mp3 Player

Yamaha 01V96 Version2 Upgrade Guide

Maxtor OneTouch User's Guide

ROBOTC Software Inspection Guide with Additional Help Documentation

EXERCISE 3: String Variables and ASCII Code

Surf it Easy. User Guide

Programming Device Manual Booklet AVR Prog USB v2

AVR Prog User Guide. Section 3

How to design and implement firmware for embedded systems

AC-PG-USBASP USBASP AVR Programmer

2.0 Command and Data Handling Subsystem

Computer Automation Techniques. Arthur Carroll

Six-servo Robot Arm. DAGU Hi-Tech Electronic Co., LTD Six-servo Robot Arm

Optional Bluetooth Firmware Update HW05-SW Enables Bluetooth AVRCP control and metadata display for iphone 5 and ios 6 users.

Why using ATmega16? University of Wollongong Australia. 7.1 Overview of ATmega16. Overview of ATmega16

Addonics T E C H N O L O G I E S. NAS Adapter. Model: NASU Key Features

EMBEDDED C USING CODEWARRIOR Getting Started Manual

computer (please download the software from the official website if there is no CD available).

The 104 Duke_ACC Machine

Acer LCD Monitor Driver Installation Guide

CashFlow Programming Module CPM

Instructions for Installing and Using the FOCUS DL-15 Data Transfer Software

Digital Photo Bank / Portable HDD Pan Ocean E350 User Manual

Jianjian Song LogicWorks 4 Tutorials (5/15/03) Page 1 of 14

TRILOGI 5.3 PLC Ladder Diagram Programmer and Simulator. A tutorial prepared for IE 575 by Dr. T.C. Chang. Use On-Line Help

M68EVB908QL4 Development Board for Motorola MC68HC908QL4

Lab 11 Digital Dice. Figure Digital Dice Circuit on NI ELVIS II Workstation

EnVivo 4 GB Aluminum MP3 Player

GPS/GLONASS SiRFstarV Evaluation Kit EVA5100-A

GSM Interfacing Board

MN POS TM. Hardware & Peripherals. All required hardware may be purchased from Home Office.

Work with Arduino Hardware

Portable MP3 Player User's Guide

Applications Development on the ARM Cortex -M0+ Free On-line Development Tools Presented by William Antunes

ScreenBeam Wireless Display Kit. User Manual. Solutions for the Digital Life. Model #: SBWD100KIT. Ver 1.0

SP8 Programmers 硕 飞 科 技. User's Guide. TEL: FAX: WEB:

Installing the IF-NMEASC & SC30 Windows XP Drivers & Software

Waspmote. Quickstart Guide

Lab 1: Full Adder 0.0

How to setup a serial Bluetooth adapter Master Guide

BE635 User Manual. Rev. V Bolymin, Inc. All Rights Reserved.

5. Tutorial. Starting FlashCut CNC

MANUAL (p. 2) USB Turntable HAV-TT20USB

ISP Engineering Kit Model 300

Lab 3 Microcontroller programming Interfacing to Sensors and Actuators with irobot

WIZ-Embedded WebServer User s Manual (Ver. 1.0)

AXE114S BINARY CLOCK. revolution Revolution Education Ltd. Web: Version /09/08 AXE114.PMD.

CodeWarrior Development Studio for Freescale S12(X) Microcontrollers Quick Start

Developing an Application on Core8051s IP-Based Embedded Processor System Using Firmware Catalog Drivers. User s Guide

Transcription:

Experiment 4 1. Objectives The objectives of this experiment are to Implement functions using AVR assembly language. Use a stack to store dynamic data such as parameters and local variables. Use AVR macros. Use nite to download a program to the AVR development board and run it. 2. Tasks There are three tasks in this experiment. The first two tasks are about implementing functions in AVR assembly language and the third task is about using AVR development board to run a program. 2.1 Task A: Evaluating A Polynomial The C program polynomial.c shown in Figure 1 evaluates the polynomial function F(x)=a n x n + a n-1 x n-1 + +a 1 *x + a 0. Assume that a i (i=0, 1,, n), x and n are ONE BYTE long and the result F(x) is TWO BYTE long. Write an AVR program to implement the C program. Your program must satisfy the following requirements: All constants are stored in the program (FLASH) memory. All global variables are stored in SRAM. All local variables and parameters are stored in the stack. The return value of each function is stored in the register pair r25:r24. Checkpoint A: Signature:

#include <stdio.h> int n=7; int x=-3; int power(int number, int power) int i = 0, num = 1; for(i=0;i<power;i++) num *= number; return num; int main() int i = 0, sum = 0; int a[n]; for(i=0;i<n;i++) a[i] = i; result = power(x, i); sum += result * a[i]; return sum; Figure 1: Program polynomial.c 3.2 Task B: Hanoi Tower Problem The following is an excerpt from the book Concrete Mathematics - A Foundation for Computer Science (2nd Edition) by Graham, Knuth and Patashnik: A neat little puzzle called the Tower of Hanoi, invented by the French mathematician Edouard Lucas in 1883. We are given a tower of eight unequally sized disks, initially stacked in decreasing size on one of three pegs. The objective is to transfer the entire tower to one of the other pegs, moving only one disk at a time and never moving a larger one onto a smaller. Lucas furnished his toy with a romantic legend about a much larger Tower of Brahma, which supposedly has 64 disks of pure gold resting on three diamond needles. At the beginning of time, he said, God placed these golden disks on the first needle and ordained that a group of priests should transfer them to the third, according to the rules above. When they finish, the Tower will crumble and the world will end. Now the question arises: How many moves are necessary and sufficient to perform the task?

The C program shown in Figure 2 solves this problem, where n is the number of disks and A, B and C denote the three pegs. After the program is completed, the value of counter is the total number of moves. #include <stdio.h> int counter = 0; void move(int n, int A, int C, int B) if (n==1) counter++; else move(n-1,a,b,c); move(1,a,c,b); move(n-1,b,c,a); int main() int n=8, A=1, B=3, C=2; move(n,a,b,c); return 0; Figure 2: Program tower-hanoi.c Assume that the number of disks is at most 15. Write an AVR assembly language program using the above C code. Your program must satisfy the following requirements: All constants are stored in the program (FLASH) memory. All global variables are stored in SRAM. All local variables and parameters are stored in the stack. No overflow occurs during the execution of your program. How many bytes of SRAM memory are needed for the stack to run this program correctly? Checkpoint B: Signature:

2.3 Task C: AVR Development Board and Downloader This task introduces the AVR Microcontroller Development Board and the downloader nite. In the subsequent labs you will use the development board to run your program instead of only simulating it using AVR Studio. 2.3.1 Board Handling Precautions Two students in each group share one AVR development board due to the limited number of boards. You are required to keep the board properly. A few precautions are necessary when you use the AVR development board: Electrostatic discharge can destroy electronic equipment without giving any sign of doing so! Please always discharge yourself before handling the AVR microcontroller board, and observe any handling precautions as advised by the demonstrator. You can do this painlessly by touching a grounded conductor using a coin, a key or another metallic object instead of your finger. Short circuits may damage certain devices. Please remove any metal watch straps, buckles, rings and so on before handling the board. Always turn the power off before connecting or disconnecting any I/O subsystems. 2.3.2 Examining the AVR Microcontroller Board Figure 3 shows a picture of the assembled system. It also shows how cables attach between the microcontroller connectors and the I/O connectors. Figure 4 is a layout diagram of the assembled system: As you can see from the figures, the AVR Microcontroller Board has one printed circuit board which contains most of the electronics, peripherals and connectors. This board is designed by David Johnson in the School of Computer Science and Engineering, University of New South Wales, Australia. The particular microcontroller used on this board is Atmel ATmega64 device, one of the dozens available from different manufacturers world-wide.

Figure 3: AVR Development Board Figure 4: AVR Development Board Block Diagram

Take a closer look at the particular microcontroller used on the AVR Microcontroller Board. Refer to page 2 of the Atmel ATmega64 Datasheet for the pin diagram for this microcontroller (You can find this datasheet in the AVRDOC folder on your desktop). Now identify the following components on the board, observe them on the system block diagram and try to trace the connections between them and other major components: AVR processor USB Interface Flash Memory SRAM Reset & Loader Switches Speaker I/O Pins Keyboard LED bargraph LCD Display Microphone Filter-Amplifier Motor, Shaft Encoder LDR, LED, POT, PB1, PB0 2.3.3 Create New File Create a new file for this checkpoint and name it led.asm. led.asm is shown in Figure 5. After creating the above AVR assembly program, you are now ready to advance to the next step, which simulates the code using AVR Studio. 2.3.4 Simulating the Code At this point you have generated the file needed to simulate the code. Now Build and Run your program. To view the contents of I/O registers and ports, select View Toolbars I/O and double click on I/O ATMEGA64 tree to expand it. This is used to inspect and modify the contents of the I/O registers. The standard configuration gives you a quick overview of the hardware with the ability to expand particular items for more information. Now expand PORTC tree in the list as before. You can see three I/O memory locations associated with Port C. They are: Port C Data Register (PORTC), Data Direction Register (DDRC) and Input Pins (PINC). PORTC: PORTC register is a read/write register. It is initialized to $00 at reset. If it is programmed as an output, writing to PORTC will allow you to change the logic state at the PORTC pins. DDRC: This register is used to control the direction of each of the pins of the PORTC. Writing a 0 (which is also the reset value) to any bit of this register will make the corresponding PORTC bit as input, and writing a 1 will make it an output bit.

PINC: PINC is read-only. With PINC you can read the logic of each physical pin of PORTC. As shown in I/O View each bit in the registers is represented by a white square box. A logical zero (0) is represented by a white square box and a logical one (1) is represented by a black square box. These boxes will be updated dynamically during program execution, and show the current state of each bit. You may also set and clear these bits by clicking on the appropriate box at any time during the program execution. ; led.asm ; Author: ; Date:.include "m64def.inc".def temp =r16.equ PATTERN1 = 0x5B.equ PATTERN2 = 0xAA ser temp out PORTC, temp out DDRC, temp out PORTA, temp clr temp out DDRA, temp switch0: sbic PINA, 0 rjmp switch1 ldi temp, PATTERN1 out PORTC, temp switch1: sbic PINA, 1 rjmp switch0 ldi temp, PATTERN2 out PORTC, temp rjmp switch0 ; Write ones to all the LEDs ; PORTC is all outputs ; Enable pull-up resistors on PORTA ; PORTA is all inputs ; Skip the next instruction if switch0 is pushed ;If not pushed, check the other switch ; Store PATTERN1 to the LEDs if the switch was pushed ; Skip the next instruction if switch 1 is pushed ; If not pushed, check the other switch ; Store PATTERN2 to the LEDs if the switch was pushed ; Now check switch 1 again Figure 5: Program led.asm Now single step down to the last line of the program by repeatedly pressing the F11 key or by selecting Step Into from the Debug menu. Notice how the color changes from black to red when the value of a register changes. 3.7.5 Download Program After having finished simulating the program, you need to download the program to the board and run it there by using nite. nite is a downloader which downloads your program onto the board. It was developed by Jayasooriah. The detailed descriptions of nite can be

found at http://www.cse.unsw.edu.au/~jayas/esdk/nite.html. Only two commands i.e. path and send will be used in the lab. An Intel Hex Fomat file called led.hex has been generated after Build and Run. Here are the steps you need to follow: (Note: Don t have the USB power cable plugged in before performing any wiring.) 1. Use the provided patch cables to connect pins PC0-PC7 to the LED0-LED7, and PB0-PB1 to the PA0-PA1. (Make sure you have the right order). 2. Plug the USB cable into the board and the PC 3. Open the downloader nite by double clicking the nite icon on the desktop. 4. Hold the Loader push-button down on the AVR Microcontroller Board 5. While holding the Loader push-button down push the Reset button and release the Reset button. 6. Release the loader button. The board is now waiting for a program to be downloaded. 7. When you see the logo in the nite window appears, then you can download the new version of the program. 8. Now change the directory by typing :path directory name, where directory name is the name of the directory which contains the hex file of your program. 9. To download the program, type :send file.hex (ie: :send led.hex). This downloads the program to the AVR board, and some output is also generated. 10. Press the Reset switch to execute the program. Note that every time you download a new or modified program to the AVR Microcontroller Board, you have to RESET the board first by pressing the Loader button and the Reset button at the same time. 3.7.6 LED Bit Pattern Your first task is to work out the bit patterns by examining the AVR assembly program given in figure 5. Answer the following questions: 1. Does a 1 bit turn the LED on or does it turn it off? Why? 2. Which registers change their value? How are the values changed? 3. Which instruction turns on the LEDs? Explain your answers to the laboratory assessor. Checkpoint C: Signature: