Electrical Eng ; lab reports paraphrase

profilefaisal0z
lab9.doc

ECE 425L

Lab #9: LCD Display

Introduction:

In this lab, the use of branches will be greatly expanded and used to create and call functions, for the purpose of setting up and displaying text on the LCD display. Since the display contains a controller of its own connected to 8 data pins plus 3 control pins, the pins must have the correct outputs written to them and changed multiple times in order to have the controller “remember” the values of the characters written to the data pins and display multiple characters on the screen at the same time. The values must also be manipulated on order to send commands to the controller, such as erase, scroll, return, or position cursor on the display. The diagram of the pins can be seen in Figure 1 below.

image1.png

Figure 1: Pin Schematic for LCD on education board.

All of these methods require writing to both ports on the processor at the same time. After such writing, some delays and more writing will be required. These routines will be called multiple times. Therefore, they must be written as subroutines that can have parametrized values passed to them. Repeated calls of these subroutines will be used to write strings to the board, and even send commands that will initialize the board and scroll the text. With all of these writes to the LCD controller, text can be easily displayed on the LCD.

Equipment Used:

Keil tools to compile and debug the code.

LPC2148 Education Board.

Procedure:

The process of setting up the board requires several different steps, and each one is contained in its own function. So the first function written is to initialize the ports on the board by setting all pins connected to the display to GPIO on the function select registers, then setting all those pins to output pins. All of the registers are modified using the read-modify-write method. That way, the remaining pins on each port are unaffected.

The second function is a simple delay function. R0 is used to pass in a value containing the the number of microseconds that the controller should wait. However, this is reliant on the clock speed, and as a result, the delay value received was much greater than the desired delay. However, due to the usage of the function, a larger delay is okay for the display, and will not cause any problems in making it operate.

LCD-cmd and LCD_char were the next two functions in line. They are identical to each other except for the LCD_RS bit, which is low when sending a command, and high when sending a letter. These functions will be the main data feed into the board.

LCD_init is the initialization function used on the board. It passes a series of commands to the board, which will wake up and initialize the LCD controller, then light the LED backlight once the display controller is set up. This subroutine is important because the LCD display will not work if its not set up properly first. However, it can be wired into a main function if code size is important, since the LCD only needs to be set up once before it will just work. The subroutine is used for simplicity.

LCD_String uses a loop along with a pointer passed in in order to determine the text to display on the LCD. It will then write the text to the display by using a loop to repeatedly call the LCD_char function. In this lab, the function we wrote will cut off on the last character of the active line in order to avoid wrap-around to the second line on the display.

LCD_clear and LCD_home simply sent the commonly-used functions to either clear the display or go to the first char position and reset scrolling, and their main task is to simply send the command to the LCD_cmd function and return once that is done.

LCD_shift also sends a command to the board; however, this function will be used to shift the display to either the right or left. However, this function will be called many times when a shifting loop is entered, so it is important that it works correctly and can be called easily from a loop. This function shifts the text to the right or left on the display, based upon a certain bit sent to the command, but the text in the display memory will not be changed. To undo such a shift, the LCD_home function will be called.

Once all these routines are written, the main function is written in a separate file. It simply initializes the LCD, writes text to it, and using a loop, it scrolls it. Other commands can also be easily sent, but to simply display and scroll text, calls to the subroutines written above will be easy and few because the main function can reuse them and the subroutines do most of the work. Using the loop, the scrolling can be performed indefinitely (until the processor is reset, that is.

Results:

Task One:

Task one had seven different parts to it. The first part required a certain delay to be produced. This was achieved by sending the desired value through register 0 and multiplied to produce the delay. The delay can be tested by using debug and checking the seconds that the subroutine started and what it ended with. Seconds can be found under the “Internal” section.

The next three task configure the LCD interface to make sure that the LCD is on and that the correct command is being sent to the pins. Each of these were done by separate subroutines called “LCD_pins”, “LCD_init”, and “LCD_cmd”. LCD_pins clears or sets different bits to make sure “00” is set for that bit for GPIO or if a certain bit needs to be input/output. To make everything easier to read the bits that controlled each pin were named such as “LCD_RW” that controls whether to write to the LCD or read to it. All these different bits were obtained from the Table 1 shown below. LCD_init make sure Enable, Register Select, and Read Write bit are set to the proper bit. This will also turn the LCD backlight on. LCD_cmd is called every time a command needs to be sent to the education board.

image2.png

Table 1: Pin Assignment of LCD module.

A subroutine was asked to be made to send a character to the LCD. This was achieved by sending the ASCII value to the subroutine and the desired bits were cleared and then moved to the IOPIN. The result can be seen in Results Figure 1:

Result Figure 1: Character “H” displayed on LCD.

The next part to task one required a string to be displayed on the first line of the LCD. This was accomplished by using the subroutine LCD_String that would grab each character from the string and follow the same procedure that the LCD_char did. The counter would be incremented until the 0 at the end of the string was reached. The result can be seen on Result Figure 2.

Result Figure 2: The String “Hello” displayed on the first line of the LCD.

Task Two

Task two required the display of a string on both the top line of the LCD and the bottom. This was achieved by using the same subroutine LCD_String as the previous task but however this time the starting cursor was changed to 0x80 for the second string after the first string was finished. The result can be seen in Result Figure 3.

Result Figure 3: A String is displayed on both lines of the LCD.

Task Three

Task Three required the strings on the LCD to scroll continuously. This was achieved by writing the subroutine LCD_Shift that would shift everything one to the left. This function was called repeatedly using a continuous loop. The result can be seen in Result Figure 4. This was then enhanced by making it to that the string would reset back to home once the string reach the send so that there would be no time where a blank LCD was displayed.

Result Figure 4: Strings scrolling left in a continuous loop.

Questions:

No questions are presented in this lab

Conclusion:

This experiment introduced how to set up and send data to the LCD on the education board. This was done by doing different subroutines that each had its own purpose. Depending the task required such as displaying a character or a string or even just turning it on different subroutines needed to be executed. These subroutine calls were initialed from main.s depending on the task.

Throughout each task, pins from both Port 1 and Port 0 were manipulated to what was required such as setting them to outputs. Since some pins have multiple uses we had to make sure we manipulated and had the correct delays set in-between.

This experiment showed how by making each part into a different subroutine it is easier to keep track of everything that is going on. Since everything was separated into subroutines knowing what is going on at each part of the code is a lot easier not only to read but also to edit. This will be useful in future experiments as they become longer and more complicated. This will make it easier to isolate problems when debugging.