Lab #4 - Alphanumeric Liquid

advertisement
ASEN 4519/5519 – Microcontroller Fundamentals
Fall 2005
Lab #4 - Alphanumeric Liquid-Crystal Displays
Assigned:
Due:
Monday
Monday
03 October 2005
10 October 2005 (22:00 hours)
OBJECTIVES
1.
2.
Learn how to use the DisplayC and DisplayV subroutines to display characters
Learn how to create user-defined characters
READING
•
Peatman: Embedded Design with the PIC18F452 Microcontroller
o Chapter 7
OVERVIEW
The QwikFlash board uses the Hitachi HD44780 LCD controller chip for its alphanumeric LCD. The chip has two
different interface modes, 4-bit and 8-bit, meaning data can either be sent a nibble at a time or a byte at a time. The
advantage of the 4-bit interface being that it frees four I/O lines on the microcontroller for alternative uses. The
disadvantage is that the 4-bit interface requires more programming on the microcontroller end to send data.
Fortunately, within the lab4.asm template program the author has given us two subroutines, DisplayC and DisplayV,
which help make the interfacing easier. The DisplayV subroutine is used to send a variable string stored in RAM.
DisplayC is used to send a constant display string residing in program memory to the LCD. Due to the PIC’s Harvard
architecture, a special mechanism is needed to retrieve a constant string from program memory. This will be discussed in
the Procedure section.
ASSIGNMENT
The Procedure section should be followed to give you an understanding of how the lab4.asm template program works.
The Questions section comes from the back of the chapter and will require you to modify the lab4.asm program to have
the LCD display new characters.
PROCEDURE
1.
Download the lab4.asm code from the class website. Use the assembler to generate the HEX file and load the
file to the PIC using QwikBug. Run the program and observe the QwikFlash board's behavior.
QUESTIONS:
1. What does the RPG do? Explain why.
2. What does the pushbutton switch? Explain why.
You should be able to tell what port the LCD is displaying, either by looking at the code or better yet, by looking at
Figure 4-2.
2.
Also from looking at Figure 4-2, it should be clear that the LCD is operating with its 4-bit interface rather than
the 8-bit interface. The Hitachi controller initialization sequence includes setting it to the 4-bit interface mode.
In the lab4.asm program, the initialization is done in the InitLCD subroutine. The subroutine waits 0.1 seconds
to allow the Hitachi controller to reset and then sends the initialization sequence, the initialization string shown
in Figure 7-6 (a). This constant string is stored in program memory, not operand memory (remember the PIC's
Harvard architecture), and therefore the mechanism discussed in Section 2.5 must be employed. To summarize,
the 16-bit address register TBLPTR (i.e., TaBLe PoinTeR) can be instructed to point to the location in program
memory of the constant string. Then by executing one of the four "tblrd" commands, the mechanism will read
the data from location TBLPTR into a register in operand memory called TABLAT (i.e., TABle LATch).
ASEN4519_lab4.doc (10/4/2005)
1
ASEN 4519/5519 – Microcontroller Fundamentals
Fall 2005
There are some subtleties here, but by reading Section 2.5 and the preceding discussion, you should better
understand what the InitLCD subroutine is doing.
1.
Next, the DISPLAY macro is called, which puts PORTD into a variable called BYTE and then calls
ByteDisplay. Immediately a constant string is displayed and the DisplayC subroutine is called to perform this
task. This subroutine sends each the constant string one nibble at a time to the LCD. The remaining code of
ByteDisplay includes all the basics needed to produce a variable string on the display, including calling
DisplayV. This will include a foray into pointers, which we have not done much if any of in the PIC section of
the class. See Section 2.4 and Figure 2-12 for some pointers on pointers (no pun intended, really).
2.
Modify the lab4 program as follows:
a) Comment out the DisplayV command at the end of the subroutine ByteDisplay
b) Delete the trailing spaces from the string BYTE_1 so that it reads “\x80BYTE=\x00”
c) Compile and load your code onto the QuickFlash board. The output should now read BYTE=
d) Now change the 5th character of the LCDstr used to initialize the LCD from 0x0c to 0x0d. Compile load
and run your program. Note the results.
e) Now change the 5th character of the LCDstr used to initialize the LCD from 0x0e to 0x0d. Compile load
and run your program. Note the results.
QUESTION:
1. Explain what is happening when the LCD configuration string value was changed from 0x0c to 0x0d and
0x0e. Looking at the data sheet for the HD44780 explain what is happening.
PROGRAMMING ASSIGNMENT
Your assignment for this lab is to write a program called lab4.asm that will print the string LAB4 centered on the upper
line of the LCD display and then on the lower segment of the LCD display print VALUE=X, where X is an ASCII
character. The value of X will begin as the capital letter A and approximately each second will be incremented to the
next letter of the alphabet. Once at the letter Z your program should return and start again at the letter A.
For example:
After initialization the second row of the LCD will read VALUE=A
A second later it will read VALUE=B then VALUE=C, … until VALUE=Z and then back to VALUE=A.
ASEN5519 ONLY
In addition to the above programming assignment your program (lab4.asm) should also cause the = to toggle between on
and off every 250ms (see questions 7-6 and 7-7) and your code should also reset the letter being printed out on the
display to A whenever switch 3 is pressed.
QUESTIONS
Answer all of the questions in the procedure section.
Answer questions 7-1, 7-4
For 7-7, modify lab4.asm to lab4_blink.asm, a program that will show the results of the BlinkColon subroutine. Hint:
Replace the ByteDisplay subroutine with the BlinkColon subroutine and instead of calling the DISPLAY macro in the
mainline loop, call BlinkColon.
For 7-13, modify lab4.asm to lab4_bslash.asm, a program that will display the characters in part c) on the top row.
ASEN4519_lab4.doc (10/4/2005)
2
Download