Magic 8 Ball. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

Similar documents
By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz II

Interrupt and Timer ISRs. Student's name & ID: Partner's name(s) & ID(s): Your Section number & TA's name

Interfacing Memory Chips on the 6812 Processor Bus. Student's name & ID: Partner's name & ID: Your Section number / TA's name

Laboratory 10. Programming a PIC Microcontroller - Part II

Lab Overview. Lab Details. ECEN 4613/5613 Embedded System Design Week #7 Spring 2005 Lab #4 2/23/2005

C:\CYGNAL\Examples\C8051F02x\C\Edu_Board_Source_Code\Magcard.c

ELEC 3040/3050 Lab 5. Matrix Keypad Interface Using Parallel I/O

Designing Your Own Soft Modules

ELEC 3040/3050 Lab 5. Matrix Keypad Interface Using Parallel I/O

Announcements Homework #3 due today. Ports. Outline for Today C8051 SFRs & Port I/O Worksheet #4 - simple I/O code. Using Ports

Interfacing Memory Chips on the 6812 Processor Bus. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

Asynchronous & Synchronous Serial Communications Interface. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

Parallel I/O and Keyboard Scanning

Using the IDE and ANSI Display Commands. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

2. (2 pts) If an external clock is used, which pin of the 8051 should it be connected to?

Before Class Install SDCC Instructions in Installing_SiLabs-SDCC- Drivers document. Solutions to Number Systems Worksheet. Announcements.

ECE2049 Homework #2 The MSP430 Architecture & Basic Digital IO (DUE Friday 9/8/17 at 4 pm in class)

May the Schwartz be with you!

ECGR 4101/5101, Fall 2015: Lab 7 Digital Oscilloscope

Outline for Today. Lab Equipment & Procedures. Teaching Assistants. Announcements

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

8032 MCU + Soft Modules. c = rcvdata; // get the keyboard scan code

Lab 3 LCD Mar

Department of Electronics and Instrumentation Engineering Question Bank

8051 Microcontroller Interrupts

University of Texas at El Paso Electrical and Computer Engineering Department

University of Florida EEL 4744 Spring 2012 Dr. Eric M. Schwartz Department of Electrical & Computer Engineering 22 February Jun-12 4:55 PM

University of Florida EEL 3744 Spring 2018 Dr. Eric M. Schwartz. Good luck!

University of Florida EEL 4744 Spring 2013 Dr. Eric M. Schwartz Department of Electrical & Computer Engineering 28 March Jun-13 6:18 PM

Lab #2: Building the System

C Language Programming

Spring 2017 Project Assignment Alarm Clock with Indoor/Outdoor Thermometer

Lab #3: Keypad Scanning in C Week of 11 February 2019

C:\Users\Jacob Christ\Documents\MtSAC\ELEC74 Mt SAC - chipkit\homework Sheets.docx

Nikhil Gupta. FPGA Challenge Takneek 2012

SANKALCHAND PATEL COLLEGE OF ENGINEERING, VISNAGAR. ELECTRONICS & COMMUNICATION DEPARTMENT Question Bank- 1

University of Florida EEL 4744 Spring 2014 Dr. Eric M. Schwartz Department of Electrical & Computer Engineering 1 April Apr-14 9:03 AM

University of Florida EEL 4744 Summer 2014 Dr. Eric M. Schwartz Department of Electrical & Computer Engineering 1 July Oct-14 6:41 PM

80C51 Block Diagram. CSE Overview 1

Embedded Controller Programming II. I/O Device Programming in C Part 1: Input and Interrupts

Lab 9: On-Board Time Generation and Interrupts

EE 231 Fall EE 231 Lab 3. Decoders and Multiplexers. Figure 1: 7-Segment Display. Memory: where the program is stored.

8051 Microcontroller

Bachelor of Engineering in Computer and Electronic Engineering

C:\Users\jacob\Documents\MtSAC\ELEC74 Mt SAC - chipkit\homework Sheets.docx

Lab 4: Register File and Memory 50 points Instructor: Yifeng Zhu Due: One week

Programming the CME11E9-EVBU, Keypad, and LCD

Lab 5: LCD and A/D: Digital Voltmeter

Programming the CME11E9-EVBU, Keypad, and LCD

Chapter 11: Interrupt On Change

I Introduction to Real-time Applications By Prawat Nagvajara

Signature: 1. (10 points) Basic Microcontroller Concepts

Interrupt and Timer ISRs. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

Lab 5: LCD and A/D: Digital Voltmeter

