0 tutorial, 1 getting started, Tutorial – Rice Lake iRite IDE User Manual

Page 9

Advertising
background image

920i

Programming Reference - Tutorial

5

2.0

Tutorial

2.1

Getting Started

Traditionally, the first program a programmer writes
in every language is the famous “Hello World!”
program. Being able to write, compile, download, and
run even the simple “Hello World!” program is a
major milestone. Once you have accomplished this,
the basics components will be in place, and the door
will be open for you and your imagination to start
writing real world solutions to some challenging
tasks.

Here is the “Hello World!” program in

iRite

:

01

program HelloWorld;

02

03

begin

04

DisplayStatus("Hello, world!");

05

end HelloWorld;

This program will display the text

Hello, world!

on the

920i

’s display in the status message area, every time

the indicator is turned on, taken out of configuration
mode, or reset. Let’s take a closer look at each line of
the program.

Line 1:

program HelloWorld;

The first line is the program header. The program
header consists of the keyword program followed by
the name of the program. The name of the program is
arbitrary and made up by the programmer. The
program name; however, must follow the identifier
naming rules (i.e. an identifier can’t start with a
number or contain a space).

The second line is an optional blank line. Blank lines
can be placed anywhere in the program to separate
important lines and to make the program easier to read
and understand.

Line 3:

begin

The begin keyword is the start of the optional main
code body. The optional main code body is actually
t h e P r o g r a m S t a r t u p e v e n t h a n d l e r. T h e
ProgramStartup handler is the only event handler that
doesn’t have to be specifically named.

Line 4:

DisplayStatus("Hello, world!");

T h e s t a t e m e n t D i s p l a y S t a t u s ( " He l l o ,
world!")

is the only statement in the main code

b o d y. I t i s a c a l l t o t h e b u i l t - i n p r o c e d u r e
DisplayStatus with the string constant “Hello, world!”
passed as a parameter. The result is the text, "Hello,
world!" will be shown in the status area of the display
(lower left corner), whenever the startup event is fired.

Line 5: end HelloWorld;

The keyword end followed by the same identifier for
the program name used in line one, HelloWorld, is
required to end the program.

From this analysis, you may have gathered that only
the first and last lines were required. This is true, the
program would compile, but it would do nothing and
be totally useless. At a minimum, a working program
must have at least one event handler, though it doesn’t
have to be the ProgramStartup handler. We could have
written the HelloWorld program to display “Hello,
world!” whenever any key on the keypad was pressed.
It would look like this:

01

program HelloWorld;

02

03

handler KeyPressed;

04

begin

05

DisplayStatus("Hello, world!");

06

end;

07

08

end HelloWorld;

In this version, we chose to use the KeyPressed event
handler to call the DisplayStatus procedure. The
KeyPressed event will fire any time any key on the
keypad is pressed. Also notice that the begin keyword
that started the main code body, and the DisplayStatus
call have been removed and replaced with the four
lines making up the KeyPressed event handler
definition.

Using the

iRev

Editor, write the original version of the

“Hello, world!” program on your system. After you
have compiled the program successfully, download it
to your

920i

. After the program has been downloaded

and the indicator is put back in run mode, then the text

Hello, world!

should appear on the display.

Advertising
This manual is related to the following products: