Lab 4

17 downloads 23328 Views 187KB Size Report
operated using a data width of 4-bits, and the busy flag is unavailable. Due to ... Fill in the rest of Table 1 by referring to the 4x4 Matrix KeyPad schematic and the  ...
CSE3215 Embedded Systems Laboratory Lab 4: Simple Calculator Objective The hand held calculator is an example of an embedded system. Today calculators come in various degrees of complexity from the elaborate graphing type to the ones that may perform square roots if you are lucky. In either case an engineer had to sit down and come up with a design based on some specifications outlined by there supervisors. So for this lab design a calculator that performs the basic math operations +, -, /, and *.

Reference Material Reference Guide For D-Bug12 Version 4.x.x DB12RG4 April 04,2005.pdf DRAGON12 Schematics.pdf LCD_SPEC.pdf

LCD Display The DRAGON12’s LCD has two operating restrictions; the display must be operated using a data width of 4-bits, and the busy flag is unavailable. Due to these restrictions the routines dealing with resetting and writing characters to the display have been provided to help simplify the task at hand, designing the calculator. Appendix A lists the routines made available to you. Please note the LCD still has to be initialized in order to function properly so you must read the LCD_SPEC.pdf document. Also note the addresses for the display character position and character address as specified in the LCD_SPEC.pdf document do not work properly, use address 0x80 for display position 1 of the first line and address 0xC0 for display position 1 of the second line. The command codes are correct.

4x4 Matrix Keypad Typically matrix keypads are scanned at a fixed rate, Figure 1 shows the scanning timing sequence that will be followed in this lab. Scanning a matrix keypad involves driving, in our case each row low once every 20ms. Key hits are acknowledged by detecting an active low on any of the column return lines. If all of the column return lines are high then no key has been pressed. Each key in the keypad has a unique scan code which is a combination of the row and column lines. Matrix keypads are mechanical membrane switches and therefore must be debounced.

Pre Lab 1. Fill in the rest of Table 1 by referring to the 4x4 Matrix KeyPad schematic and the timing diagram shown in Figure 1. (0) PA[7..4] 1110

(1) PA[3..0] 1110

PA[7..4]

(4) PA[7..4]

PA[3..0]

PA[7..4]

PA[7..4]

PA[3..0]

PA[3..0]

PA[3..0]

PA[7..4]

PA[7..4]

PA[3..0]

PA[7..4]

PA[3..0]

PA[7..4]

PA[3..0]

PA[7..4]

PA[7..4]

PA[3..0] (B)

PA[3..0]

PA[7..4]

(E) PA[3..0]

PA[3..0] (7)

(A)

(D) PA[7..4]

(3)

(6)

(9)

(C) PA[7..4]

PA[3..0] (5)

(8) PA[7..4]

(2)

PA[3..0] (F)

PA[3..0]

PA[7..4]

PA[3..0]

Table 1: 4x4 Matrix Key Pad Scan Codes 2. Develop a program in either C or Assembler that will perform the basic math operations +, -, *, and /. Use the _CSE3215_C_MS_LAB4_W06 stationary for C applications and the _CSE3215_RELOC_ASM_LAB4_W06 for assembler applications. Your program must: •

Accept key hits from the 4x4 matrix keypad connected to PORTA.



Display key values on the first line of the LCD display, left justified as they are entered.



Accept an equation up to and no more then sixteen characters.



Perform operations left to right as they appear in the equation; do not worry about following the mathematical rules for operations.



Acknowledge all divide by zero and operations where the result is outside the range for signed 16-bit integers as math errors by displaying the message and only the message “MA ERROR” on the first line of the display right justified. No other characters shall be accepted until a CLR command is entered.



Acknowledge all syntax errors situations like “2 + / 3” where two or more operations follow one another or “2 + 3/” when the equation ends in an operation by displaying the message and only the message “SYN ERROR” on the first line of the display right justified. No other characters shall be accepted until a CLR command is entered.



Display the result of the operation and only the result of the operation right justified on the second line.



When receiving a CLR command at any point clear the display and move the cursor back to the far left position of the top line.



Must not use interrupts to handle any I/O or timing operations. All I/O or timing operations must be handled by polling the appropriate I/O lines or timing registers.



Refer to Table 2 for the keypad function mapping.

Procedure 1. Connect the DRAGON12 to the PC. 2. Download and debug your program. 3. Demonstrate your working program to the lab demonstrator. Return all equipment and boards before leaving the lab.

Evaluation Demonstrate a working version of your code to the lab demonstrator (note this means you must show convincing evidence that it works) and have acceptable written documentation about your programs performance. You should be able to answer questions about the program, the use of the test equipment and your test and debugging techniques.

Report At the beginning of the next lab session, submit a report for this lab. Your report should contain the specification for your design, overall view of the system (both hardware and software) and the source code.

Key 0 4 8 C

Function 0 4 8 *

Key 1 5 9 D

Function 1 5 9 /

Table 2: Key Pad Function Definitions

PA0

PA1

PA2

PA3 50us 20ms Figure 1: KeyPad Scanning Timing Diagram

Key 2 6 A E

Function 2 6 + CLR

Key 3 7 B F

Function 3 7 EXE

Appendix A: LCD Interface Routines void ResetLCD( void ) This routine performs a software initialization on the LCD display using a data width of 4-bits. Routine should be called once after initial power up just in case LCD power conditions are not meet and internal reset does not function properly. void WriteLCDCommandString( char *cmdString ) Writes the null terminated string of command characters pointed to by the passed parameter *cmdString to the LCD. void WriteLCDMessageString( unsigned char address, char *msgString ) Writes the null terminated string of display characters pointed to by the passed parameter *msgString to the LCD starting at the address location specified in the parameter address. void WriteLCDCharacter( char type, char character ) This routine writes a single character to the LCD. The type of character is determined by the passed parameter type. type = 1: display character type = 0: command character void Delay( unsigned char delayTime ) This routines generates a delay where the delay time is 5ms * the value of the passed parameter delayTime. void Delay50us( void ) This routine simply generates a 50us delay.

Assembler sub-routines LCDReset: This subroutine performs a software initialization on the LCD display using a data width of 4-bits. Routine should be called once after initial power up just in case LCD power conditions are not meet and internal reset does not function properly. LCDWriteCommandString: Writes a null terminated string of command characters to the LCD. The start address of the string must be loaded into the x index register prior to calling this subroutine.

LCDWriteMessageString: Writes a null terminated string of display characters to the LCD. The start address of the string must be loaded into the x index register prior to calling this subroutine. LCDWriteChar: This subroutine writes a single character to the LCD. Accumulator A contains the character to write CCA, accumulator B determines the type of character. ACCB = 1: display character ACCB = 0: command character Delay5ms: This subroutine generates a 5ms delay. Delay50us: This subroutine generates a 50us delay.