Serial Interface LCD circuit

Not rated 23,914

Circuit Image

The circuit consists of a PIC microcontroller, an in-circuit serial programming (ICSP) interface, an RS232 level translator, and an HD44780 LCD display. Initially, a scrolling message is shown using the show_intro function. When a serial input is detected, the main program commences. All keys are designated for either text entry or commands. An infinite loop continuously checks for key input. If the key is a hash symbol, the command is retrieved using the function get_prefix_and_execute_command(&x, &y). Otherwise, the key value is displayed on the LCD at the current cursor position.

Note: The use of x and y addresses (&x, &y) allows for passing the variable addresses to the called functions, enabling updates to the values of x and y in the main program through pointers. The get_prefix_and_execute_command function invokes execute_command, which retrieves another key from the UART (or waits for one). If the key matches a valid command, the corresponding code is executed to control the LCD. If it does not match, the UART1_unget_char function is employed to push the key back. Notably, the commands #X and #Y in execute_command utilize get_and_Set_X and get_and_Set_Y, using pointers without the need for address dereferencing, as px is a pointer returning its address when called. These functions invoke get_2dig_num, which expects more characters in the form of digits; if digits are not received, the key is pushed back using UART1_unget_char. The UART1_get_char and UART1_unget_char functions are complementary and are utilized in parsers (this program functions as a simplistic parser) to examine the next character of the input. If the character is not the expected one, UART1_unget_char is employed to store the current character in memory. The UART1_get_char function checks this memory first before retrieving a character from its standard input, ensuring effective operation. However, only one character can be ungotten at a time; for handling more, an array for unget storage would be necessary. These routines simplify the process by avoiding complex look-ahead algorithms or indexing, allowing a focus on the current character without needing to track an index. For a more extensive parser, the focus would shift to handling complete words.

The described circuit integrates various components to facilitate user interaction through a serial interface and an LCD display. The PIC microcontroller serves as the core processing unit, executing commands based on user input. The ICSP interface allows for programming the microcontroller, enabling updates and modifications to the firmware as needed. The RS232 level translator is crucial for ensuring compatibility between the microcontroller's logic levels and the serial communication standards.

The initial scrolling message displayed on the HD44780 LCD serves as a user interface element that provides feedback and informs the user about the system's status. Once user input is detected, the system transitions into a command processing mode where it can accept both textual input and specific commands, enhancing its functionality.

The infinite loop structure ensures the system remains responsive to user input, continuously checking for key presses. The use of a hash symbol as a command initiator allows for a clear distinction between standard text input and command execution, streamlining the user experience. The command retrieval process employs pointers to manipulate the values of x and y, facilitating dynamic updates to the system's state based on user interactions.

The UART communication functions enhance the program's ability to manage input effectively, allowing for a robust parsing mechanism that can handle unexpected characters gracefully. The design emphasizes simplicity and efficiency, with a focus on maintaining a responsive and user-friendly interface. These characteristics make the circuit well-suited for applications requiring real-time user interaction and feedback through a visual display.The circuit simply consists of a PIC micro, ICSP interface, an RS232 level translator and an HD44780 LCD. Initially a scrolling message is displayed using show_intro. When a serial input is detected the main program starts. All keys are now either text entry or commands. An infinite loop keeps checking for key input. If the key is a hash symbol then the command is fetched using: get_prefix_and_execute_command(&x,&y); Otherwise the key value is displayed on the LCD at the current cursor position.

Note: the use of x and y addresses (&x,&y) to pass the variable address through to the called functions so that values of x and y in main() are updated (using pointers in the called functions). get_prefix_and_execute_command calls execute_command which gets another key from the UART (or waits for one).

If it matches a valid command then the appropriate code is executed to control the LCD. If not then UART1_unget_char is used to push the key back. The most interesting commands in execute_command are #X and #Y which use get_and_Set_X and get_and_Set_Y, again using pointers (this time the address & de-reference is not used as px is a pointer that returns its address when invoked). These functions both use get_2dig_num which gets more characters expecting digits - if it does not get them it pushes the key back again using UART1_unget_char.

UART1_get_char, UART1_unget_char These complementary functions are used in parsers (this program is a very small parser) where you need to look at the next character of the input to see if you want to continue. If you don't i.e. its not the character you were expecting then you use UART1_unget_char to put the current character into memory.

The function UART1_get_char always checks this memory first before getting a character from its normal input so the system works well - but you can only do one unget-char at a time. For more you would need an array of unget storage etc. The routines let you avoid complicated look ahead algorithms or indexing - you can concentrate on the current character without knowing where an index is.

For a bigger parser you work with complete words. 🔗 External reference