Pond Electronics - Home of the µFlash876 & µFlash876B embedded controllers, µStack & µConnect Bus.

µTerm Module - User Manual

The µTerm can provide an instant user interface for any µConnect enabled controller, such as the µFlash876B.

Introduction

An LCD/Keypad/Buzzer interface is one of the most common requirements in an embedded system. Unfortunately developing code to drive an LCD, scan a keypad and sound a buzzer can be an exercise in frustration, wasting a substantial part of the projects development time & budget. The µTerm addresses this problem by providing a fully debugged "plug & play" user interface module for any system equipped with a µConnect (buffered I2C) bus. Time saved in interface development means that you have more time for application development and ultimately results in development cost savings.

Note: While this manual was written for the original µTerm (now called the µTerm216), all information is also relevant to the new µTerm420 module.

 

Connecting to the µTerm

The µTerm is a fully compliant µConnect bus slave module. Therefore connection to the bus is a simple matter of plugging in a standard RJ45 UTP patch cable (which carries both signal and power). As with all µConnect slave modules the µTerm has a second RJ45 connector to allow simple expansion of the bus by daisy-chaining to the next module.

 

Communicating with the µTerm

All communication with the µTerm is via the µConnect bus using standard I2C protocol. The µTerm supports communications rates up to the I2C full speed of 100 Kbits/S. The default slave address of the µTerm is 4, however it can be configured in the range 1-16 allowing multiple µTerm modules on a single bus.

Printable characters sent to the µTerm are displayed at the current cursor position, the µTerm also supports a number of standard control characters (like FORM FEED '\f', LINE FEED '\r' and CARRIAGE RETURN '\r') as well as a number control sequences implementing high level functionality (such as PLOT BAR).

 

A quick example

Though the µTerm is a powerful and sophisticated device it is surprisingly easy to use. The following code fragment is written in CCS PIC C for the µFlash876B , the printf function of this compiler is particularly suited to use with the µTerm module.

To try this example simply connect a µTerm module to the µFlash876B using an RJ45 UTP patch cable, compile the code and download it to the µFlash, it will run automatically once download is complete and the message will appear on the µTerm display.

 

#include <uf876.h>          // include uFlash support code 
#include <uconn.h>          // include uConnect support code 
 
#define UTERM 0x0           // the uTerm default address
 
void main(void)
  {
  delay_ms(100);                        // 100 mS startup delay 
  uc_wstart(UTERM);                     // address the uTerm
  printf(uc_write,"\f");                // Form Feed
  printf(uc_write,"Hello World!\n");    // Write to first line
  printf(uc_write,"Hello again...\n");  // Write to second line 
  uc_stop();                            // all done
  }

 

µConnect Support Library

To facilitate easy use of the µConnect (and I2C) bus , we have made a support library available in source form. Please see our web site for availability of the library for your compiler. The library consists of 5 function calls as follows:

void uc_wstart(x);
starts a µConnect write sequence to address x

void uc_write(y);
write a single byte y to the addressed slave

void uc_rstart(x);
starts a µConnect read sequence from address x

BYTE uc_read(y);
read a char from addressed slave, set y=0 if this is the last read, else make y non-zero if you intend to read more bytes.

void uc_stop(void);
end a µConnect read or write sequence

 

Display Initialization

When the µTerm module is powered up it first initializes the LCD, this takes a short while so you should not send commands to the µTerm for at least 100 mS following power up.Once initialization is complete The µTerm then displays its start up message. The number to the right of the version number is the current I2C address of the module.

 

Writing data to the µTerm

The procedure for writing data to the µTerm module is as follows:

This procedure is illustrated below showing a 3 byte write to the µTerm.

 

Writing Data to the µTerm Module

 

This write sequence can be generated using the µConnect library code as follows:

uc_wstart(UTERM_ADDRESS);
uc_write(DATA0);
uc_write(DATA1);
uc_write(DATA2);
uc_stop();

 

The µTerm Virtual Display

When a series of "\n" terminated strings is sent to a terminal, the standard scrolling behavior always results in the last line being empty. This is not a significant problem in a standard 40 line terminal display, however on the µTerms LCD it results in the wastage of 50% of the screen area. To overcome this problem the µTerm implements a virtual 3 line display. The top two lines of this display area appear on the 2 line LCD, the third "wasted" line is maintained internally in the µTerm.

(Note: for the 4X20 char µTerm420 the virtual line is the 5th line)

