Knowledge Base
Valid For#HMI
Applies ToHMI430

This function prints text on the LCD.

Function Prototype
#HMI Print(
"\C" | "\R" | "\RR"
"text" | values,
"text" | values,
etc
)
ParameterOptionDescription
“\C” or “\R” or “\R\R”optional“C”entering or “R”ightAlign or “R”esume”R”ightAlign directive.  This MUST be placed at the start of the string.  SimpleHMI will then perform the required alignment on everything in this print statement.
“text”optional, multipleA string to display.  This may occur more than once.   
valuesoptional, multipleValues to print, refer to the formatting functions chapter.
Description

This function prints text and values within the current bounds.  It uses the font as specified by SetFont() and colours as specified by SetColours().  There’s not really any limit to how many arguments you can provide to the Print() instruction, but try to keep it short to allow other parts of your program a chance to run.

C style carriage return “\r” or linefeed “\n” escape sequences may be used to print on the next line.  Characters on the next line will have the same alignment, that is, they will also be left aligned, centered or right aligned.

Values either from byte or floating point registers or from RAM may be printed using the formatting functions.

Centering and Right Alignment

Print() can use the current bounds to display your message either:

  • From the current cursor position.  This is the default.
  • Or horizontally centered within the current bounds, via “\C” (note this MUST be a capital C).
  • Or right aligned against the edge of the current bounds, via “\R” (note this MUST be a capital R).
  • Or to resume the right alignment, that is, to prepend more text to the existing right aligned text on the current line, via “\R\R” (note these MUST be capital R’s).
Examples
   #HMI Print( "\CHello World\nThe count is ", b(=x), "units" )

 Assuming the X register is 46, this will display the following message, horizontally centered:

Hello World
The count is 46units
   #HMI SetFont( "sysdefault.fon" )
#HMI SetBounds( x:50px, b:3, w:200px, h:3 )
#HMI SetColours( f:HUEkGreen, b:HUEkOrange )
#HMI Cls()
#HMI Print( "\C\r", f(*fTemperature, 4, 1), "°C" )
#HMI SetBounds()
#HMI SetColours( f:HUEkWhite, b:HUEkTransparent )

This will display the temperature in green as held in the variable “fTemperature”, centered within an orange 3 line box.  It is very good practice to remove the bounds via “#HMI SetBounds()” when you’ve finished with the bounds.  This allows other parts of your program to assume the bounds is the whole screen.  In this example, the following things are assumed to exist in the program:

HUEkWhite        #EQU 'FFFFFFFF
HUEkTransparent #EQU '00000000
HUEkGreen #EQU 'FF00C000
HUEkOrange #EQU 'FFFF9000

fTemperature defFLOAT
Low Level

If you need to do something unusual with Print and the built in formatting functions don’t provide the required functionality, then you can roll your own.  The serial command that instructs the HMI controller to print takes this form:

1, “@”, “Test Message”, 3

Where

  • 1 = StartOfMessage marker
  • @ = Print instruction
  • 3 = EndOfMessage marker

So here’s an example the echos text received on the serial port to the LCD, centering it too:

   iiPrintText    COMHMI,1,"@"   ;being print instruction
iiPrintText COMHMI,"\C" ;request centering
_DisplayLoop
COMRx_ReadOne COM0 ;get a character from the serial port
RtoX ;end if nothing..
GoIfnz _EndDisplay ;..in buffer
iiChrPrintX COMHMI ;display this character
Goto _DisplayLoop
_EndDisplay
iiPrintText COMHMI,3 ;end print instruction