ECGR 4101/5101, Fall 2016: Lab 1 First Embedded Systems Project Learning Objectives:

University of Florida EEL 3744 Spring 2017 Dr. Eric M. Schwartz Department of Electrical & Computer Engineering 22 February Mar-17 1:44 PM

Procedure: Determine the polarity of the LED. Use the following image to help:

EECE 690/890 Digital Radio Hardware Design. Team 3 Assignment 2. Informal Design Review: Thurs 10/15/98 Deliverables Due: Tues 10/20/98

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz III

CpSc 1011 Lab 5 Conditional Statements, Loops, ASCII code, and Redirecting Input Characters and Hurricanes

NCSU - ECE 306- Exam 2 March 27, 2003

ONE AVR D EVELOPMENT SECTION I NTRODUCTION TO NTRODUCTION TO AVR EVELOPMENT TOOLS. Section One: Introduction to AVR Development Tools

Welcome to Lab! You do not need to keep the same partner from last lab. We will come around checking your prelabs after we introduce the lab

Practical 1 Review. ECE Rick

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Lab Test III

EE251: Thursday September 20

Microprocessors B (17.384) Spring Lecture Outline

ENGR 40M Project 3c: Switch debouncing

Embedded and Ambient Systems Laboratory

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Lab Test III

ECEN 5613 Embedded System Design Week #9 Spring 2017 Lab #4 3/20/2017

AN1239. HC05 MCU Keypad Decoding Techniques Using the MC68HC705J1A. Introduction

Programming Studio #9 ECE 190

CEIBO FE-51RD2 Development System

Chapter 9. Input/Output (I/O) Ports and Interfacing. Updated: 3/13/12

Graphical LCD Display Datasheet EB

Introduction to Embedded Systems

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz IV

Finite State Machine Lab

Interrupts, timers and counters

LCD Display. Other I/O. LCD display Flash ROM SPI EPROM Keyboard (PS/2) UART connectors DAC ADC. 2-line, 16 character LCD display

Problem Score 1 / 27 2 / 19 3 / 16 4 / 14 code check off 5 / 22 /2 Total /100

Fall 2017 Project Assignment Speed Trap

University of Florida EEL 4744 Fall 1998 Dr. Eric M. Schwartz

A LCD display with ethernet interface

MICROPROCESSORS A (17.383) Fall Lecture Outline

University of Hawaii EE 361L MPLab Quick Tutorial and Project 2.1 Last updated September 1, 2011

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

AN10210 Using the Philips 87LPC76x microcontroller as a remote control transmitter

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

ECEN 5613 Embedded System Design Week #9 Fall 2017 Lab #4 10/29/2017

The modules in this lab room are 4 line by 16 character display modules. The data sheet/users manual for the module is posted on My.Seneca.

Figure 1. Proper Method of Holding the ToolStick. Figure 2. Improper Method of Holding the ToolStick

EECS 373 Midterm 2 Fall 2018

EECS 140 Laboratory Exercise 5 Prime Number Recognition

ECEN 5613 Embedded System Design Week #9 Fall 2016 Lab #4 10/22/2016

Lesson I2C. I²C (Inter-Integrated Circuit) Lab Assignment: I2C Slave Driver

EE 231 Fall Lab 2: Decoders and Multiplexers. Introduction

Transcription:

MPS Magic 8 Ball Lab Exercise Magic 8 Ball Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name Notes: You must work on this assignment with your partner. Hand in a printer copy of your software listings for the team. Hand in a neat copy of your circuit schematics for the team. These will be returned to you so that they may be used for reference. ------------------------------- do not write below this line ----------------------------- #1 POINTS (1) (2) TA init. #2 POINTS (1) (2) TA init. #3 POINTS (1) (2) TA init. Grade for performance verification (50% max.) Grade for answers to TA's questions (20% max.) Grade for documentation and appearance (30% max.) TOTAL TOTAL TOTAL Grader's signature: Date:

