Page 143 - Making PIC Microcontroller Instruments and Controllers
P. 143
134 SERIAL COMlllUl{lCAtlO S: SOCKETS Ug AND UiO
When and How Will I Know
If It Is Workine?
Once set up properly, whatever is sent out by the LAB-XI wjll show up on the
Hypellermjnal screen, and whatever is typed in at the computer keyboard will show
up on the LAB-XI LCD and the H)?erTerminal screen-
We will be using the hardware serial oulput command HSEROUT, which applies to
the firsl COM poft on the LAB Xl. (The LAB-XI has only one porl, so HERSOUT2
is not applicable for use with this MCU. The mosr obvious use is for data coliection and
conversion with useful filtering where the data comes in on one porl for from an instru-
meotl, is translated and filtered, and then goes o t on the other pol1.)
Let's write a simple program (see Program 8.2), with no salety or error correc-
"A"s
tion interlocks, to send a senes of?5 uppercase to the computer one "A" at a
time with no delay between transmissions. Seventy-llve characters will fit on one
line with the cafiage return. This will keep the LAB-XI busy for aboua 0 25 sec
onds every time you press the reset pushbutton while adjusting the terminal settings,
ifnecessary,
!lqf&di!!liFia:: Rs232 communications (Program to send informalion to lhe
CI.EAR
DEFINE OSC 4 Define the oscillator speed
DEFINE IISER RKSTA 9Ob lsettinq up che conrnunicaLions
DEFINE HSER 'XSTA 2 OTI lvariables and baud tale
DEFINE HSER BAUD 24OO lsee PBP nanual for details
DEFINE HSER SPBRG 25 l
^
IISEROUT TSD. $A, $A1 a . q r ! . d q e t o i . - t e e o s
A'JPIIA VAR B{TE set counter variable
FOR AI,PEA =1 IO ?5 _ 5
r
IISEROUT [$A/] o o p o s e r d o l r h - A r \ a q e s
NEKT AjJPHA
END
protocol, we will match the settings of the HyperTerminal.
For the communications
As indicated in the compiler manual, this is done with lhe arguments in the HSEROUT
command and by the protocol related DEFINES in the pro$am. This is what is imple-
mented iII Program 8.2. Before you go any futher, the preceding program must be
made operational.
Next, we need to receive information from the computer and display it on the two
lines of the LCD. We will set it up so the LCD will be clearcd after every 20 characters
recei\ed. so $e don l nrn our ol ,pr,je on line l of lhe displa). The oPetut command
to rcceive data is:
HSERIN {ParitylEbel. } {f iredt. tabel,}Irt4(,...}I