LCD

The LCD Module is programmed to handle all events that utilize the LCD screen. Its public function include those allowing the user to initialize the LCD correctly, write a character or string to the LCD any position that the user inputs, or simply use setup functions that will print the score or time in predetermined positions.

Click here to see the hardware setup of the LCD

Click here to see and download the complete LCD.h module

Click here to see and download the complete LCD.c module

Public Level Functions:

Function: LCDInit(void)
Description: It will initialize the LCD to take character inputs. This function must be run before using the LCD. The timers12 library must be initalized before using this function.
Input: None
Output: None
Psuedocode: Initialize the ports of the LCD
Write a command of 0x30 to the LCD
Wait at least 4.1 ms
Write a command of 0x30 to the LCD
Wait at least 100 microseconds
Write a command of 0x30 to the LCD
Wait at least 1.6 ms
Write a command of 0x08 to the LCD
Write a command of 0x01 to the LCD
Wait at least 4.9 ms
Write a command of 0x06 to the LCD
Write a command of 0x0F to the LCD

Function: LCDputchar(char ch)
Description: It will take the character passed as the input and place it in the current position of the blinker. It will then scroll the entire display one character to the left.
Input: char ch: character to be output
Output: None
Psuedocode: Set the register on the LCD to data
Write the character to the ports of the LCD
Pulse the enable line of the LCD

Function: LCDWriteString(char stringToWrite [ ], unsigned int address)
Description: Writes the string to the specified address
Input: char stringToWrite [ ], unsigned int address
Output: None
Psuedocode: Set the register on the LCD to command
Write the address to the ports of the LCD
Pulse the enable line of the LCD
Run through a for loop of the length of the string

Use LCDputchar on each character in the string

End for loop


Function: WriteScore(int score), WriteTime(int time)
Description: Converts the score or time to a string and prints it to the LCD in the appropriate position
Input: int score, int time
Output: None
Psuedocode: Convert the passed integer to a string
If the integer is less than 10
Pad the created string with a leading '0'
Use LCDWriteString to write string in appropriate position
Else
Use LCDWriteString to write string in appropriate position
End If

Function: LCDGameSetUp(void)
Description: Sets up the LCD screen for starting the game
Input: None
Output: None
Psuedocode: Read in GameType and set to static local variable
Set the LCD to output two lines
Clear both lines of the LCD
If the GameType is cooperative mode

Print out the corresponding cooperative mode screen

Else

Print out the corresponding versus mode screen

End If


Function: LCDGameEnd(int player1_score, int player2_score)
Description: Prints out the correct print out when the game ends
Input: None
Output: None
Psuedocode: If the GameType is cooperative mode
Do nothing
Else
If player1_score > player2_score, print out player 1 wins
Otherwise, print out player 2 wins
End If

Function: LCDResetGame(void)
Description: Resets the LCD to what it should read when the game has yet to begin
Input: None
Output: None
Psuedocode: Clear both screens
Use LCDWriteString to write "Insert Coin" to appropriate position

Function: LCDWaitTrigger(void)
Description: Prints out the correct message while waiting for the a trigger press
Input: None
Output: None
Psuedocode: Clear both screens
Use LCDWriteString to write "Pull Trigger to begin " to appropriate position


Private Level Functions:

Function: PulseEnable(void)
Description: Pulses the enable line of the LCD
Input: None
Output: None
Psuedocode: Set the enable line to be an output line
Set the enable line high
Wait at least 4 ms
Set the enable line low

Function: PulseClock(void)
Description: Pulses the clock of the shift register used to send data to the ports of the LCD
Input: None
Output: None
Psuedocode: Set the clock line to be an output line
Set the clock line high
Wait a very short amount of time
Set the clock line low

Function: SelectRegister(char type)
Description: Sets the register line of the LCD to recieve either data or a command
Input: char type (data or command)
Output: None
Psuedocode: Set the register select line to be an output line
If the char type is data
Set the register select line high
Else
Set the register select line low
End If

Function: LCD_Init_Ports(void)
Description: Sets the register line of the LCD to recieve either data or a command
Input: char type (data or command)
Output: None
Psuedocode: Set the register select line to be an output line
Set the enable line to be an output line
Set the input line (for the shift register) to be an output line
Set the clock line to be an output line
Set the register select line low
Set the enable line low
Set the input line low
Set the clock line low

Function: wait(unsigned int wait_time)
Description: Waits the specified wait_time in terms of ticks as initialized by the timers12 library
Input: unsigned int wait_time
Output: None
Psuedocode: Set startTime to the current time on the timer
While the current time - the startTime < wait_time
Do nothing
End Loop

Function: WriteToPorts(char portData)
Description: Writes the char portData to the ports of the shift register which correspond to the ports of the LCD
Input: char portData
Output: None
Psuedocode: Set variable curr_line to be equal to 1000 0000 (128)
Set the input line to be an output
Loop through the 8 bits that will be set to the shift register
Use bit wise manipulation with curr_line to get the value of the current line
If the current line is low
Set the input line low
Else
Set the input line high
End If
Wait a very short amount of time
Use PulseClock to pulse the clock line
Divide the curr_line by 2
End Loop