Page 55 - Making PIC Microcontroller Instruments and Controllers
P. 55
COMPILENS.
44 IHE SOFTWAEE.IHE AND THE EDITOB
tii.!!!.iia!ii.,:a!ii The first program (Blinking alleighi LEDS on PORTD one ai a llme)
TRISD =%00000000 set PORTD Lo all outputs
UAINI"OOP: toop is eaecuLed forever
initiaLize the counter to I
FOR LED,ID = I TO a do it for Lhe I LEDS
puLs nunber ln PoRTD
PAUSE 100 pause so you can see the displav
l = I * 2 nultiptying by 2 noves Llr LED Left I pos
NEXI I,ED_ID go up and increnent counter
coEo lrArr{LooP do it alr forever
END always end tith FND statement
PICBASIC PBO TIPS AND CAUTIONS
l. To get contexlsensitive help, move the cuisor over a PICBASIC command, click to
Fl.
set the culsor, .md Press
2, Programs assume the PIC is running at 4 MH4 To change the default setting (for
l3xample, to 20 MHz), simply add DEFINE OSC 20 at the top of your program and
se! the oscillatorjumpe$ on the LAB X I accordingly lt is good praclice to always
specily the oscillator speeal in a program. Beginne$ should start with 4 MHz designs
Th" LAB-XI i. ."t up to run at 4 MHz as received from the factory' See the manual'
The defined OSC speed has to match the hardware orystal for ihe hardware and sofl
u r-re lo \^ork coneLtl\. This i. e\peciall) imporlanl lor rrme-'en5ili\e rn'lruclion'
3. Before you can use the LcDisptay on the LAB-XI' ADCON1 must be set (to
7o000001 11 to nake PORTE tand PORTAI digital) and you must pause about 500 msec
10 allow the LCD to siafl up before issuing it its nrst command You may not rced a
rnsfuc
pause, orasho er pause may be specilied, if there are many time_consuming
tioft before the lirst LCDOUT inslruction is executed (Other values ofADCONI can
also be used, depending on how you want the A and E porls coniigured See ihe dis-
cussion in Chapter I8.)
4, I have useal binary notation (7,01010101) throughout this book to sct relevant bytes
and registers so you can teadily see which bit is being set to what. The compiler
accepts hexadecimal and decimal notalion just as willjngly Binaty nolation does not
permit a space after the 7o sign, and all eigbt bits mustbe specilied.
5. When using Wod ior prografiming support, if a single quotation mark (') is copied
f.om a Word fi le and pasted into the Microcode Sludio editot it will be i nterpreted as
a (') and wil thel€fore ,1rr pnperlr stut1 the commen secrio, of the line All these have
to be changed in the ealitor after pasting. Pasling from the editors il1lo Word does not
exhibit fie same effect. lf you use (:) for ihe conments' this problem does not occur
6. All the named registers can be called by name when using the compiler' The rcgis-
ler names are the same as those used (defined) by the manufacturer in the datasheet
and are the same across the entire family of PIC microcontrollers if they provide thc
same function. Uppercase ol lowercase names can bc used Thc DEFINES m st be