The display sequence shown to the right illustrates the effect of a series of LINEFEED ('\n') terminated printf statements sent to the µTerm module.

Note that characters sent to the display while the cursor is located on the 3rd virtual line will not appear on the display until a LINEFEED character has been received causing the virtual line to scroll onto the physical display.

 

Control Characters

The µTerm supports a number of non-printable control codes and command sequences. The control codes are located at character codes 0x00 to 0x0f, some of these codes implement functions as per the ASCII code standard, others are specific to the µTerm and often take extra parameter bytes.

The examples accompanying each control code assume that all data written to the µTerm as part of a write sequence, ie bracketed by a START (write) and STOP condition as follows (assuming the µTerm default address 0x04):

uc_wstart(0x04);
// code for writing display characters 
// and/or control code sequences
// inserted here
uc_stop();

Note that multiple control codes and/or display characters can be sent as part of a single write sequence.

 

NULL Command <0x00>

The null command is reserved for future use

 

LOCATE CURSOR <0x01>

Moves the cursor to the specified location on the LCD.

Format : <0x01><row><col>

Example: Move cursor to location (0,8)

uc_write(0x01);
uc_write(0);
uc_write(8);

 

SET CURSOR MODE <0x02>

Format : <0x02><ctrl byte>

The ctrl byte can take the following values:

<0x00> Cursor OFF (the cursor is invisible)
<0x01> Cursor ON (the cursor is visible)
<0x02> Cursor FLASH (the cursor blinks on and off)

Note that even when the cursor is OFF all printable characters (not part of a control sequence) are still inserted on the display at the current cursor position, the effect of turning cursor off is simply to make the cursor invisible.

Example : Turn the cursor off (make it invisible)

uc_write(0x02);
uc_write(0);

 

SET DISPLAY MODE <0x03>

Format : <0x03><ctrl byte>

The ctrl byte can take the following values:

<0x00> Display OFF (all characters are invisible )
<0x01> Display ON (all characters are visible)
<0x02> Display FLASH (all characters flash on and off)

Note that when the display is off characters can still be written to the LCD, these characters will become visible when the display is once again turned on. The effect of turning off the display is simply to make the contents of the display invisible.

Example : Make display flash

uc_write(0x03);
uc_write(0x02);

 

PLOT BAR <0x04>

Plot a horizontal bar from the current cursor position. The bar is specified in pixels, 5 pixels is equivalent to one character width.The maximum display width for the µTerm is 16 characters or 80 pixels. Once the bar has been plotted the cursor will be located at the character position following the end of the bar.

Format : <0x04><size>

The size byte specifies the bar length in pixels.

Example : Plot a bar 22 Pixels in length

uc_write(0x04);
uc_write(22);
 

SET BUZZER PATTERN <0x05>

Set the alert buzzer pattern. Once set, the buzzer will constantly repeat the specified buzzer pattern until a new pattern is set (or the µTerm is reset).

Format : <0x05><bphigh><bplow>

bphigh - buzzer pattern high byte
bplow - buzzer pattern low byte

Each bit in the 16 bit pattern cycled through on a continuous basis, a 1 in the current bit position turns the buzzer on, a zero turns it off. In this way the buzzer can be made to generate a number of distinct alarm patterns. Some useful patterns include:

<0x0000> Buzzer off
<0xffff> Buzzer on continuously
<0x00ff> Continuous beeps, equal length and spacing
<0x0001> Continuous cycle of short beep, long space
<0x00aa> Continuous 4 short beeps followed by a space

The buzzer pattern generator operates independently of the keyboard beep and BELL control character.

Example : Set buzzer to equal on/off pattern

uc_write(0x05);
uc_write(0x00);
uc_write(0xff);

 

FLUSH KEYBOARD BUFFER <0x06>

Flushes any characters in the µTerm keyboard buffer leaving it empty. This command takes no parameters.

Example : Clear the keyboard buffer

uc_write(0x06);

 

BELL <0x07>

The ASCII BELL character causes the buzzer to emit one short beep. This command takes no parameters.

Example : Sound one short beep on buzzer

uc_write(0x07);

 

BACKSPACE <0x08>

The ASCII BACKSPACE character moves the cursor back one character on the current line. Note as is common with most terminals, this simply moves the cursor position, it does not delete or overwrite any characters. This command takes no parameters.

Example : Move the cursor back one character space

uc_write(0x08);

 

TAB <0x09> '\t'

