Page 140 - Making PIC Microcontroller Instruments and Controllers
P. 140
SERIAL COMTilUNICATIONS:
U9
SOGKETS AND UlO
If all you need is a quick serial communications implementation for your project,
Program 8. 1 (from the microEngineering Labs Web site) gives all the code you need to
reaal and write to the USART. Combine the single character code in a loop to read and
wdte more than one character (in other words, create strings).
wilh a computer)
W RS232 Communications (Program to communicate
; rhis microBnsineeriner Labs proqran can be found on theif, web
; site. use the fales! version.
CLE,AR , read and wrile hardware usart
DEFINE OSC 4 i osc speed
81 vaR BYIE ; initialize usart
BRIsc = b10111111 ; sec Tx (PoRTc.6) to ou!, re6! in
sPaRG = 25 , set baud rale to 2400 _"i
RcsIA = g1OO1OOO0 eaable serr€l po - and cor LinLous e
i
Txstr = %OO1OOOO0 ; enable transnit and asvnchxonous mode
; echo received characlers in innnite loop
LOOP !
SOSI'B CEARIN ; ge! a characler fxon serial input, if anv
IF 81 : O TEEI I'OP; no character yet
GOSDB CEAROIIT send characrer lo serial ouLput
GO:rO LOOP
r
CIIARIN: s l r o o g o L l r o l u s a r . r e ^ , / e !
preseL to no character received
l F P I R 1 . 5 = 1 E E E N , lf receive flas then...
81 = RCREG i set received char:acler co b1
ENDIF i
(ContinwA
t 3 l