PIC16C56 EEPROM 1: LCD User-Interface Terminal BASIC Stamp I Application Notes Introduction. This application note presents a program in PBASIC that enables the BASIC Stamp to operate as a simple user-interface terminal. Background. Many systems use a central host computer to control remote functions. At various locations, users communicate with the main system via small terminals that display system status and accept inputs. The BASIC Stamps ease of programming and built-in support for serial communications make it a good candidate for such user- interface applications. 1 The liquid-crystal display (LCD) used in this project is based on the popular Hitachi 44780 controller IC. These chips are at the heart of LCDs ranging in size from two lines of four characters (2x4) to 2x40. How it works. When power is first applied, the BASIC program initializes the LCD. It sets the display to print from left to right, and enables an underline cursor. To eliminate any stray characters, the program clears the screen. After initialization, the program enters a loop waiting for the arrival of a character via the 2400-baud RS-232 interface. When a character arrives, it is checked against a short list of special characters (backspace, control-C, and return). If it is not one of these, the program prints it on the display, and re-enters the waiting-for-data loop. If a backspace is received, the program moves the LCD cursor back one SWITCHES 03 1k (C) 1992 Parallax, Inc. +5V Vin 0 DB4 11 1 DB5 12 2 DB6 3 13 PC DB7 4 14 RS 5 4 6 E Vdd Vo Vss R/W DB0 DB1 DB2 DB3 6 7 231 57 8 9 10 BASIC STAMP GND +5 10k 10k 1k 22k (contrast) SERIAL OUT SERIAL IN Schematic to accompany program TERMINAL.BAS. Parallax, Inc. BASIC Stamp Programming Manual 1.9 Page 71BASIC Stamp I Application Notes 1: LCD User-Interface Terminal space, prints a blank (space) character to blot out the character that was there, and then moves back again. The second move-back step is necessary because the LCD automatically advances the cursor. If a control-C is received, the program issues a clear instruction to the LCD, which responds by filling the screen with blanks, and returning the cursor to the leftmost position. If a return character is received, the program interprets the message as a query requiring a response from the user. It enters a loop waiting for the user to press one of the four pushbuttons. When he does, the program sends the character (0 through 3) representing the button number back to the host system. It then re-enters its waiting loop. Because of all this processing, the user interface cannot receive charac- ters sent rapidly at the full baud rate. The host program must put a little breathing space between characters perhaps a 3-millisecond delay. If you reduce the baud rate to 300 baud and set the host terminal to 1.5 or 2 stop bits, you may avoid the need to program a delay. At the beginning of the program, during the initialization of the LCD, you may have noticed that several instructions are repeated, instead of being enclosed in for/next loops. This is not an oversight. Watching the downloading bar graph indicated that the repeated instructions actu- ally resulted in a more compact program from the Stamps point of view. Keep an eye on that graph when running programs it a good relative indication of how much program space youve used. The terminal program occupies about two-thirds of the Stamps EEPROM. From an electronic standpoint, the circuit employs a couple of tricks. The first involves the RS-232 communication. The Stamps processor, a PIC 16C56, is equipped with hefty static-protection diodes on its input/ output pins. When the Stamp receives RS-232 data, which typically swings between -12 and +12 volts (V), these diodes serve to limit the voltage actually seen by the PICs internal circuitry to 0 and +5V. The 22k resistor limits the current through the diodes to prevent damage. Sending serial output without an external driver circuit exploits an- other loophole in the RS-232 standard. While most RS-232 devices Page 72 BASIC Stamp Programming Manual 1.9 Parallax, Inc.