Part 1: Introduction to the Magic 8 Ball GOAL By doing this lab assignment, you will learn: 1. Review of basic serial I/O to the terminal. 2. Logic programming PREPARATION Review the C language studio utilities. Review the 8051 hardware port and interrupt features Develop a flowchart for the program you need to write. This will be signed off by your TA and must be included when you turn in your code for the lab. Write a C program that is free from syntax errors (i.e., it should assemble without error messages). INTRODUCTION TO THE MAGIC 8 BALL Programming Tasks For this lab you will be developing an electronic Magic 8 Ball. You will write a program that generates answers to different kinds of questions. The user selects the type of answer that is desired and the answer is displayed on the screen. There are four different types of answers that can be generated. They are: 1. Yes/No: This will output either a yes or no answer. 2. True/False: This will output either true or false. 3. Day of the week: This will randomly select a day of the week. 4. Random Number: This will select a random integer number within any range stated by the user (e.g. a random number between 3 and 7). The program should have a menu that allows the user to select which type of answer will be generated. After the answer is displayed the program should return to the menu. It is not necessary to clear the screen when returning to the menu. The answers that are generated are to be determined randomly. The section below provides a suggestion for developing random values. In order to earn full credit on the project, the answers must be generated randomly. You should first develop a flowchart for the program you need to write. This will be signed off by your TA and must be included when you turn in your code for the lab. The code must be logically written and well commented. This is very important since you will be using this code as the basis of Parts 2 and 3. After being signed off by the TA you will turn in your flowchart from the preparation work and the fully commented copy of your code. Helpful Hints Here are several suggestions to get you started on the project: 1. Start small. Break the project up into several functions and begin by only debugging one at a time. 2. Random number generation. The rand() function can be used to generate a random number. You can also use a free running counter and read in a value, which will be fairly random as well. Page 2