The ASCII HORIZONTAL TAB character causes the insertion of spaces from the current cursor position to the next tab stop. On the µTerm, tab stops are fixed at 4 character intervals. This command takes no parameters.

Example : Move cursor to next tab location on current line

uc_write('\t');

 

LINEFEED <0x0a> '\n'

The ASCII LINE FEED character, clears from the current cursor position to the end of the current line then sets the cursor to the beginning of the next line. If necessary the virtual display area is scrolled up to accommodate the new line. This command takes no parameters.

Example : Write a message and advance cursor to the next line (using the CCS PIC C printf function)

printf(uc_write,"Hello World\n");

 

RESERVED <0x0b>

This code is reserved for future use.

 

FORM FEED <0x0c> '\f'

The ASCII FORM FEED character, clears the display and places the cursor in the home position (0,0). This command takes no parameters.

Example : Clear the display

uc_write('\f');

 

CARRIAGE RETURN <0x0d> '\r'

The ASCII CARRIAGE RETURN character, clears from the current cursor position to the end of the current line and resets the cursor back to the beginning of that line. This command takes no parameters.

Example : Write a value read from the ADC to the display, reposition the cursor at the beginning of the line read for update in a loop. (CCS PICC).

printf(uc_write,"ADC Val=%d\r",read_adc());

 

DEFINE CUSTOM CHARACTER<0x0e>

This commands allows you to configure custom characters for the display.

Format : <0x0e><ccode><p0><p1><p2><p3><p4><p5><p6><p7>

<ccode> The character code to update, The custom characters are located at codes 0x10 to 0x17. Note that codes 0x10 to 0x13 inclusive are used by the plot bar command and so should not be redefined if your are using the bar plotting function.

<P0> to <p7> New pixel map for the specified character code. Please see the section on custom characters for details of character pixel mapping.

Example : redefine the char code 0x15 to be a summation char. (this could also be done with a loop and a data array),

uc_write(0x0e);  // Define Custom char cmd
uc_write(0x15);  // char code to redefine
uc_write(0x0f);  // 8 bytes of new definition
uc_write(0x09);
uc_write(0x04);
uc_write(0x02);
uc_write(0x04);
uc_write(0x09);
uc_write(0x0f);
uc_write(0x00);

Once written the new character definition is stored in EEPROM on the µTerm and so is not lost even when the µTerm is reset or powered down.

 

RESERVED <0x0f>

This code is reserved for future use.

 

The Keyboard Interface

The µTerm module can be interface to up to 16 keys arranged in a 4X4 key matrix. The diagram to the right illustrates the proper connection to a matrix keypad.

The µTerm automatically scans the keyboard, debounces any keypresses and handles autorepeat for keys held down. For each keypress or autorepeat event detected the µTerm places the associated key scan code a 16 entry key buffer and causes the buzzer to emit a short click. Key presses are retrieved from the buffer by the µConnect master initiating an I2C read from the µTerm. If the buffer is empty a read returns a NULL (0) character else the scan code for the next key in the buffer (1-16). The µTerm will also return the character code 0xfe for the first read following a reset or power up event.

Code (Decimal)

Code (Hex)

Meaning

0

0x00

Key buffer empty

1-16

0x01-0x0f 

Scan code of new keypress

254

0xfe

Module has been reset

Pressing a key when the key buffer is full results in the buzzer emitting a long beep.

 

Reading from the µTerm

When a key is pressed its scan code is placed in the µTerm key buffer, to read characters from the buffer simply execute an I2C read operation from the µTerm slave address. The procedure to read a single byte from the key buffer is as follows:

Reading from the µTerm key buffer

To generate the sequence above using the µConnect library use:

uc_rstart(UTERM_ADDRESS);
x=uc_read(0);
uc_stop();

The byte variable x now contains a character taken from the keyboard buffer.

 

Example : CCS PIC C code to display the scan code of each key as it is pressed

 

#include <uf876.h>            // include uFlash support code 
#include <uconn.h>            // include uConnect support code 
    
#define UTERM 0x04            // the uTerm default address 
    
void main(void) 
  { 
  BYTE key; 
   
  delay_ms(100);                            // 100 mS startup delay 
  while(1) 
      { 
      uc_rstart(UTERM);                     // address the uTerm (read) 
      key=uc_read(0);                       // read 1 byte and then NAK 
      if(key)                               // if key code is non zero 
          { 
          uc_wstart(UTERM);                 // address the uTerm (write) 
          printf(uc_write,"Key:%d\r",key);  // print the key code 
          } 
      uc_stop();                            // all done 
      delay_ms(100);                        // 100ms between scans 
      } 
  } 

 

