DOC PREVIEW
ISU CPRE 381 - Sprayer Lock lab 8

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CPR E 381x/382x  Lab08aSprayer LockCPR E 381x/382x  Labw08aCPR E 381x/382x  Lab08aSprayer Lock1. ObjectivesThis lab continues to provide practice with C programming, since C programming is a tool that we use in the laboratory to gain hands-on experience with microcontrollers. However, the lab experience goes beyond the syntax of C to address program design and introduce a more complicated input device than the switches used so far – i.e., a keypad. Although advanced I/O devices are the focus of the latter part of the course, we start with the keypad to expand the programmer’s view of an I/O device. In addition, the lab underscores that software needs to understand the hardwarethat it is interfacing with.2. PrelabRead all of the lab sections, there is a lot of info, which will take awhile to read through if you wait until lab time. Begin to design your software, even if only pseudo-code.3. SetupAs you did in previous labs, make sure you create the folder in your homedirectory U:\CPRE381\Labw08a to save all your work from this lab. 4. Sprayer LockWrite a C program that implements a digital lock, e.g., to open a tractor's sprayer unit (i.e., give the farmer access to gauges, valves, chemicals used intreatments, etc.), having the following specifications and behavior.BEFORE YOU START: As of Spring 2004, a hardware modification has been made to the PowerBoxes to accommodate this lab. Please make sure that you are sitting at a PowerBox that has a silver sticker on the circuit board (lower-left corner) reading "CAP MOD".The digital lock uses the keypad input and LCD display output. The keypad is at the lower left of the PowerBox, as shown in the following diagram. The keypad has four rows and four columns of keys.The layout of the keys on the keypad is:1 - 2 - 3 - A4 - 5 - 6 - B7 - 8 - 9 - C* - 0 - # - DAs given in the file defines.h, the address of the keypad input register, or port, is:#define IO_DIGITAL_INPUT_KEYPAD 0x40000013This is an 8-bit port, and the bits have the following interpretation:Bit 7-5 4 3-0Description Not used1 – Keypressed0 - No keyPosition of key pressed (0-15):0 - 1 - 2 - 34 - 5 - 6 - 78 - 9 - 10-1112-13-14-15For example, key '#' is at position 14. Notice that the position field indicates a position number, with the key values (1, 2, 3, A, ... D) mapping directly to a position number (0, 1, 2, 3, ... 15).The digital lock is either open or closed. The keypad is used to enter the password for the digital lock. The password is written to the LCD display. The correct password opens the lock, which in turn, allows the sprayer unit to be opened. The initial password will be #05C382. Upon successfully reading and identifying the sequence, the digital lock will open. Any sequence may beentered provided that the last sequence is the password (e.g., ABCD#05C382is valid). For each key pressed, print the character that the key represents to the LCD screen. Use the LCD_PutChar(char) function. Remember to initialize the LCD at the beginning of the program. Pressing the * key should let the user change the password. Implement and document this feature using your own ideas. In addition to the keypad input, the digital lock has one other input:Reset digital lock - bit 0 of DIP Switch 1: If bit equals 0, reset the digital lock to closed. After the sprayer has been locked, you should be able to enterthe password for the lock again without having to restart the program. In addition to the LCD display, the digital lock has one other output:Status of digital lock - bit 0 of LED Bargraph 1: Turn on LED when the digital lock is open. If you study the LED output description from Lab 7b, you will see that the bargraph works as follows: setting a bit to 1 turns the LED off.The design of your program needs to address two interesting behaviors:Password IdentificationHow is the password sequence identified? How does the program keep track of which keys have been pressed in order to check them against the password? Select one of the following options to design your program:- State Machine approach: Recall that a state machine can implement a sequence detector, not just sequences of 0 and 1, but sequences of any values. Design a FSM that uses the key pressed as an input to determine present state and next state transitions. Ateach state, it checks whether the key values match the password and acts appropriately. A challenge in this design approach is implementing the change of password (hint: each state may use a variable for the key expected). - Buffer approach: A buffer is a place to store data. It can be a hardware device, such as a buffer chip. However, it can also refer to a software data structure, such as an array. Declare a buffer to store the characters as keys are pressed, and then check whether it matches the password. (Hint: see the strstr string handling function in C. What does the function do? How is the function used? Note: you should not need to include the string.h file.) Key DebouncingThe keypad is set up to read the immediate value of the digital input. However, a phenomenon known as bouncing may occur. Due to the mechanical nature of the keypad, the input will bounce as it makes intermittent contact and finally settles on the contact. Thus, you will get awaveform similar to the following graphic, where time is on the horizontal axis and logic value, vertical axis:If you take the first value and assume that the next different value is the user releasing the key, your input will behave as if every key press causes theuser to tap the key several times. Of course, this is incorrect, as one key press by the user should be detected as only one key press in your program. There are two solutions to this problem, one in hardware and another in software. Hardware: For a hardware-based solution, you would use a resistor/capacitor combination, below, resulting in the waveform shown.Software: In software, you will simply ignore the input for a pre-specified amount of time (i.e. the bounce period). To wait a specified number of milliseconds, use the msleep function, which takes number of milliseconds to wait as a parameter.msleep(xx); // Waits xx ms In this lab, you should experiment with the software solution to debouncing to find the value for xx which waits long enough to keep the keys from bouncing, but does not wait so long that it keeps you from pressing keys quickly. Please treat this project as if you were building a real lock -- add anything a real


View Full Document

ISU CPRE 381 - Sprayer Lock lab 8

Download Sprayer Lock lab 8
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 Sprayer Lock lab 8 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 Sprayer Lock lab 8 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?