Part 2: Interfacing an LCD Screen to the 8051 GOAL By doing this lab assignment, you will learn to: 1. Interface the C8051F120 to a Hitachi HD44780 2-line LCD display. 2. How the LCD screen operates. 3. Print results on the LCD screen. This will be used to display the answers generated in Part 1. PREPARATION Read Hitachi HD44780U LCD Controller manual Become familiar with the different LCD screen functions included in LCD.c & LCD.h and the example LCDTEST8051.c (http://www.rpi.edu/dept/ecse/mps/mps_handouts.html). Rewrite your code from Part 1 so that the answers from the program are displayed on the LCD screen. The menu used to select the answer type will still displayed on the UART terminal screen. INTRODUCTION TO THE LCD SCREEN Programming Tasks For this lab you will be adding an LCD screen to the Magic 8 Ball system. This screen will be used to display the answers that are generated by the program. When an answer is written to the screen, the screen should first be cleared and then the answer printed. The answer should remain on the screen until a new answer is generated. A list of the LCD functions is in the LCD.h header file. Helpful Hints: Here are several suggestions to help you with the lab. 1. Remember that all characters to be sent to the screen must be sent as ASCII. This can be done by creating a char * with the character string or by passing in each character separately as an ASCII character. 2. Don t forget to include LCD.h (found on the course web page) in your program. 3. Remember to initialize the screen and make sure you have set the format type (number of lines and character size) to the desired value before trying to use the screen. 4. There are several ways of passing characters to the lcd_puts() function: char buffer[] = Hello. ; lcd_puts(buffer); //But the 2008 SDCC compiler doesn t allow //lcd_puts(buffer[]); OR lcd_puts((char *) & Hello. ); OR char buf; buf = H ; lcd_puts((char *) &buf); 5. Add delays between LCD commands in program if the display doesn t respond correctly every time. Page 3

Part 3: Interfacing a Keypad to the 8051 GOAL By doing this lab assignment, you will learn to: 1. Interface the C8051F120 to a Grayhill 16-button keypad. 2. Develop interrupt-activated software to decode key presses on the keypad. PREPARATION References: C8051F12x-13x Reference Manual, Ch. 13, 14, 23, 24 Write a header file, called keypad.h that has the interrupt initialization routine and Interrupt Service Routine. Develop a new version of your code from Part 2 that incorporates the header file and uses the keypad for all user input. Write a flow chart for the operation of the Interrupt Service Routine. Create a circuit schematic to handle the interrupt generation INTRODUCTION TO THE KEYPAD Programming Tasks This part of the lab adds a keypad to the program that was developed in Part 2. The keypad is connected to the microcontroller by the External Interrupt 0. This will allow the keypad to operate on an interruptbased method. The code for controlling the keypad will be located in a header file called keypad.h. This will allow the file to be easily transported to different programs. The Grayhill keypad is an industry standard device that was designed to work with another standardized microcontroller port with a built-in hardware interrupt capability called a Key Wakeup. For historical perspective, each bit of the port supporting Key Wakeup can be used to generate a Key Wakeup interrupt when either a rising or falling edge is detected. It is important to note that even though each bit can generate an interrupt independently of the others, the same interrupt will be called regardless of which bit triggered it. The Key Wakeup Interrupt for each individual bit is enabled using a SFR. Writing a 1 to a bit in the register will enable the corresponding bit of the port to generate an interrupt when a falling edge is detected. The flag bits for the Key Wakeup interrupt are located in another SFR. Multiple flags can be set at the same time, although software must be written in order to determine which flags have been set. The flags are cleared by writing a one to the flag bits that have been set. It is a good idea to clear the flags before the Key Wakeup Interrupt is enabled to prevent any false triggers. Unfortunately the C8051 does not support this standard hardware interface. To implement the same functionality, an extra logic device must be added to the hardware to permit keypad hits to generate interrupts. The ANDing of the keypad input lines (4 LSBits) creates a suitable signal for generating interrupts when connected to INT0. You may want to consider using a keypad for your final project. One idea for this would be, instead of returning the value to the main program, to have the buttons call different functions, which in effect allows the keypad to operate as a more advanced flexible version of the IRQ. Page 4

Required Additional Hardware Add four 10kΩ pull-up resistors on P3.3-0 to the +3.3V supply. An ANDing operation of the four bits P3.3-0 will be used to generate an INT0 interrupt. A 4-input AND gate is made from 3 2-input 7408 DIP AND gates available in the lab. Required Software Setup Port 3 pins P3.3-0 must be configured as inputs: Open-drain option on P3MDOUT and set data values to 1 s (P3 = 0x0F). Interrupt INT0 is used to detect a key press on the keypad. The key decode subroutine must be assigned to INT0. The interrupt works better when set for level triggering rather than edge triggering. The keypad switches are noisy so delays must be added to wait for the signals to settle. Delays must also be used when switching the outputs on and off to allow the slow signals to settle. It will be necessary to use the xdata keyword on many variables to move them to external memory where there is more room. Helpful Hints 1. You should use port P3 for the keypad. 2. Remember to assign the ISR vector to INT0 used for the Key Wakeup with: void KeypadVector(void) interrupt 0 3. Remember to clear the flag for INT0 triggered by the keypad hardware. 4. You must include C8051F120.h in the header file. If you do not include this then the compiler will not recognize any of the register names for the F120 SFRs. You must include putget.h, or LCD.c & LCD.h if you want to use any of those I/O functions. 5. Be sure to add the external 10kΩ pull-ups and configure the output pins as push-pull & the input pins as open-drain. The keypad may work (intermittently) without the pull-up resistors. In general, the rise & fall times of the voltage pulses on the data line are a little slow and the pull-ups improve the signals at the expense of increasing the current draw and power requirements of the system. See the sample code below. 6. Remember the column select bit values are 1,2,4,8 not 1,2,3,4. KEYPAD INITIALIZATION FRAGMENT Use SYSCLK set to 22.1184MHz from the external crystal and the following: P3MDOUT=0xF0; P3=0x0F; TCON=TCON & 0xFC; IE=IE 0x81; // hi nibble to push-pull, lo nibble to open-drain // write 0's to Port 3 hi nibble, lo nibble set for input // Clear INT0 flag and set for level triggered // Enable all interrupts & enable INT0 Page 5

KEYPAD DECODING FRAGMENT Once an interrupt has been detected, reading P3 will indicate which column the pressed key is in. Switching the 4 outputs on one at a time will determine which row contains the pressed key and the combination of the row and column will determine the precise key that was pressed. Global variables are necessary to pass values from ISRs back to the main program. Here asciichar is declared to be global. P3=0x8F; for(i = 0; i<300; i++); // check if row one (top) was active // wait for the output and input pins to stabilize portvalue = P3 & 0x0F; if (portvalue == 0x0F) { if (keyvalue == 0x07) asciichar = 1 ; else if (keyvalue == 0x0B) asciichar = 2 ; else if (keyvalue == 0x0D) asciichar = 3 ; else asciichar = A ; } else... // read the value of the lower 4 bits // if this row was selected then the value will be 0x0F // since the 1 on bit 7 will allow the 4 inputs to be hi // look at the value of the low 4 bits // return the value of the matching key // must be another row Before returning from the interrupt routine, make sure the key has been released and then delay a little before re-enabling interrupts to prevent any stray bounces from retriggering the interrupt. while (P3!= 0x0F); // wait while the key is still pressed for(i = 0; i<10000; i++);// wait for output and input pins to stabilize // after key is released IE = IE 0x81; // enable INT0 interrupt Page 6

Keypad wiring diagram - The keypad is a passive device with only switches that connect wires on the crossbar matrix of 4 x 4 wires. Page 7

Page 8