Setting the µTerm to an alternate I2C address

When supplied the µTerm responds to an I2C address of 4. If you want to place more than one µTerm module on the bus you will need to select different addresses for each module. To set a new slave address on a module you will need a 16 key keypad attached, the procedure is as follows.

  1. With the µTerm powered down, press and hold the keys with scan codes 1 and 13.
  2. Power up the µTerm
  3. Release the keys
  4. When prompted press the key with the required new address as a scan code. (ie to set the address to 16 (Hex 0x0f) press the bottom right key.)
  5. The µTerm will now store this new setting in on board EEPROM memory and will now only respond to messages addressed to this new location.

 

Defining Custom Characters

The µTerm supports up to 8 custom defined characters located at character codes 0x10-0x17. These can be set using the DEFINE CUSTOM CHAR command (0x0e). The format is as follows:

<0x0e><ccode><p0><p1><p2><p3><p4><p5><p6><p7>

<0x0e> DEFINE CUSTOM CHAR command
<ccode> The character code to update
<P0> to <p7> New pixel map for the specified character

The diagram to the right shows the relationship between pixel map and the character appearance. Bit numbers 5-7 in each pattern byte are unused. Note that while the last line (defined by p7) can be used, it is normal to leave it blank as this line is used by the cursor.

Once a symbol is written to the µTerm it is stored in on board EEPROM and so remains defined even when the µTerm is reset or powered down.

 

The µConnect library code to load the euro symbol into character position 0x14 is therefore:

uc_wstart(UTERM);  // address the uTerm
uc_write(0x0e);    // DCC command
uc_write(0x14);    // char to update
uc_write(0x00);    // p0
uc_write(0x00);    // p1
uc_write(0x07);    // p2
uc_write(0x08);    // p3
uc_write(0x1e);    // p4
uc_write(0x08);    // p5
uc_write(0x07);    // p6
uc_write(0x00);    // p7
uc_stop();class="right"

 

The µTerm is shipped with the following custom characters preset:

0x10 - 1 pixel bar (used by plot bar function)
0x11 - 2 pixel bar (used by plot bar function)
0x12 - 3 pixel bar (used by plot bar function)
0x13 - 4 pixel bar (used by plot bar function)
0x14 - The euro symbol (as in the example)
0x15 - The pound sterling symbol (£)
0x16 - The up arrow symbol
0x17 - The down arrow symbol

 

Code

0x00

0x10

0x20

0x30

0x40

0x50

0x60

0x70

0x00

RES

X0

Space

0

@

P

`

p

0x01

LC

X1

!

1

A

Q

a

q

0x02

SCM

X2

"

2

B

R

b

r

0x03

SDM

X3

#

3

C

S

c

s

0x04

PB

X4

$

4

D

T

d

t

0x05

SBP

X5

%

5

E

U

e

u

0x06

FKB

X6

&

6

F

V

f

v

0x07

BEL

X7

'

7

G

W

g

w

0x08

BS

RES

(

8

H

X

h

x

0x09

TAB

RES

)

9

I

Y

i

y

0x0a

LF

RES

*

:

J

Z

j

z

0x0b

RES

RES

+

;

K

[

k

{

0x0c

FF

RES

,

<

L

l

|

0x0d

CR

RES

-

=

M

]

m

}

0x0e

DCC

RES

.

>

N

^

n

RAR

0x0f

RES

RES

/

?

O

_

o

LAR

µTerm codes 0x00 - 0x7f

Reserved (do not use)

Command code

ASCII character code

User defined characters

Predefined glyphs

The µTerm Character Set

RES

Reserved

LC

Locate Cursor command

SCM

Set Cursor Mode command

SDM

Set Display Mode command

PB

Plot Bar command

SBP

Set Buzzer Pattern command

FKB

Flush Key Buffer command

BEL

ASCII Bell char

BS

ASCII Back Space char

TAB

ASCII Horizontal TAB char

LF

ASCII Line Feed char

FF

ASCII Form Feed char

CR

ASCII Carriage Return char

DCC

Define Custom Char command

RAR

Right Arrow char

LAR

Left Arrow char

Character codes 0x80-0xff contain a number of predefined glyphs including some oriental characters, greek characters & mathematical symbols. For details please refer to the Hitachi HD44780 (LCD display driver) data sheet.

 

Home | Products | Technical Info | How to Order | Contact Us | Links