Serial LCD Kit LCD #117 (formerly LCD #107) with Variable LED Backlight



Introduction.

(May 18, '06). The LCD #117 kit replaces the LCD #107. The LCD #117 adds a number of capabilities.

These added capabilities are noted in parenthesis in the following discussion.

[For PICAXE users, I suggest the LCD #118 Kit This is the same as the former LCD #117 except that the baud rate is 2400. In addition, the LCD #118 uses a more precise external 4.0 MHz resonator.]

The LCD #117 kit includes a programmed PIC16F648A (18-pin DIP) or similar, a 4.7K resistor for the /RESET of the PIC, a 330 and 4.7K resistor for biasing the contrast of the interfacing LCD, a TIP41 NPN transistor as associated 330 Ohm resistor for controlling the intensity of the LED backlight, a small supply of 22 AWG solid wire (four colors) suitable for use on a solderless breadboard and schematics. This kit was designed for tinkerers using a solderless breadboard. A PCB is not provided.

Note that this kit does not include an LCD. I have a number which are available including the 20X4 Character LCD with Yellow - Green Back light shown above. I also include a 4.7 Ohm (0.5W) and 39 Ohm (3W) current limiting resistor which may be used to limit the back light LED current to a maximum of nominally 200 mA when using either a +5 VDC or a +12 VDC source, respectively.

The LCD #117 PIC processor is code protected and the source code is not provided.

I believe this to be the most versatile serial LCD interface available on the market, with a 64 byte receive buffer, the ability to interface with a variety of LCD geometries, EEPROM storage of the LCD geometry, a customized text screen, eight user defined characters, tab size and cursor style, the ability to display normal text and "big numbers", a rich plain language instruction set, five general purpose outputs and an interface with a speaker or similar to provide a "beep".

The programmed PICs (16F648A or similar) may be purchased in bulk; $34.95 / 10, $295.00 / 100. Note this includes only the programmed PICs. Feel free to sell these to others or incorporate them in your product.

If you would like a baud rate other than 9600, I can supply 300, 1200, 2400 or 19.2K. There is a $10.00 charge for this. For 38.4K and 57.6K, please contact me.


  • LCD #117 Kit with the 20X4 LCD with Yellow Green Backlight as shown in the photo above. I also provide the header pins and a 4.7 Ohm (1/2 W) and 39 Ohm (3W) for limiting backlight current when using backlight sources of +5 VDC and +12 VDC, respectively. $19.95

    Other enthusiasts offer this design along with a printed circuit board in kit form.


    This is a combination of my LCD #117 PIC, an assembled printed circuit board from Modern Device, a 20X4 LCD with Yellow / Green backlight and interfacing connector. This is fully assembled. (I normally provide this with a 9600 baud interface. If you would like 19200 baud, please include a note with your PayPal payment.) - $29.95


    This is a combination of my popular LCD #117 Kit, a K107 printed circuit board from Wulfden.org and a quality 4X20 LCD with blue backlight. Note that this is a fully assembled unit. $39.95.

    Rear View.

    Documentation.

    Introduction.

    This design provides an interface between a 9600 baud serial line from a Microchip PIC, Parallax Basic Stamp, NetMedia BX24 and similar and a character LCD having an HD44780 interface.

    The serial interface is TTL. That is, the idle state is a TTL logic one, or near +5 VDC. This is often termed non-inverting or true. This provides direct compatibility with the UART associated with a PIC, SerOut on a Basic Stamp and Com3 on a BX24. When interfacing with a PC or similar where the logic is inverted, an inverter is required. This might be as simple as a single 2N3904 NPN transistor.

    The baud rate is fixed at 9600. My feeling is that virtually any application can support 9600 baud and to provide the ability to change the baud rate in firmware is bad design as it opens the possibility of the unit inadvertently assuming a baud rate which is not compatible with the interfacing circuitry.

    The processor provides for variable backlight intensity. The backlight current is controlled by a TIP-41 transistor which is included with the kit. The maximum backlight intensity is controlled with a series limiting resistor.

    The processor does not provide for variable contrast. Two fixed resistors, 4.7K and 330, are included in the kit to provide nominally 0.3 VDC for contrast. However, the user may wish to use a potentiometer.

    The processor provides a 64 character buffer. However, delays of nominally 100 ms are required after sending a command which requires the LCD processor to write to it's EEPROM.

    A source of +5 VDC with a minimum current of 10 mA is required for this design. This excludes backligght current. If the interfacing LCDs LED back light feature is used, the back light current must be limited to less than 250 mA.


    LCD Commands.

    A list of various text manipulation commands follows. Note that all commands are prefaced with a "?" and the commands are case sensitive.

    ?a - set cursor to home position.
    ?b - destructive backspace
    ?f - clear LCD and leave cursor at home position
    ?g - beep
    ?h - backspace
    ?i - forward cursor
    ?j - up cursor
    ?k - down cursor
    ?l - clear current line and leave cursor at the beginning of the line
    ?m - carriage return.  Position the cursor at the beginning of the current line.
    ?n - new line.  Advance to the beginning of the next line and clear this line.
    ?t - tab.  Advance the cursor one tab.
    
    ?? - display the character '?'.
    

    Note that the "?g" causes a 50 ms burst of nominally 500 Hz on a processor output. The LCD #117 kit does not include the interfacing audible device.

    The cursor may be set to any position using the x and y commands;

    ?y0
    ?x15
    
    Note that the line number, follows the 'y' command and the column number, consisting of two digits, follows the 'x' command.

    Thus, outputting the string;

        "?y1?x10Hello?n"
    
    positions the cursor at column 10 of line 1 and then prints "Hello", followed by a newline which also clears the next line.

    Note that the line and column numbers begins with 0. Thus, for a 4 X 20 LCD, valid lines are 0 - 3 and valid columns are 00 - 19.

    Any of eight user defined characters may be displayed using the digits 0 - 7. Thus;

    	"?5?2"
    
    causes user defined character 5 followed by user character 2 to be displayed on the LCD. Defining the user characters is discussed below.

    (New with the LCD #117). A user text screen may be displayed at any time using the command;

        "?*"
    
    I ship this with the customized text message as simply all numbers and characters. This may be modified using the ?C command which is discussed below.

    Big Number Mode (New with LCD #117). This capability is operational only when using a 20X4 LCD.




    The LCD #117 design provides both three and four block wide characters. The big number mode is entered;

        "?>3"
    or
        "?>4"
    
    On receipt of either of the "?>3" or "?>4" commands, the processor will download to the LCD the special characters required to display the big numbers. These are probably different from any user defined characters which the user may have defined. Thus, don't display your user defined characters when displaying in the "big number" format.

    The cursor is then located on the top row of the current column.

    In the >3 mode, as each numeric digit is received, it will erase anything appearing in the three column wide by four high space and display the number in the big number format. In addition, it will clear the column to the right of the character. The cursor will then be located at the top row for display of the next digit. Note that for the three block wide mode, this is four columns to the right of the upper left of the previous character. Thus, each digit uses four columns, three for the display of the digit and one for the spacing between digits.

    Display of the minus sign, colon and decimal point use two columns, one for the display of the symbol plus one space.

    The >4 mode is similar, except that each digit is four wide plus one space.

    There is no intelligent "wrapping" provision for the "big number" mode. Thus, if there are only two columns remaining before the end of the LCD and you attempt to display a "7", part of the "7" will appear on the right side of the LCD, and the rest on the beginning of the display.

    The big number mode may be exited at any time:

        "?<"
    

    This may be used to display ordinary text along with the "big number" characters. For example, in one of the photos, the message "4X4 Demo" appears. This might be done;

        "?<"  ' exit the big number mode
        "?y0?x164X4"  ' row 0, beginning at column 16 - 4X4
        "?y1?x16Demo" ' row 1, beginning at column 16 - Demo
    

    Note that the "?< command simply exits the "big number" mode. It does not download the user defined characters that might be used for graphics.

    If one later wishes to use the user defined characters;

        "?R"  ' restore the user defined characters.
    
    Again, note that the characters associated with the display of the "big number" characters are not compatible with the user defined characters one might use for plotting and thus, "big numbers" and graphics type applications using specially defined characters cannot coexist on the display.

    Configuration Commands.

    A number of parameters are stored in the processors EEPROM. This includes the geometry of the LCD, the type of cursor, the number of spaces in a tab, the eight user defined characters, defining a custom splash screen of text, selection of the screen which is displayed on boot and the backlight intensity setting.

    The default is a 20 X 4 LCD, a tab size of 4, a full blinking cursor (3), eight user defined characters consisting of a single horizontal line, two horizontal lines, etc., a backlight intensity setting of 40, a text screen consisting lower case letters "a-t", "A-T" and two rows of numbers (see photo). The default screen which is selected for bootup is the configuration screen which displays the geometry, tab size, specially defined characters, the backlight setting and the cursor type.

    All of these parameters may be modified. Note that when the modifications are made, the new values are written to the processor's EEPROM and thus need only be modified once.

    Note that after sending commands which cause the processor to save data to EEPROM, provide a 100 ms delay prior to sending additional characters. Otherwise the addtional characters may be lost.

    Set LCD Geometry

    Setting the geometry defines the configuration of the interfacing LCD.

    ?Gyxx
    
    For example;
       "?G216"
    
    indicates the LCD is a 2X16 configuration.

    Note that appropriate configurations include 2X16, 2X20, 2X24, 2X40, 4X16 and 4X20.

    The configuration is important for the processor to properly position the cursor after each text character is displayed and in executing such commands as backspace, up cursor, down cursor, new line, etc.

    Set Tab

    The tab size may be set;

    	"?s5"
    
    In this case, the tab size is set to five. Valid values of the tab are 1 - 8.

    When this command is received by the processor, the new tab size is written to EEPROM and this value is used thereafter when executing the ?t command.

    When executing the ?t command, the cursor is advanced, and any characters in its path are overwritten with a space. For example, if the cursor is in column 3 and the tab size is 5, the cursor will advance to column 5. Anything in columns 3 and 4 will be replaced with spaces.

    Backlight Intensity

    The intensity of an LED backlight on the associated LCD may be adjusted;

        "?B80"
    
    Note that the digits following the "B" are two digit hexadecimal, ranging from 00 (back light off) to FF (back light full on). This command causes an output to change duty cycle over the range of 0 to 255/256. The output may be used to switch a power transistor which then controls the avarage backlight current.

    Set Cursor Style

    The style of the cursor may be set using the ?c command.

    	"?c3"
    
    where the number is in the range of 0-3. A 0 configures as no cursor, a 2 as a non blinking cursor and a 3 as a blinking cursor. As with the set geometry and set tab, the style of the cursor is saved to EEPROM.

    User Defined Characters.

    User defined characters may be defined using the ?D command;

    	"?D300000000001f1f1f"
    
    The number after the 'D' is the number associated with the user defined character, in this case user defined character 3. This is then followed by the eight data bytes expressed in two digit hexadecimal. Note that the hexadecimal letters must be lower case.

    In this example, lines 0, 1, 2, 3 and 4 consist of no pixels and lines 5, 6 and 7 consist of all five pixels. Thus, when user defined character 3 is displayed using the command ?3, a character consisting of the lower three lines will be displayed.

    Each user defined character is saved in EEPROM.

    Custom Text Screen (New with the LCD #117).



    The customized text screen may be an advertisement which is displayed on boot or a template which may be displayed at any time. It is set using the ?C command, followed by the row, followed by the twenty characters which are to appear on the row. For example, the following sequence defines the custom screen shown in the photo.

        "?C0abcdefghijklmnopqrst"
        "?C1ABCDEFGHIJKLMNOPQRST"
        "?C201234567890123456789"
        "?C398765432109876543210"
    

    Note that this custom screen may be displayed at any time;

        "?*"
    

    Boot Screen Selection (New with the LCD #117).

    The screen which is displayed on boot may be specified using the ?S command followed by a number, 0, 1 or 2.

       "?S1"  ' display the configuration setting on boot
       "?S0"  ' display no screen on boot.
       "?S2"  ' display the user custom text screen on boot.
    

    Direct Control of the LCD.

    Commands may be directly passed to the LCD using the ?! command;

    	"?!01"
    
    In this example the command 01 is sent directly to the LCD which clears the LCD.

    A word of caution. With all other commands the program keeps track of the current cursor position. This is not done with commands sent directly to the LCD using the ?! command. Thus, if the user configures the LCD such that the cursor is located at some point, subsequent line feeds and similar will not work correctly as the program does not know the current cursor location.

    Clearly, if the ?! command is used to place the LCD in a mode such that the cursor is decremented with each character or the display itself is scrolled, the subsequent operation of the LCD which assumes an incrementing cursor and a fixed display will give unpredictable results.

    General Purpose Outputs

    The LCD #117 provides four general purpose TTL outputs. Any of these outputs, 4 - 7, may be brought high or low using the 'H' and 'L' commands.

    	"?H4?L7"
    
    The above brings output 4 high and output 7 low. Note that outputs 0, 1, 2 and 3 are not valid.

    On power up, all outputs are at a high impedance (configured as inputs). As each output is addressed, it is taken out of the high impedance state. The initial high impedance state permits the user to use either pull up or pull down resistors to avoid "bounce" when the processor is powered.

    The current (source or sink) by any output should be limited to 15 mA.


    Assembly

    Content of the Kit.

    Please take a few seconds to acquaint yourself with the content of the kit.

    It consists of;

    1 	Programmed Microchip PIC16F648A (or similar) Processor (18-pin DIP).
    1	4.7K Resistor for the /MCLR on terminal 4 of the processor
    1 	4.7K Resistor for LCD contrast.
    1	330 Ohm (Orange, Orange, Brown) for LCD contrast.
    
    1   TIP-41 NPN Power transistor and 330 Ohm base resistor.
    
    1	5V LED with integrated series limiting resistor for debugging.
    
    1	Bundle of 22 awg solid wire suitable for use with a solder less breadboard.
    
    

    Assembly.

    Wire the circuitry as shown in Fig #1,

    Note that the programmed PIC is an 18-pin DIP device with terminals 1-9 on one side and terminals 10 (across from terminal 9) through 18 on the other side. Integrated circuits are descendants of vacuum tubes and the terminal assignment is in a circular counter clockwise fashion as viewed from the top.

    The layout of the LCD terminals is illustrated on the extreme right of the figure. It has been my experience that most LCDs have either an array of 14 terminals arranged in a single line or 2 lines of 7 terminals. If the LCD has an LED back light there may also be terminals 15 and 16. However, occasionally, I have seen other arrangements and it is best to consult the LCD data sheet for the LCD terminal numbers.

    Note that there is a 4.7K pull up resistor to +5 VDC on the /MCLR terminal (term 4 of the PIC processor). The processor may either be reset by applying power, or by momentarily grounding the /MCLR terminal.

    Note the OP/TEST input on terminal 8 of the processor. For the moment, leave this input open.

    Prior to applying +5 VDC and GRD to the circuit, carefully check that +5 VDC is on terminal 14 of the PIC and terminal 2 of the LCD. Carefully, check to verify ground is on terminal 5 of the PIC and terminal 1 of the LCD.

    Apply power and verify the LCD displays the geometry of the LCD, the tab size, eight user defined characters and a blinking cursor. The unit is shipped with a 4 X 20 geometry, a tab size of 4, user defined characters of a single row of pixels, two rows, three rows, etc and a blinking cursor.

    This screen message appears for about two seconds and the LCD is cleared and the cursor is positioned at the home position. The LCD is now awaiting the receipt of characters to display. Momentarily ground the /MCLR (term 4) on the PIC processor to reboot the processor and the message will again appear for two seconds.

    If the message does appear, it verifies that both the processor and the LCD are operational and the associated wiring is correct.

    Troubleshooting the LCD circuitry

    If the screen message does not appear.

    Assembly Continued.

    Serial Communication.

    Note that the LCD #117 processor is designed to interface with 9600 baud serial using TTL levels. When idle, the serial line is near +5 VDC. A start bit, is a TTL logic zero pulse for one bit time (1/9600 or about 104 usecs). This is then followed by each of the eight bits followed by a return to idle, a TTL logic one. This is often referred to as non-inverting.

    If you are interfacing with a PIC processor having a UART, the output is non-inverting and is thus, directly compatible with the LCD #117.

    For a Basic Stamp 2, this is implemented;

    	SerOut 5, 84, ["Hello World?n"]
    
    For a BX24 using COM3 this is implemented;
       Call DefineCom3(0, OutputPin, &H08)
       Call OpenSerialPort_3(9600)
    

    However, with a PC COM Port or similar, a logic one is less than nominally -8 VDC and a logic zero is greater than +8 VDC. With newer laptops and and with COM1 of the BX24, these levels may be somewhat less, say, 0.0 for a logic one and +5 VDC for a logic zero and thus, an inversion and level shift is required to interface with the LCD #117. This is often performed by a MAX232, A simpler circuit using a single 2N3904 is illustrated in the lower left of Figure #1.

    Sample Routines

    Many of the features of the LCD #117 are illustrated in the following routines which was written for the Parallax Basic Stamp 2 and the BasicX BX-24. Note that the "beep" function may be tested using the test LED on terminal 6 of the PIC. Operation of the 'H' and 'L" output commands may be similarly tested using the test LED.

    Parallax Basic Stamp 2 Example.

    
    ' LCD117_1.BS2  (Parallax Basic Stamp 2)
    '
    
    ' Configured for 9600 baud, 8 bits, no parity.
    '
    ' Basic Stamp 2		   		         LCD #117
    '
    ' P0 (term 5) -----------------------------------> RX (term 7)
    '
    '
    ' Sets geometry of LCD as 4X20 and clears the LCD and writes a byte in decimal and in hex
    ' an integer, a word, a character to the LCD display.
    '
    ' Defines, special characters 0 - 5 as no vertical lines, 1 vertical line, 2 vertical lines etc.  Displays an
    ' increasing bar and then a decreasing bar on line 3.
    '
    ' Enters an infinite loop winking outputs 7 and 6.
    '
    ' copyright, Peter H. Anderson, Baltimore, MD, Oct, '06
    
       BaudMode Con 84 	' 9600 baud, non-inverted
    
       N Var Byte
       I Var Byte
       WordVar Var Word
       ByteVar Var Byte
    
       NN Var Byte
       Remainder Var Byte
       Num_5 Var Byte
    
    
       Dir0 = 1	' make P0 an output
       High 0	' this is the steady state for non-inverted
       Pause 1000	' allow to stabilize
    
       SerOut 0, Baudmode, ["?G420"] ' configure LCD geometry
       Pause 200	' pause to allow LCD EEPROM to program
    
       SerOut 0, Baudmode, ["?B40"] ' set backlight to 40 hex
       Pause 200    ' pause to allow LCD EEPROM to program
    
       SerOut 0, Baudmode, ["?f"]  ' clear the LCD
    
       SerOut 0, Baudmode, ["     LCD #117?n"]  'note new line
    
       SerOut 0, Baudmode, ["www.phanderson.com?n"]
    
       SerOut 0, Baudmode, ["?0?1?2?3?4?5?6?7?n"]	' display special characters
    
       Pause 5000		' pause five secs to admire
    
       SerOut 0, Baudmode, ["?y1?x00"] ' cursor at line 1, col 0
    
       SerOut 0, Baudmode, ["?l?j?l?j?l?y1"]' clear lines 1, 2 and 3 and start at line 1
       					' note use of down cursor
    
       WordVar = 12345
       ByteVar = 123
    
    
       For N = 0 to 25
          SerOut 0, Baudmode, ["?x00?y1"]			' locate cursor to beginning of line 1
          SerOut 0, Baudmode, [Dec N, "?t", Hex N, "?t"]	' display N in Dec and Hex
          SerOut 0, Baudmode, [Dec ByteVar, "?n"]
          SerOut 0, Baudmode, [Dec WordVar, "?n"]	' display a word
          ByteVar = ByteVar + 1
          WordVar = WordVar + 1
          For I = 1 to 4
             SerOut 0, Baudmode, ["?g"] ' beep four times
             Pause 50
          Next
          Pause 500
       Next
    
       SerOut 0, Baudmode, ["?D00000000000000000"]		' define special characters
       Pause 200   ' delay to allow write to EEPROM
    
       SerOut 0, Baudmode, ["?D11010101010101010"]
       Pause 200
    
       SerOut 0, Baudmode, ["?D21818181818181818"]
       Pause 200
    
       SerOut 0, Baudmode, ["?D31c1c1c1c1c1c1c1c"]
       Pause 200
    
       SerOut 0, Baudmode, ["?D41e1e1e1e1e1e1e1e"]
       Pause 200
    
       SerOut 0, Baudmode, ["?D51f1f1f1f1f1f1f1f"]
       Pause 200
    
       SerOut 0, Baudmode, ["?c0"]		' no cursor
       Pause 200
    
       SerOut 0, Baudmode, ["?y3?x00?l"]	' cursor to beginning of line 3 and clear line
    
       For N = 0 to 25			' increasing bar
          SerOut 0, Baudmode, ["?y3?x00"]
          NN = 4 * N
          Num_5 = NN / 5
          Remainder = NN // 5
          For I = 1 to Num_5
             SerOut 0, Baudmode, 10,["?5"]
          Next
          SerOut 0, Baudmode, 10, ["?", Dec1 Remainder]
       Next
    
       Pause 1000
       For N = 0 to 25			' decreasing bar
          SerOut 0, Baudmode, ["?y3?x00?l"]
          NN = 4 * N
          NN = 100 - NN
          Num_5 = NN / 5
          Remainder = NN // 5
          For I = 1 to Num_5
             SerOut 0, Baudmode, 10, ["?5"]
          Next
          SerOut 0, Baudmode, 10, ["?", Dec1 Remainder]
       Next
    
       Do					' continually bring outputs 7 annd 6 high and low
          SerOut 0, Baudmode, ["?H7?L6"]
          Pause 500
          SerOut 0, Baudmode, ["?L7?H6"]
          Pause 500
       Loop
    


    Basic Stamp 2 - Big Number Example

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' LCD117_2.BS2  (Parallax Basic Stamp 2)
    '
    ' Illustrates displaying quantities using the Big Number (3-wide) format.
    '
    ' Continually calls a stub program which returns temperatures in the range
    ' of -99.9 to 999.9 and display on the LCD in the 3-wide big number format.
    '
    ' Configured for 9600 baud, 8 bits, no parity.
    '
    ' Basic Stamp 2                    LCD #117
    '
    ' P0 (term 5) -----------------------------------> RX (term 7)
    '
    ' Sets geometry of LCD as 4X20, sets backlight intensity to 40 hex and configures
    ' for no cursor.
    '
    ' Note that PBASIC 2.5 is used.
    '
    ' copyright, Peter H. Anderson, Baltimore, MD, Oct, '06
    
       BaudMode CON 84  ' 9600 baud, non-inverted
    
       N VAR Byte
       T_10 VAR Word
       TWhole VAR Byte
       TFract VAR Byte
       Digit VAR Byte
    
       DIR0 = 1  ' make P0 an output
       HIGH 0  ' this is the steady state for non-inverted
       PAUSE 1000  ' allow to stabilize
    
       SEROUT 0, Baudmode, ["?G420"] ' configure LCD geometry
       PAUSE 200  ' pause to allow LCD EEPROM to program
    
       SEROUT 0, Baudmode, ["?B40"] ' set backlight to 40 hex
       PAUSE 200    ' pause to allow LCD EEPROM to program
    
       SEROUT 0, Baudmode, ["?c0"] ' clear the cursor
       PAUSE 200
    
       SEROUT 0, Baudmode, ["?f"]  ' clear the LCD
    
    '   SEROUT 0, Baudmode, ["?>3"]  'note new line
    '   PAUSE 200    ' allow time for the new special characters to be downloaded.
    
    AGN:
       FOR N = 0 TO 7 ' for seven different temperatures
          SEROUT 0, Baudmode, ["?f"] ' clear the LCD
          SEROUT 0, Baudmode, ["?>3"]' big num 3 format
          PAUSE 200    ' allow time for the new special characters to be downloaded.
    
          GOSUB MeasTemp
    
          IF T_10 >= $8000 THEN  ' if sign bit is one, its negative
             T_10 = -T_10
             TWhole = T_10 / 10  ' separate off whole and fractional parts
             TFract = T_10 // 10
    
             IF TWhole > 9 THEN ' -10 to -99
                SEROUT 0, Baudmode, ["-"]
                Digit = TWhole / 10
                SEROUT 0, Baudmode, [DEC1 Digit]
                Digit = TWhole // 10
                SEROUT 0, Baudmode, [DEC1 Digit]
             ELSE         ' -0.0 to - 9.9
                SEROUT 0, Baudmode, ["?y0?x04"]
                SEROUT 0, Baudmode, ["-"]
                Digit = TWhole
                SEROUT 0, Baudmode, [DEC1 Digit]
             ENDIF
    
          ELSE    ' its positive
             TWhole = T_10 / 10
             TFract = T_10 // 10
             IF TWhole > 99 THEN   ' 100.0 - 999.0
                Digit = TWhole / 100
                SEROUT 0, Baudmode, [DEC1 Digit]
                TWhole = TWhole // 100
                Digit = TWhole / 10
                SEROUT 0, Baudmode, [DEC1 Digit]
                Digit = TWhole // 10
                SEROUT 0, Baudmode, [DEC1 Digit]
             ELSEIF TWhole > 9 THEN ' 10.0 to 99.0
                SEROUT 0, Baudmode, ["?y0?x02"]
                Digit = TWhole / 10
                SEROUT 0, Baudmode, [DEC1 Digit]
                Digit = TWhole // 10
                SEROUT 0, Baudmode, [DEC1 Digit]
             ELSE
                SEROUT 0, Baudmode, ["?y0?x06"]
                Digit = TWhole
                SEROUT 0, Baudmode, [DEC1 Digit]
             ENDIF
          ENDIF
          ' now the fractional part
          SEROUT 0, Baudmode, ["."]
    
          SEROUT 0, Baudmode, [DEC1 TFract]
    
          SEROUT 0, Baudmode, ["?<"]  ' Display "Deg F" in normal text
          SEROUT 0, Baudmode, ["?y1?x17"]
          SEROUT 0, Baudmode, ["Deg"]
          SEROUT 0, Baudmode, ["?y2?x17"]
          SEROUT 0, Baudmode, [" F "]
    
          PAUSE 2500
       NEXT
    
       GOTO AGN
    
       MeasTemp:
       ' This is a stub which returns various values of a temerature T_10
       ' It is intended to illustrate examples from -99.9 to 999.0
          LOOKUP N, [-123, -42, -8, 1234, 723, 72, 2], T_10
                    '-12.3, -4.2, -0.8, 123.4, 72.3, 7.2, 0.2
          RETURN
    


    Sample Code - BasicX BX24

    Download for BX24.

    ' LCD117.Bas  (BasicX BX24)
    '
    '
    ' Configured for 9600 baud, 8 bits, no parity.
    '
    '												     LCD #117
    '   BX24 (term 12) -----------------------------------> RX (term 7)
    '
    '
    ' Opens BX24 terminal 12 as SerCom3, 9600, noninverted, 8 bits per byte, no parity. Sets geometry of LCD as 4X20
    ' and clears the LCD and writes a byte in decimal and in hex, an integer, a long, a character and a single to the
    ' LCD display.
    '
    ' Defines, special characters 0 - 5 as no vertical lines, 1 vertical line, 2 vertical lines etc.  Displays an
    ' increasing bar and then a decreasing bar on line 3.
    '
    ' Enters an infinite loop winking outputs 7 and 6.
    '
    ' Compile with SerCom3.Bas
    '
    ' copyright, Peter H. Anderson, Baltimore, MD, Dec, '03
    
    Sub Main()
    
       Dim Num_5 as Byte, N as Byte, NN as Byte, J as Byte, Remainder as Byte
       Dim I as Integer, L as Long, F as Single
       Dim Str as String
    
       Call Sleep(3.0)
    
       Call SetupComPort(12, 9600, &H08)	' term 12, 9600 baud, inverted
       Str = "?G420"
       Call PutStr_3(Str)		      	' configure LCD as 4 X 20
    
       Str = "?Ba0"					' set backlight for LCDs having an LED backlight
       Call PutStr_3(Str)
    
       Str = "?f"
       Call PutStr_3(Str)			' clear the LCD and home the cursor
    
       Str = "     LCD #117?n"		' note new line
       Call PutStr_3(Str)
    
       Str = "www.phanderson.com?n"
       Call PutStr_3(Str)
    
       Str = "?0?1?2?3?4?5?6?7?n"		' display special characters
       Call PutStr_3(Str)
    
       Call Sleep(5.0)			' pause to admire
    
       Str = "?y1?x00"
       Call PutStr_3(Str)
    
       Str = "?l?j?l?j?l?y1"		' clear lines 1, 2 and 3 and start at line 1
       Call PutStr_3(Str)			' note use of down cursor
    
       L = 123456
       I = 12345
       F = 23.75
    
       For N = 0 to 25
          Str = "?x00?y1"			' locate cursor to beginning of line 1
          Call PutStr_3(Str)
          Call PutB_3(N)			'  display in decimal
          Str = "?t"
          Call PutStr_3(Str)
          Call PutHexB_3(N)			' display in hex
          Str = "?t"
          Call PutStr_3(Str)
          Call PutI_3(I+CInt(N))		' display an integer
          Str = "?n"
          Call PutStr_3(Str)
          Call PutL_3(L + CLng(N))		' display a long
          Str = "?t"
          Call PutStr_3(Str)
          Call PutByte_3(ASC("a") + N)	' display a character
          Str = "?t"
          Call PutStr_3(Str)
          Call PutS_3(F + CSng(N))		' display a single
          Str = "?g"
          Call PutStr_3(Str)		' beep
          Call Sleep(1.0)
       Next
    
       Str ="?D00000000000000000"		' define special characters
       Call PutStr_3(Str)
       Call Sleep(0.2)
       Str ="?D11010101010101010"
       Call PutStr_3(Str)
       Call Sleep(0.2)			' delay to allow write to EEPROM
       Str ="?D21818181818181818"
       Call PutStr_3(Str)
       Call Sleep(0.2)
       Str ="?D31c1c1c1c1c1c1c1c"
       Call PutStr_3(Str)
       Call Sleep(0.2)
       Str ="?D41e1e1e1e1e1e1e1e"
       Call PutStr_3(Str)
       Call Sleep(0.2)
       Str ="?D51f1f1f1f1f1f1f1f"
       Call PutStr_3(Str)
       Call Sleep(0.2)
    
       Str = "?c0"				' no cursor
       Call PutStr_3(Str)
    
       Str = "?y3?x00?l"			' cursor to beginning of line 3 and clear line
       Call PutStr_3(Str)
    
       For N = 0 to 25				' increasing bar
          Str = "?y3?x00"
          Call PutStr_3(Str)
          NN = 4 * N
          Num_5 = NN \ 5
          Remainder = NN Mod 5
          For J = 1 to Num_5
             Str = "?5"
             Call PutStr_3(Str)
          Next
          Str = "?" & CStr(Remainder)
          Call PutStr_3(Str)
       Next
    
       For N = 0 to 25			' decreasing bar
          Str = "?y3?x00?l"
          Call PutStr_3(Str)
          NN = 100 - 4 * N
          Num_5 = NN \ 5
          Remainder = NN Mod 5
          For J = 1 to Num_5
             Str = "?5"
             Call PutStr_3(Str)
          Next
          Str = "?" & CStr(Remainder)
          Call PutStr_3(Str)
       Next
    
       Do					' continually bring outputs 7 annd 6 high and low
          Str = "?H7?L6"
          Call PutStr_3(Str)
          Call Sleep(0.5)
          Str = "?L7?H6"
          Call PutStr_3(Str)
          Call Sleep(0.5)
       Loop
    
    End Sub