0% found this document useful (0 votes)
73 views

Pic Basic Compiler Reference Manual

The document provides information about the BASIC compiler for the PICSimulatorIDE. It describes variable types, mathematical and logical operations, standard BASIC language elements, subroutines, microcontroller related functions, and more. Special features like initializing variables on declaration and not compiling unused code are also covered. The compiler outputs assembler source code that can be assembled and loaded into the simulator with a single click.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views

Pic Basic Compiler Reference Manual

The document provides information about the BASIC compiler for the PICSimulatorIDE. It describes variable types, mathematical and logical operations, standard BASIC language elements, subroutines, microcontroller related functions, and more. Special features like initializing variables on declaration and not compiling unused code are also covered. The compiler outputs assembler source code that can be assembled and loaded into the simulator with a single click.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

PICSimulatorIDE

BASICCompilerReferenceManual
TableOfContents:
Generalinfo
Sho!arnin"s#Do$otCompile%nuse&Co&e#Initiali'e(ariablesOnDeclaration#
About)ariables
Dim#As#Bit#B*te#!or&#+on"#Reser)e#,-B#,+B#,-!#,+!#S*mbol#True#.alse#Const#Pointer#
ASM#!REG#
Mathematicalan&lo"icaloperations
Mo&#S/r#$ot#An&#Or#0or#$an&#$or#$1or#-i"h#+o#To""le#
Stan&ar&Basiclan"ua"eelements
Goto#.or#To#Step#$e1t#!hile#!en&#If#Then#Else#En&if#SelectCase#Case#En&Select#-alt#
Subroutines
En&#Gosub#Return#
Microcontrollerrelate&lan"ua"eelements
Confi"#Input#Output#AllDi"ital#Define#CO$.2!ORD#CO$.2!ORD23#C+OC42.RE5%E$C6#
EEPROM#
SpecialBasiclan"ua"eelements
!aitMs#!ait%s#SIM%+ATIO$2!AITMS2(A+%E#Brea7#Shift+eft#ShiftRi"ht#+oo7%p#Count#
CO%$T2MODE#.re/Out#
Structure&lan"ua"esupport8proce&uresan&functions9
Proc#En&Proc#Call#E1it#.unction#En&.unction#Inclu&e#
%sin"internalEEPROMmemor*
Rea&#!rite#
%sin"internalA:Dcon)ertermo&ule
A&cin#ADC2C+OC4#ADC2SAMP+E%S#
%sin"interrupts
Enable#Disable#OnInterrupt#Resume#Sa)eS*stem#
Serialcommunicationusin"internalhar&are%ART
-seropen#-serout#-serin#-ser"et#Cr+f#+f#A++O!2M%+TIP+E2-SEROPE$#
A++O!2A++2BA%DRATES#
Softare%ARTimplementation
SERO%T2DE+A6%S#Serout#Serin#SeroutIn)#SerinIn)#
Interfacin"character+CDs
+CD2BITS#+CD2DREG#+CD2DBIT#+CD2RSREG#+CD2RSBIT#+CD2EREG#+CD2EBIT#
+CD2R!REG#+CD2R!BIT#+CD2COMMA$D%S#+CD2DATA%S#+CD2I$ITMS#
+CD2READ2B%S62.+AG#+c&init#+c&out#+c&cm&out#+c&Clear#+c&-ome8+c&+ine;-ome9#
+c&+ine3-ome#+c&Displa*On#+c&Displa*Off#+c&CurOff#+c&CurBlin7#+c&Cur%n&erline#
+c&CurBlin7%n&erline#+c&+eft#+c&Ri"ht#+c&Shift+eft#+c&ShiftRi"ht#+c&+ine;Clear#
+c&+ine3Clear#+c&+ine;Pos#+c&+ine3Pos#+c&&efchar#+c&+ine<-ome#+c&+ine=-ome#
+c&+ine<Clear#+c&+ine=Clear#+c&+ine<Pos#+c&+ine=Pos#+CD2+I$ES#+CD2C-ARS#
1
I3Ccommunicationithe1ternalI3C&e)ices
I3C!rite#I3CRea&#I3C!rite;#I3CRea&;#I3CREAD2DE+A6%S#I3CC+OC42STRETC-#
I3CPrepare#I3CStart#I3CStop#I3CSen&#I3CRecA8I3CRecei)eAc79#I3CRec$8I3CRecei)e$Ac79#
SupportforSerialPeripheralInterface8SPI9communication
SPI2SC42REG#SPI2SC42BIT#SPI2SDI2REG#SPI2SDI2BIT#SPI2SDO2REG#SPI2SDO2BIT#
SPI2CS2REG#SPI2CS2BIT#SPIC+OC42I$(ERT#SPICS2I$(ERT#SPIC+OC42STRETC-#
SPIPrepare#SPICSOn#SPICSOff#SPISen&#SPIRecei)e#SPISen&Bits#
Interfacin""raphical+CDsith;3>1?=&otmatri1
G+CD2DREG#G+CD2RSREG#G+CD2RSBIT#G+CD2EREG#G+CD2EBIT#G+CD2R!REG#
G+CD2R!BIT#G+CD2CS;REG#G+CD2CS;BIT#G+CD2CS3REG#G+CD2CS3BIT#G+c&init#
G+c&clear#G+c&pset#G+c&preset#G+c&clean#G+c&position#G+c&rite#G+c&out#G+c&in#
G+c&cm&out#
%sin"internalP!Mmo&ules
P!Mon#P!Moff#P!M&ut*#
Interfacin"Ra&ioControl8R:C9ser)os
Ser)oIn#Ser)oOut#
Interfacin"StepperMotors
STEP2A2REG#STEP2A2BIT#STEP2B2REG#STEP2B2BIT#STEP2C2REG#STEP2C2BIT#
STEP2D2REG#STEP2D2BIT#STEP2MODE#Step-ol&#StepC!#StepCC!#
Interfacin";@!IRE&e)ices
;!IRE2REG#;!IRE2BIT#;ireInit#;ireSen&Bit#;ireGetBit#;ireSen&B*te#;ireGetB*te#
DS;>S3AStart#DS;>S3ARea&T#
A&)ance&features
Start.romBero#
CGeneralinfo
Basiccompilere&itoriscompose&ofe&itorpanel8foruserpro"rame&itin"9an&sourcee1plorer8for
eas*na)i"ationthrou"hallelementsofuserpro"ram@)ariables#s*mbols#constants#subroutines#
proce&uresan&functions9,E&itorformatsan&colori'esentere&linesofuserpro"ram#that
simplifiesthe&ebu""in"process,
Theprimar*outputofthecompilerisanassemblersourcefile,-oe)er#ithanappropriate
comman&fromthemenuitcanbeassemble&an&e)enloa&e&inthesimulatorithasin"leclic7,
Menucomman&san&optionsarerich#asellasthecomman&sfromtheri"ht@clic7popupmenus
forthee&itoran&sourcee1plorer,BasiccompilerDsassembleroutputcontainsman*useful
commentlines#thatma7esit)er*helpfulfore&ucationalpurposes#also,
Sho!arnin"s
IfSho!arnin"soptionisenable&#inthe!arnin"sin&oBasiccompilerillshoinformation
aboutunuse&&eclarations#subroutines#proce&uresan&functionsintheuserbasicpro"ram,
Do$otCompile%nuse&Co&e
Ifthisoptionisenable&#Basiccompilerillnotcompileunuse&&eclarations#subroutines#
proce&uresan&functions#inor&ertosa)ememor*resources,
Initiali'e(ariablesOnDeclaration
Ifthisoptionisenable&#Basiccompilerillresetto'eroallmemor*locationsallocate&for
)ariables#atthepositionoftheir&eclarationinthebasicpro"ram,Thisoptionisusefulfor
be"inners#becauseRAMmemor*isfille&ithran&om)aluesat&e)icepoer@up#an&itiseas*to
ma7eamista7etoassumethatall)ariablesareresetto'eroatpoer@up,E1perience&userscan
sa)esomepro"rammemor*#b*&isablin"thisoptionan&ta7in"controlof)ariableinitial)aluesb*
userpro"ramherenecessar*,
2
CAbout)ariables
.our&atat*pesaresupporte&:
Bit@;@bit#Aor;
B*te@;@b*teinte"ersintheran"eAto3EE
!or&@3@b*teinte"ersintheran"eAto?E#E<E
+on"@=@b*teinte"ersintheran"eAto=#3F=#F?G#3FE
(ariablescanbe"lobal8&eclare&inthemainpro"ram#beforetheEn&statement9orlocal8&eclare&
insubroutines#proce&uresan&functions9,(ariablenameuse&fora)ariableith"lobalscopecan
beuse&a"ainforlocal)ariablenames,Thecompilerillreser)eseparatememor*locationsfor
them,Thetotalnumberof)ariablesislimite&b*thea)ailablemicrocontrollerRAMmemor*,
(ariablesare&eclare&usin"DIMstatement:
Dim i As Bit
Dim j As Byte
Dim k As Word
Dim x As Long
Ifnecessar*#)ariablea&&resscanbespecifie&&urin"&eclaration:
Dim x As Byte @ 0x050
Itispossibletouseone@&imensionalarra*sforB*tean&!or&)ariables,.ore1ample:
Dim x(10) As Byte
&eclaresanarra*of;AB*te)ariablesitharra*in&e1intheran"eHA@FI,
+on"&atat*pe8<3@bitmathsupport9isanoptionala&&@onmo&ulefortheinte"rate&basiccompiler,
RESER(Estatementallosa&)ance&usa"eb*reser)in"someoftheRAMlocationstobeuse&b*
in@co&eassemblerroutinesorb*MP+ABIn@CircuitDebu""er,.ore1ample:
Reserve 0x70
-i"han&lob*teofaor&)ariablecanbea&&resse&b*,-Ban&,+Be1tensions,In&i)i&ualbits
canbea&&resse&b*,A#,;#,,,#,;=an&,;Ee1tensions,Itispossibletoma7econ)ersionsbeteen
B*tean&!or&&atat*pesusin",+Ban&,-Be1tensionsor&irectl*:
Dim x As Byte
Dim y As Word
x = y.B
x = y.LB !"#is st$tement is e%&iv$'ent to x = y
y.B = x
y.LB = x
y = x !"#is st$tement (i'' $'so )'e$r t#e #ig# *yte o+ y v$ri$*'e
-i"hor&8compose&b*b*tes<an&39an&loor&8compose&b*b*tes;an&A9ofalon"
)ariablecanbea&&resse&b*,-!an&,+!e1tensions,B*teAcanbea&&resse&b*,+Ban&b*te;
b*,-Be1tensions,.ore1ample:
Dim i As Byte
Dim j As Word
Dim x As Long
i = x.LB
j = x.W
Allspecialfunctionre"isters8S.Rs9area)ailableasB*te)ariablesinbasicpro"rams,In&i)i&ual
bitsofaB*te)ariablecanbea&&resse&b*,A#,;#,3#,<#,=#,E#,?an&,Ge1tensionsorusin"official
namesofthebits:
Dim x As Bit
Dim y As Byte
x = y.7
y., = 1
"R-.A.1 = 0
"R-.B = 0
3
/0R"A.1 = 1
/0R"B = 155
."A"2..R/0 = 1
-3"403.-3"5 = 0
Stan&ar&shortformsforaccessin"portre"istersan&in&i)i&ualchippinsarealsoa)ailable8RA#
RB#RC#RD#REcanbeuse&asB*te)ariablesJRAA#RA;#RA3#,,,#RE?#REGarea)ailableasBit
)ariables9:
RA = 0x++
RB0 = 1
Itispossibletouses*mbolicnames8s*mbols9inpro"rams#toeasil*a&&resss*stem)ariables,
S*mbolscanbe"lobalorlocal,S6MBO+&irecti)eisuse&to&eclares*mbolicnames:
.ym*o' 'ed1 = /0R"B.0
'ed1 = 1
.ym*o' $d6$)tion = AD4030.706D038
Constantscanbeuse&in&ecimalnumbers*stemithnospecialmar7s#inhe1a&ecimalnumber
s*stemithlea&in"A1notation8orith-attheen&9an&inbinar*s*stemithlea&in"Kmar78or
ithBattheen&9,4e*or&sTruean&.alsearealsoa)ailableforBitt*peconstants,.ore1ample:
Dim x As Bit
Dim y As Byte
x = "r&e
y = 0x55
y = 901010101
Constantscanbeassi"ne&tos*mbolicnamesusin"CO$ST&irecti)e,Constantscanbe"lobalor
local,Onee1ample:
Dim x As Word
4onst :i = ;1<
x = :i
An*)ariablethatis&eclare&asaB*teor!or&)ariableusin"Dimstatementcanbeuse&asa
pointertouserRAMmemor*henitisuse&asanar"umentofPOI$TERfunction,The)alue
containe&inthe)ariablethatisuse&asapointershoul&beintheran"eA@E;;,-ereisone
e1ample:
Dim x As Word
Dim y As Byte
x = 0x;+
y = /ointer(x)
y = y = 0x55
x = x > 1
/ointer(x) = y
y = 0x$$
x = x > 1
/ointer(x) = y
Itispossibletousecommentsinbasicsourcepro"rams,Thecommentsmustbe"inithsin"le
/uotes*mbol8D9an&ma*beplace&an*hereinthepro"ram,
+inesofassemblersourceco&ema*beplace&an*hereinbasicsourcepro"raman&mustbe"in
ithASM:prefi1,.ore1ample:
A.?@ 30/
A.?@LAB8L1@ ?0ALW 0x55
S*mbolicnamesof&eclare&)ariablescanbeuse&inassemblerroutinesbecauseproper)ariable
a&&ressillbeassi"ne&tothosenamesb*E5%&irecti)e:
Dim v$rn$me As Byte
v$rn$me = 0
A.?@ ?0ALW 0x55
A.?@ ?0AW5 AAR3A?8
4
!henor7in"ithinlineassemblerco&e#itcoul&beusefultouseor7in"re"isterasasourceor
&estinationinassi"nstatements,.orthatpurpose!REG7e*or&shoul&beuse&an&thecompiler
illta7ecareoftheban7control:
Dim v$rn$me As Byte
A.?@ ?0ALW 0x55
v$rn$me = WR87
CMathematicalan&lo"icaloperations
.i)earithmeticoperations8L#@#M#:#MOD9area)ailableforB*te#!or&an&+on"&atat*pes,The
compilerisabletocompileallpossiblecomple1arithmetice1pressions,.ore1ample:
Dim i As Word
Dim j As Word
Dim x As Word
i = 11;
j = i B 1;<
x = 1
x = (j B x > 11;<5) C (i = x)
S/uarerootofanumber8A@?EE<Eran"e9canbecalculate&usin"S5Rfunction:
Dim x As Word
x = ;,00
x = .%r(x)
.orBit&atat*pe)ariablesse)enlo"icaloperationsarea)ailable,Itispossibletoma7eonl*one
lo"icaloperationinonesin"lestatement,+o"icaloperationsarealsoa)ailableforB*tean&!or&
)ariables,.ore1ample:
E1ample;:
Dim i As Bit
Dim j As Bit
Dim x As Bit
x = 3ot i
x = i And j
x = i 0r j
x = i Dor j
x = i 3$nd j
x = i 3or j
x = i 3xor j
E1ample3:
Dim x As Word
Dim y As Word
x = x 0r y
/0R"B = /0R"4 And 911110000
Therearethreestatementsthatareuse&forbitmanipulation@-IG-#+O!an&TOGG+E,Ifthe
ar"umentofthesestatementsisabitinoneofthePORTre"isters#thenthesamebitinthe
correspon&in"TRISre"isterisautomaticall*cleare&#settin"theaffecte&pinasanoutputpin,Some
e1amples:
ig# /0R"B.0
Lo( AD4030.AD03
"ogg'e 0/"-036R87.-3"8D7
CStan&ar&Basiclan"ua"eelements
%ncon&itionalNumpsareperforme&b*GOTOstatement,Ituseslinelabelnameasar"ument,+ine
labelscanbe"lobalorlocal,+inelabelsmustbefolloe&b*colonmar7D:D,-ereisonee1ample:
Dim x As Word
x = 0
'oo:@ x = x = 1
5
7oto 'oo:
.ourstan&ar&BASICstructuresaresupporte&:.OR@TO@STEP@$E0T#!-I+E@!E$D#I.@T-E$@
E+SE@E$DI.an&SE+ECTCASE@CASE@E$DSE+ECT,-erearese)erale1amples:
E1ample;:
Dim x As Byte
"R-.B = 0
x = 155
W#i'e x E 0
/0R"B = x
x = x > 1
W$it?s 100
Wend
/0R"B = x
E1ample3:
"R-.B = 0
'oo:@
-+ /0R"A.0 "#en
/0R"B.0 = 1
8'se
/0R"B.0 = 0
8ndi+
7oto 'oo:
E1ample<:
Dim x As Word
"R-.B = 0
5or x = 0 "o 10000 .te: 10
/0R"B = x.LB
3ext x
E1ample=:
Dim i As Byte
Dim j As Byte
Dim x As Byte
j = 155
x = 1
"R-.B = 0
5or i = j "o 0 .te: >x
/0R"B = i
3ext i
E1ampleE:
Dim x As Byte
'oo:@
.e'e)t 4$se x
4$se 155
x = 1
4$se F= 117
x = x = 1
4$se 8'se
x = 155
8nd.e'e)t
7oto 'oo:
AfterI.@T-E$statementinthesamelinecanbeplace&almoste)er*otherpossiblestatementan&
thenE$DI.isnotuse&,Therearenolimitsforthenumberofneste&statementsofan*7in&,Inthe
teste1pressionsofI.@T-E$an&!-I+EstatementsitispossibletousemultipleORe&an&multiple
A$De&con&itions,Multiplecommaseparate&con&itionscanbeuse&ithCASEstatements#also,
6
Ifthereisanee&toinsertaninfiniteloopinbasicpro"ram#thatcanbe&oneith-A+Tstatement,
CSubroutines
Structure&pro"ramscanberittenusin"subroutinecallsithGOS%Bstatementthatusesline
labelnameasar"ument,Returnfromasubroutineisperforme&b*RET%R$statement,%sernee&
tota7ecarethatthepro"ramstructureisconsistent,!henusin"subroutines#mainroutinenee&to
been&e&ithE$Dstatement,E$Dstatementiscompile&asaninfiniteloop,-ereisane1ample:
.ym*o' $d6$)tion = AD4030.706D038
.ym*o' dis:'$y = /0R"B
"R-.B = 900000000
"R-.A = 9111111
AD4030 = 0x)0
AD4031 = 0
ig# AD4030.AD03
m$in@
7os&* get$dres&'t
dis:'$y = ADR8.
7oto m$in
8nd
get$dres&'t@
ig# $d6$)tion
W#i'e $d6$)tion
Wend
Ret&rn
CMicrocontrollerrelate&lan"ua"eelements
Microcontrollerportsan&pinscanbeconfi"ure&asinputsoroutputsb*assi"nin"proper)aluesto
TRIS1re"istersortheirbits,Thattas7canalsobeaccomplishe&b*aCO$.IGstatement,Itss*nta1
isapparentfromthefolloin"e1amples:
4on+ig /0R"B = 0&t:&t
4on+ig RA0 = 0&t:&t
4on+ig /0R"4.; = -n:&t
4on+ig RD = -n:&t
AllPICmicrocontrollersthatfeatureanalo"capabilities8A:Dcon)ertersan&:oranalo"comparators9
aresetupatpoer@uptousethein)ol)e&pinsfortheseanalo"purposes,Inor&ertousethosepins
as&i"italinput:outputs#the*shoul&besetupfor&i"italuseb*chan"in"the)aluesinsomeofthe
specialfunctionsre"istersasspecifie&b*the&atasheets,Tosetupallpinsfor&i"italpurposes#
A++DIGITA+statementcanbeuse&atthebe"innin"ofthebasicpro"ram,
Therearetoconfi"urationparametersCO$.2!ORDan&CO$.2!ORD238nota)ailableforall
&e)ices9thatcanbesetusin"DE.I$E&irecti)etoo)erri&ethe&efault)alues,Thecloc7fre/uenc*
ofthetar"et&e)icecanbespecifie&b*settin"theC+OC42.RE5%E$C6parameter8the)alueis
e1presse&inM-'9,Theseparametersshoul&besetupatthebe"innin"ofthebasicpro"ram,.or
e1ample:
De+ine 40356W0RD = 0x;+71
De+ine 4L04G65R8H2834I = 10
EEPROMmemor*contentcanbe&efine&inbasicpro"ramsusin"EEPROMstatement,Itsfirst
ar"umentisthea&&ressofthefirstb*teinthe&atalist,MultipleEEPROMstatementscanbeuse&
tofillin&ifferentareasofEEPROMmemor*#ifnee&e&,.ore1ample:
88/R0? 0J 0x55
88/R0? 15;J 0x01J 0x01J 0x0;
CSpecialBasiclan"ua"eelements
!AITMSan&!AIT%Sstatementscanbeuse&toforcepro"ramtoaitforthespecifie&numberof
millisecon&sormicrosecon&s,Itisalsopossibletouse)ariablear"umentofB*teor!or&&ata
7
t*pe,TheseroutinesuseCloc7.re/uenc*parameterthatcanbechan"e&fromtheOptionsmenu,
!AIT%Sroutinehasminimal&ela*an&stepthatalso&epen&ontheCloc7.re/uenc*parameter,
Dim x As Word
x = 100
W$it?s x
W$it2s 50
Important$ote:!henritin"pro"ramsforrealPIC&e)ices*ouillmostli7el*use&ela*inter)als
thatarecomparableto;secon&or;AAAmillisecon&s,Man*e1amplesinthishelpfilealsousesuch
Dreal@timeDinter)als,But#if*ouanttosimulatethosepro"rams*ouha)etobe)er*patienttosee
somethin"tohappen#e)enon)er*poerfulPCsa)ailableto&a*,.orsimulationofD!aitMs;AAAD
statementon=M-'*ouha)etoaitthesimulatortosimulate;AAAAAAinstructionsan&itillta7e
consi&erableamountoftimee)enifDe1tremel*fastDsimulationrateisselecte&,So#Nustforthe
purposeofsimulation*oushoul&recompile*ourpro"ramsitha&Nuste&&ela*inter)als#thatshoul&
note1cee&;@;Ams,But#besuretorecompile*ourpro"ramithori"inal&ela*sbefore*ou
&onloa&ittoareal&e)ice,Thereisaneas*a*tochan"ear"umentsofall!AITMSstatements
inalar"ebasicpro"ramitha)alueintheran"e;@;Aforsimulationpurposes,!ithonelineof
co&esettin"parameterSIM%+ATIO$2!AITMS2(A+%EithDE.I$E&irecti)e#thear"umentsofall
!AITMSstatementsinthepro"ramillbei"nore&an&thespecifie&)alueillbeuse&instea&
&urin"compilin",Settin"the)alueA8&efault9forthisparameter8oromittin"theholeline9ill
cancelitseffectan&thecompile&co&eillberea&*a"ainfortherealhar&are,
Itispossibletoinsertbrea7pointsforthesimulator&irectl*inbasicpro"ramsusin"BREA4
statement,Itiscompile&asreser)e&opco&eA1AAA;an&thesimulatorillinterpretthisopco&eas
abrea7pointan&sitchthesimulationratetoStepB*Step,
S-I.T+E.Tan&S-I.TRIG-Tfunctionscanbeuse&toshiftbit@le)elrepresentationofa)ariable
leftan&ri"ht,Thefirstar"umentisinput)ariablean&thesecon&ar"umentisnumberofshiftstobe
performe&,-erearetoe1amples:
E1ample;:
"R-.B = 0x00
/0R"B = 900000011
go'e+t@
W$it?s 150
/0R"B = .#i+tLe+t(/0R"BJ 1)
-+ /0R"B = 911000000 "#en 7oto gorig#t
7oto go'e+t
gorig#t@
W$it?s 150
/0R"B = .#i+tRig#t(/0R"BJ 1)
-+ /0R"B = 900000011 "#en 7oto go'e+t
7oto gorig#t
E1ample3:
"R-.B = 0x00
/0R"B = 900000001
go'e+t@
W$it?s 150
/0R"B = .#i+tLe+t(/0R"BJ 1)
-+ /0R"B.7 "#en 7oto gorig#t
7oto go'e+t
gorig#t@
W$it?s 150
/0R"B = .#i+tRig#t(/0R"BJ 1)
-+ /0R"B.0 "#en 7oto go'e+t
7oto gorig#t
8
+OO4%Pfunctioncanbeuse&toselectonefromthelistofB*teconstants#base&onthe)aluein
thein&e1B*te)ariable#thatissupplie&asthelastseparate&ar"umentofthefunction,Thefirst
constantinthelisthasin&e1)alueA,Theselecte&constantillbeloa&e&intotheresultB*te&ata
t*pe)ariable,Ifthe)alueinthein&e1)ariable"oesbe*on&thenumberofconstantsinthelist#the
result)ariableillnotbeaffecte&b*thefunction,-ereisonesmalle1ampleforaG@se"ment+ED
&ispla*:
Dim digit As Byte
Dim m$sk As Byte
"R-.B = 900000000
'oo:@
5or digit = 0 "o K
m$sk = Look2:(0x;+J 0x0,J 0x5*J 0x<+J 0x,,J 0x,dJ 0x7dJ 0x07J 0x7+J
0x,+)J digit
/0R"B = m$sk
W$it?s 1000
3ext digit
7oto 'oo:
Ifallconstantsinthelist8orpartofthem9areASCII)alues#thenshorterformofthelistcanbe
create&b*usin"strin"ar"uments,.ore1ample:
m$sk = Look2:(LAB4D857-MGL)J index
Ifitisnecessar*tocountthenumberofpulsesthatcometooneofthemicrcontrollerDspins&urin"a
certainperio&oftime#thereisCO%$Tstatementa)ailableforthatpurpose,Ithasthreear"uments,
Thefirstoneisthepinthatisconnecte&tothesourceofpulses,Itshoul&pre)iousl*besetupas
&i"italinputpin,Thesecon&ar"ument&efinesthe&urationoftheobser)atione1presse&in
millisecon&san&itmustbeanumericconstantintheran"e;@;AAAA,Thelastar"umentofthis
statementisaB*teor!or&)ariableherethecounte&numberofpulsesillbestore&afterits
e1ecution,CO%$TstatementusesinternalTimerAperipheralmo&ule,ThereisCO%$T2MODE
parametera)ailablethatcanbesetupithDE.I$E&irecti)e,Ifitissetto)alue;8&efault)alue9
CO%$Tstatementillcountthenumberofrisin"pulsee&"es,IfCO%$T2MODEO3#thenumberof
fallin"e&"esillbecounte&,
De+ine 4023"6?0D8 = 1
Dim n&m6o+6:&'ses As Word
4o&nt /0R"B.0J 1000J n&m6o+6:&'ses
.RE5O%Tstatementcanbeuse&to"enerateatrainofpulses8soun&tone9onthespecifie&pin
ithconstantfre/uenc*an&specifie&&uration,Ithasthreear"uments,Thefirstar"umentisthepin
thatthetoneillbe"enerate&on,Itshoul&pre)iousl*besetupas&i"italoutputpin,Thesecon&
ar"umentspecif*thetonefre/uenc*an&itmustbeaconstantintheran"e;@;AAAA-',Thethir&
ar"ument&efinesthetone&urationan&italsomustbeanumericconstantintheran"e;@;AAAAms,
Choosin"hi"hertonefre/uenciesithlomicrocontrollercloc7fre/uenc*use&ma*resultin
somehatinaccuratefre/uenc*ofthe"enerate&tones,.RE5O%Tstatementcanbealternati)el*
use&inD)ariablemo&eDith!or&&atat*pe)ariablesinstea&ofconstantsforthelastto
ar"uments,Inthismo&eofusa"ethesecon&ar"umentissuppose&tohol&thehalf@perio&ofthe
tone8inmicrosecon&s9an&thethir&ar"umentmusthol&thetotalnumberofpulsesthatillbe
"enerate&,Thefolloin"co&eill"enerateonesecon&lon"toneonRBApinith?AA-'
fre/uenc*:
"R-.B.0 = 0
5re%0&t /0R"B.0J ,00J 1000
CStructure&lan"ua"esupport8proce&uresan&functions9
Proce&urescanbe&eclare&ithPROCstatement,The*cancontainuptoEar"uments8comma
separate&list9an&alla)ailable&atat*pescanbeuse&forar"ument)ariables,Ar"ument)ariables
are&eclare&locall*#sothe*&onotnee&toha)euni/uenamesinrelationtotherestofuserbasic
pro"ram#thatma7es)er*eas*tore@useoncerittenproce&uresinotherbasicpro"rams,The
proce&urescanbee1ite&ithE0ITstatement,The*mustbeen&e&ithE$DPROCstatementan&
mustbeplace&aftertheE$Dstatementinpro"ram,Callstoproce&uresareimplemente&ith
CA++statement,Thelistofpasse&ar"umentscancontainboth)ariablesan&numericconstants,
.ore1ample:
9
Dim x As Byte
"R-.B = 0
5or x = 0 "o 155
4$'' :ort*6dis:'$y(x)
W$it?s 100
3ext x
8nd
/ro) :ort*6dis:'$y($rg1 As Byte)
/0R"B = $rg1
8nd /ro)
Allfactsstate&forproce&uresare)ali&forfunctions#also,.unctionscanbe&eclare&ith
.%$CTIO$statement,The*cancontainuptoEar"umentsan&ar"ument)ariablesare&eclare&
locall*,.unctionscanbee1ite&ithE0ITstatementan&mustbeen&e&ithE$D.%$CTIO$,The
nameofthefunctionis&eclare&asa"lobal)ariable#soifthefunctioniscalle&ithCA++
statement#afteritse1ecutionthefunction)ariableillcontaintheresult,Stan&ar&a*offunction
callsinassi"nmentstatementscanbeuse&#also,Onesimplee1ample:
Dim x As Byte
Dim y As Word
5or x = 0 "o 155
y = s%&$re(x)
3ext x
8nd
5&n)tion s%&$re($rg1 As Word) As Word
s%&$re = $rg1 B $rg1
8nd 5&n)tion
Basicsourceco&efromane1ternalfilecanbeinclu&e&tothecurrentpro"ramb*usin"I$C+%DE
&irecti)e,Itsonl*ar"umentisastrin"containin"thepathtothee1ternal,BASfile,Thiscanbethe
fullpathoronl*thefilename#ifthee1ternalfileislocate&inthesamefol&erasthecurrentbasic
pro"ramfile,Durin"thecompilationprocessthee1ternalbasicsourceillbeappen&e&tothe
currentpro"ram,Multiplefilescanbeinclu&e&ithseparateI$C+%DE&irecti)es,Tomaintainthe
o)erallbasicco&estructure#itisstron"l*su""este&thatthee1ternalfilecontains"lobal
&eclarations#subroutines#proce&uresan&functions#onl*,-ereisone)er*simplee1ampleforthe
&emonstration:
main,bas:
Dim i As Word
Dim j As Word
-n)'&de Lin)1.*$sL
-n)'&de Lin)1.*$sL
5or i = 1 "o 10
j = +&n)1(iJ 100)
4$'' :ro)1(j)
3ext i
8nd
inc;,bas:
Dim tot$' As Word
/ro) :ro)1(i As Word)
tot$' = tot$' = i
8nd /ro)
inc3,bas:
5&n)tion +&n)1(i As WordJ j As Word) As Word
+&n)1 = i = j
8nd 5&n)tion
10
Structure&lan"ua"esupportisanoptionala&&@onmo&ulefortheinte"rate&basiccompiler,
C%sin"internalEEPROMmemor*
AccesstoEEPROM&atamemor*canbepro"ramme&usin"READan&!RITEstatements,The
firstar"umentisthea&&ressofab*teinEEPROMmemor*an&canbeaconstantorB*te)ariable,
Thesecon&ar"umentis&atathatisrea&orritten8forREADstatementitmustbeaB*te)ariable9,
Itissu""este&to7eepinterrupts&isable&&urin"thee1ecutionof!RITEstatement,
Dim x As Byte
Dim y As Byte
x = 10
Re$d xJ y
Write 11J y
C%sin"internalA:Dcon)ertermo&ule
ADCI$statementisa)ailableasasupportforinternalA:Dcon)erter,Itsfirstar"umentisADC
channelnumberan&thesecon&ar"umentisa)ariablethatillbeuse&tostoretheresultofA:D
con)ersion,ADCI$statementusestoparametersADC2C+OC4an&ADC2SAMP+E%Sthatha)e
&efault)alues<an&3A,These&efault)aluescanbechan"e&usin"DE.I$E&irecti)e,
ADC2C+OC4parameter&eterminesthechoiceforADCcloc7source8alloe&ran"eisA@<orA@G
&epen&in"onthe&e)iceuse&9,ADC2SAMP+E%Sparametersetsthe&esire&ADCac/uisitiontime
inmicrosecon&s8A@3EE9,ADCI$statementpresupposesthatthecorrespon&in"pinisconfi"ure&as
ananalo"input8TRIS#ADCO$;re"isteran&onsome&e)icesA$SE+re"ister9,-ereisone
e1ample:
Dim v(5) As Byte
Dim vm As Word
Dim i As Byte
De+ine AD464L04G = ;
De+ine AD46.A?/L82. = 50
"R-.A = 0x++
"R-.B = 0
AD4031 = 0
5or i = 0 "o <
Ad)in 0J v(i)
3ext i
vm = 0
5or i = 0 "o <
vm = vm = v(i)
3ext i
vm = vm C 5
/0R"B = vm.LB
C%sin"interrupts
Interruptroutineshoul&beplace&asallothersubroutinesaftertheE$Dstatement,Itshoul&be"in
ithO$I$TERR%PTan&en&ithRES%MEstatement,Ifarithmeticoperations#arra*soran*other
comple1statementsareuse&ininterruptroutine#thenSA(ES6STEMstatementshoul&beplace&
ri"htafterO$I$TERR%PTstatementtosa)ethecontentofre"istersuse&b*s*stem,E$AB+Ean&
DISAB+Estatementscanbeuse&inmainpro"ramtocontrolGIEbitinI$TCO$re"ister,RES%ME
statementillsettheGIEbitan&enableneinterrupts,.ore1ample:
E1ample;:
Dim x As Byte
x = 155
"R-.A = 0
/0R"A = x
11
-3"403.-3"8 = 1
8n$*'e
8nd
0n -nterr&:t
x = x > 1
/0R"A = x
-3"403.-3"5 = 0
Res&me
E1ample3:
Dim t As Word
t = 0
"R-.A = 0x++
AD4031 = 0
"R-.B = 0
0/"-036R87."04. = 0
-3"403."0-8 = 1
8n$*'e
'oo:@
Ad)in 0J /0R"B
7oto 'oo:
8nd
0n -nterr&:t
.$ve .ystem
t = t = 1
-3"403."0-5 = 0
Res&me
CSerialcommunicationusin"internalhar&are%ART
Thesupportforbothhar&arean&softareserialcommunicationisalsoa)ailable,-SEROPE$#
-SERO%T#-SERI$an&-SERGETstatementscanbeuse&ithPIC&e)icesthatha)einternal
har&are%ART,-SEROPE$statementsetsupthehar&are%ART,Itsonl*ar"umentisbau&rate
an&alloe&)aluesare:<AA#?AA#;3AA#3=AA#=>AA#F?AA#;==AA#;F3AA#3>>AA#<;3EA#<>=AA#
E?AAAan&EG?AA,Ifthear"umentisomitte&%ARTillbesetupforF?AAbau&rate,Ifparameter
A++O!2M%+TIP+E2-SEROPE$issetto;usin"DE.I$E&irecti)e#itillbepossibletouse
-SEROPE$statementmorethanonceinthepro"ram#fore1ampletochan"eselecte&bau&rate,If
A++O!2A++2BA%DRATESparameterissetto;usin"DE.I$E&irecti)eallbau&ratesintheran"e
;AA@EG?AAillbealloe&,-SERO%Tstatementisuse&forserialtransmission,-SERO%T
statementma*ha)emultiplear"umentsseparate&b*D#D,6oucanusestrin"s#+.7e*or&for+ine
.ee&characterorCR+.7e*or&forCarria"eReturn@+ine.ee&se/uence#constantsan&
)ariables,IfDPDsi"nisuse&beforethenameofa)ariablethenits&ecimalrepresentationissentto
theserialport,-SERI$statementcanbeuse&toloa&alistofB*tean&!or&)ariablesiththe
)aluesrecei)e&onserialport,Thisstatementillaituntilthere/uire&numberofb*tesisrecei)e&
onserialport,-SERGETstatementha)eonear"umentthatmustbeaB*te)ariable,Ifthereisa
characteraitin"intherecei)ebufferitillbeloa&e&inthe)ariable#otheriseA)alueillbe
loa&e&,-erearesomee1amples:
E1ample;:
Dim i As Byte
sero:en ;N<00
W$it?s 1000
5or i = 10 "o 0 .te: >1
sero&t L3&m*er@ LJ OiJ 4rL+
W$it?s 500
3ext i
E1ample3:
Dim i As Byte
sero:en 1K100
12
'oo:@
serin i
sero&t L3&m*er@ LJ OiJ 4rL+
7oto 'oo:
E1ample<:
Dim i As Byte
sero:en 1K100
'oo:@
serget i
-+ i E 0 "#en
sero&t L3&m*er@ LJ OiJ 4rL+
W$it?s 50
8ndi+
7oto 'oo:
CSoftare%ARTimplementation
Onallsupporte&PIC&e)icessoftareserialcommunicationcanbeimplemente&ithSERO%T
an&SERI$statements,Thefirstar"umentofbothstatementsmustbeoneofthemicrocontrollerDs
pins#an&thesecon&ar"umentisbau&rate:<AA#?AA#;3AA#3=AA#=>AA#F?AAor;F3AA,%sin"
hi"herbau&ratesithlocloc7fre/uenc*coul&causeframin"errors,.orSERO%Tstatementthen
follosthelistofar"umentstobesenttoserialport,6oucanusestrin"s#+.7e*or&for+ine.ee&
characterorCR+.7e*or&forCarria"eReturn@+ine.ee&se/uence#constantsan&)ariables,IfDPD
si"nisuse&beforethenameofa)ariablethenits&ecimalrepresentationissenttotheserialport,
SERO%TstatementusesSERO%T2DE+A6%Sparameterthatcanbesetb*DE.I$E&irecti)ean&
has&efault)alueof;AAAmicrosecon&s,This&efinesthe&ela*inter)albeforeacharacteris
actuall*senttotheportan&itisuse&toincreasethereliabilit*ofsoftareSERO%Troutine,.or
SERI$statementthenfollosthelistofB*tean&!or&)ariablestobeloa&e&iththe)alues
recei)e&onserialport,Thisstatementillaituntilthere/uire&numberofb*tesisrecei)e&on
serialport,.orserialinterfaceithin)erte&lo"icle)elsthereareSERI$I$(an&SERO%TI$(
statementsa)ailable,Somee1amples:
E1ample;:
De+ine .8R02"6D8LAI2. = 5000
.ero&t /0R"4.,J 1100J Le''o (or'dPLJ 4rL+
E1ample3:
Dim i As Byte
'oo:@
.erin /0R"4.7J K,00J i
.ero&t /0R"4.,J K,00J L3&m*er@ LJ OiJ 4rL+
7oto 'oo:
CInterfacin"character+CDs
Basiccompileralsofeaturesthesupportfor+CDmo&ulesbase&on-D==G>Aorcompatible
controllerchip,Priortousin"+CDrelate&statements#usershoul&setup+CDinterfaceusin"
DE.I$E&irecti)es,-ereisthelistofa)ailableparameters:
+CD2BITS@&efinesthenumberof&atainterfacelines8alloe&)aluesare=an&>J&efaultis=9
+CD2DREG@&efinestheporthere&atalinesareconnecte&to8&efaultisPORTB9
+CD2DBIT@&efinesthepositionof&atalinesfor=@bitinterface8Aor=J&efaultis=9#i"nore&for>@bit
interface
+CD2RSREG@&efinestheporthereRSlineisconnecte&to8&efaultisPORTB9
+CD2RSBIT@&efinesthepinhereRSlineisconnecte&to8&efaultis<9
+CD2EREG@&efinestheporthereElineisconnecte&to8&efaultisPORTB9
+CD2EBIT@&efinesthepinhereElineisconnecte&to8&efaultis39
+CD2R!REG@&efinestheporthereR:!lineisconnecte&to8settoAifnotuse&JAis&efault9
+CD2R!BIT@&efinesthepinhereR:!lineisconnecte&to8settoAifnotuse&JAis&efault9
+CD2COMMA$D%S@&efinesthe&ela*after+CDCMDO%Tstatement8&efault)alueisEAAA9
+CD2DATA%S@&efinesthe&ela*after+CDO%Tstatement8&efault)alueis;AA9
+CD2I$ITMS@&efinesthe&ela*for+CDI$ITstatement8&efault)alueis;AA9
13
Thelastthreeparametersshoul&besettolo)alueshenusin"inte"rate&+CDmo&ulesimulator,
IfR:!lineisconnecte&tomicrocontrolleran&parameter+CD2READ2B%S62.+AGissetto;
usin"DE.I$E&irecti)e#thenthese&ela*parametersillbei"nore&b*compileran&correcttimin"
illbeimplemente&b*rea&in"thestatusofthebus*fla"inthe+CD,
+CDI$ITstatementshoul&beplace&inthepro"rambeforean*of+CDO%T8use&forsen&in"&ata9
an&+CDCMDO%T8use&forsen&in"comman&s9statements,$umericconstantar"umentof
+CDI$ITisuse&to&efinethecursort*pe:AOnocursor8&efault9#;Oblin7#3Oun&erline#<Oblin7
Lun&erline,+CDO%Tan&+CDCMDO%Tstatementsma*ha)emultiplear"umentsseparate&b*D#D,
Strin"s#constantsan&)ariablescanbeuse&asar"umentsof+CDO%Tstatement,IfDPDsi"nisuse&
beforethenameofa)ariablethenits&ecimalrepresentationissenttothe+CDmo&ule,Constants
an&)ariablescanbeuse&asar"umentsof+CDCMDO%Tstatementan&thefolloin"7e*or&s
arealsoa)ailable:+c&Clear#+c&-ome#+c&+ine3-ome#+c&Displa*On#+c&Displa*Off#+c&CurOff#
+c&CurBlin7#+c&Cur%n&erline#+c&CurBlin7%n&erline#+c&+eft#+c&Ri"ht#+c&Shift+eft#
+c&ShiftRi"ht#+c&+ine;Clear#+c&+ine3Clear#+c&+ine;Pos89an&+c&+ine3Pos89,Ar"umentof
+c&+ine;Pos89an&+c&+ine3Pos89canbeanumberintheran"e8;@=A9orB*te&atat*pe)ariable,
The)aluecontaine&inthat)ariableshoul&beinthesameran"e,+c&Displa*Onan&+c&Displa*Off
illturnthecursoroff,Cursorrelate&s*mboliccomman&scanbeuse&asar"umentsof+CDI$IT,
-erearesomee1amples:
E1ample;:
De+ine L4D6B-". = N
De+ine L4D6DR87 = /0R"B
De+ine L4D6DB-" = 0
De+ine L4D6R.R87 = /0R"D
De+ine L4D6R.B-" = 1
De+ine L4D68R87 = /0R"D
De+ine L4D68B-" = ;
De+ine L4D6RWR87 = /0R"D
De+ine L4D6RWB-" = 1
L)dinit L)d4&rB'ink
'oo:@
L)do&t Le''o (or'dPL
W$it?s 1000
L)d)mdo&t L)d4'e$r
W$it?s 1000
7oto 'oo:
E1ample3:
De+ine L4D6B-". = N
De+ine L4D6DR87 = /0R"B
De+ine L4D6DB-" = 0
De+ine L4D6R.R87 = /0R"D
De+ine L4D6R.B-" = 1
De+ine L4D68R87 = /0R"D
De+ine L4D68B-" = ;
De+ine L4D6RWR87 = /0R"D
De+ine L4D6RWB-" = 1
Dim x As Word
x = ,55;5
L)dinit ;
W$it?s 1000
'oo:@
L)do&t L- $m )o&ntingPL
L)d)mdo&t L)dLine1ome
L)do&t Ox
x = x > 1
W$it?s 150
L)d)mdo&t L)d4'e$r
14
7oto 'oo:
+CDrelate&statementsillta7econtrolo)erTRISre"istersconnecte&ithpinsuse&for+CD
interface#butif*ouusePORTAorPORTEpinson&e)icesithA:DCon)erterMo&ulethen*ou
shoul&ta7econtrolo)ertheADCO$;re"istertosetuse&pinsas&i"italI:O,
6oucansetupuptoei"htuser&efine&characterstobeuse&on+CD,Thiscaneasil*be&oneith
+CDDE.C-ARstatement,Thefirstar"umentofthisstatementischarnumberan&mustbeinthe
ran"eA@G,$e1t>ar"umentsform>@linecharpattern8fromthetoptothebottom9an&mustbeinthe
ran"eA@<;8E@bitsi&e9,These>usercharactersareassi"ne&tocharco&esA@Gan&>@;Ean&can
be&ispla*e&usin"+CDO%Tstatement,After+CDDE.C-ARstatementthecursorillbein-OME
position,.ore1ample:
L)dde+)#$r 0J 10J 10J 10J 10J 10J 10J 10J 10
L)dde+)#$r 1J 911111J 910101J 910101J 910101J 910101J 910101J 910101J
911111
L)do&t 0J 1J Le''oPLJ 1J 0
.or+CDsithfourlinesofcharactersa&&itionals*mbolicar"umentsof+CDCMDO%Tstatement
canbeuse&:+c&+ine<-ome#+c&+ine=-ome#+c&+ine<Clear#+c&+ine=Clear#+c&+ine<Pos89an&
+c&+ine=Pos89,Ar"umentof+c&+ine<Pos89an&+c&+ine=Pos89canbeanumberintheran"e8;@=A9
orB*te&atat*pe)ariable,The)aluecontaine&inthat)ariableshoul&beinthesameran"e,Priorto
usin"theselan"ua"eelements#correct)alues&eterminin"+CDt*peshoul&beassi"ne&to
+CD2+I$ESan&+CD2C-ARSparametersusin"DE.I$E&irecti)es,
De+ine L4D6L-38. = <
De+ine L4D64AR. = 1,
De+ine L4D6B-". = N
De+ine L4D6DR87 = /0R"B
De+ine L4D6DB-" = 0
De+ine L4D6R.R87 = /0R"D
De+ine L4D6R.B-" = 1
De+ine L4D68R87 = /0R"D
De+ine L4D68B-" = ;
De+ine L4D6RWR87 = /0R"D
De+ine L4D6RWB-" = 1
L)dinit ;
'oo:@
L)d)mdo&t L)d4'e$r
L)d)mdo&t L)dLine1ome
L)do&t L"#is is 'ine 1L
L)d)mdo&t L)dLine1ome
L)do&t L"#is is 'ine 1L
L)d)mdo&t L)dLine;ome
L)do&t L"#is is 'ine ;L
L)d)mdo&t L)dLine<ome
L)do&t L"#is is 'ine <L
W$it?s 1000
L)d)mdo&t L)dLine14'e$r
L)d)mdo&t L)dLine14'e$r
L)d)mdo&t L)dLine;4'e$r
L)d)mdo&t L)dLine<4'e$r
L)d)mdo&t L)dLine1/os(1)
L)do&t LLine 1L
L)d)mdo&t L)dLine1/os(1)
L)do&t LLine 1L
L)d)mdo&t L)dLine;/os(;)
L)do&t LLine ;L
L)d)mdo&t L)dLine</os(<)
L)do&t LLine <L
W$it?s 1000
7oto 'oo:
15
CI3Ccommunicationithe1ternalI3C&e)ices
I3Ccommunicationcanbeimplemente&inbasicpro"ramsusin"I3C!RITEan&I3CREAD
statements,Thefirstar"umentofbothstatementsmustbeoneofthemicrocontrollerDspinsthatis
connecte&totheSDAlineofthee1ternalI3C&e)ice,Thesecon&ar"umentofbothstatementsmust
beoneofthemicrocontrollerDspinsthatisconnecte&totheSC+line,Thethir&ar"umentofboth
statementsmustbeaconstant)alueorB*te)ariablecalle&Dsla)ea&&ressD,Itsformatis&escribe&
inthe&atasheetoftheuse&&e)ice,.ore1ample#forEEPROMsfrom3=Cfamil*8ith&e)ice
a&&ressinputsconnecte&to"roun&9the)alueA1AAshoul&beuse&forsla)ea&&ressparameter,
Bothstatementsillta7econtrolo)erbitAofsla)ea&&ress&urin"communication,Theforth
ar"umentofbothstatementsmustbeaB*teor!or&)ariable8this&epen&sonthe&e)iceuse&9
thatcontainsthea&&ressofthelocationthatillbeaccesse&,Ifaconstant)alueisuse&for
a&&ressparameteritmustbeinB*te)alueran"e,Thelast8fifth9ar"umentofI3C!RITEstatement
isaB*teconstantor)ariablethatillberittentothespecifie&a&&ress#an&forI3CREAD
statementitmustbeaB*te)ariabletostorethe)aluethatillberea&fromthespecifie&a&&ress,It
isalloe&tousemorethanoneD&ataDar"ument,.orI3C&e)icesthat&onotsupport&ataa&&ress
ar"umentthereisshortformofI3Cstatements8I3C!RITE;an&I3CREAD;9a)ailableheresla)e
a&&ressar"umentisfolloe&ithoneormore&ataar"uments&irectl*,.orsomeI3Csla)e&e)ices
itisnecessar*toma7ea&ela*toma7esure&e)iceisrea&*torespon&toI3CREADstatement,.or
thatpurposethereisI3CREAD2DE+A6%Sparameterthatcanbesetb*DE.I$E&irecti)ean&has
&efault)alueofAmicrosecon&s,Also#forsloerI3C&e)ices#itmi"htbenecessar*touselon"er
cloc7pulses,Thatcanbe&oneb*settin"I3CC+OC42STRETC-parameterusin"DE.I$E
&irecti)e,Thisparameterillsetcloc7stretchfactor,Its&efault)alueis;,-ereisonecombine&
e1ampleith+CDmo&ulean&3=C?=EEPROM8SDAconnecte&toRC3JSC+connecte&toRC<9:
E1ample;:
De+ine L4D6B-". = N
De+ine L4D6DR87 = /0R"B
De+ine L4D6DB-" = 0
De+ine L4D6R.R87 = /0R"D
De+ine L4D6R.B-" = 1
De+ine L4D68R87 = /0R"D
De+ine L4D68B-" = ;
De+ine L4D6RWR87 = /0R"D
De+ine L4D6RWB-" = 1
Dim $ddr As Word
Dim d$t$ As Byte
.ym*o' sd$ = /0R"4.1
.ym*o' s)' = /0R"4.;
L)dinit ;
W$it?s 1000
5or $ddr = 0 "o ;1
L)d)mdo&t L)d4'e$r
d$t$ = 155 > $ddr
-14Write sd$J s)'J 0x$0J $ddrJ d$t$
L)do&t LWrite "o 88/R0?L
L)d)mdo&t L)dLine1ome
L)do&t L(LJ O$ddrJ L) = LJ Od$t$
W$it?s 1000
3ext $ddr
5or $ddr = 0 "o ;1
L)d)mdo&t L)d4'e$r
-14Re$d sd$J s)'J 0x$0J $ddrJ d$t$
L)do&t LRe$d 5rom 88/R0?L
L)d)mdo&t L)dLine1ome
L)do&t L(LJ O$ddrJ L) = LJ Od$t$
W$it?s 1000
3ext $ddr
16
Thereisasetoflo@le)elI3Ccommunicationstatementsa)ailable#ifitisnee&e&toha)emore
controlo)erI3Ccommunicationprocess,I3CPREPAREstatementhastoar"umentsthatmustbe
oneofthemicrocontrollerDspins,Thefirstar"ument&efinesSDAlinean&secon&ar"ument&efines
SC+line,ThisstatementillpreparetheselinesforI3Ccommunication,I3CSTARTstatementill
"eneratestartcon&ition#an&I3CSTOPstatementill"eneratestopcon&ition,Oneb*tecanbesent
totheI3Csla)eusin"I3CSE$Dstatement,Afterthestatementise1ecute&CbitinSTAT%S
re"isterillhol&thecop*ofthestateontheSDAline&urin"theac7nole&"ec*cle,Thereareto
statementsthatcanbeuse&torecei)eoneb*tefromI3Csla)e,I3CRECAorI3CRECEI(EAC4ill
"enerateac7nole&"esi"nal&urin"ac7nole"&ec*cleaftertheb*teisrecei)e&,I3CREC$or
I3CRECEI(E$AC4ill"eneratenotac7nole&"esi"nal&urin"ac7nole"&ec*cleaftertheb*teis
recei)e&,Onee1ample:
E1ample3:
Dim $ddr As Word
Dim d$t$(;1) As Byte
.ym*o' sd$ = /0R"4.1
.ym*o' s)' = /0R"4.;
$ddr = 0
-14/re:$re sd$J s)'
-14.t$rt
-14.end 0x$0
-14.end $ddr.B
-14.end $ddr.LB
-14.to:
-14.t$rt
-14.end 0x$1
5or $ddr = 0 "o ;0
-14Re)eiveA)k d$t$($ddr)
3ext $ddr
-14Re)3 d$t$(;1)
-14.to:
CSupportforSerialPeripheralInterface8SPI9communication
Priortousin"SPIrelate&statements#SPIinterfaceshoul&besetupusin"DE.I$E&irecti)es,
Thereareei"hta)ailableparametersto&efinetheconnectionofSC4#SDI#SDOan&8optionall*9
CSlines:
SPI2SC42REG@&efinestheporthereSC4lineisconnecte&to
SPI2SC42BIT@&efinesthepinhereSC4lineisconnecte&to
SPI2SDI2REG@&efinestheporthereSDIlineisconnecte&to
SPI2SDI2BIT@&efinesthepinhereSDIlineisconnecte&to
SPI2SDO2REG@&efinestheporthereSDOlineisconnecte&to
SPI2SDO2BIT@&efinesthepinhereSDOlineisconnecte&to
SPI2CS2REG@&efinestheporthereCSlineisconnecte&to
SPI2CS2BIT@&efinesthepinhereCSlineisconnecte&to
Theassume&settin"sareacti)e@hi"hforCloc7linean&acti)e@loforChipSelectline,Thatcanbe
chan"e&b*assi"nin"the)alue;toSPIC+OC42I$(ERTan&:orSPICS2I$(ERTparametersb*
DE.I$E&irecti)e,.orsloerSPI&e)ices#itmi"htbenecessar*touselon"ercloc7pulses,The
&efaultcloc7stretchfactor8;9canbechan"e&b*settin"SPIC+OC42STRETC-parameter,
SPIPREPAREstatement8noar"uments9illprepareinterfacelinesforSPIcommunication,
SPICSO$an&SPICSO..statementsillenable:&isabletheChipSelectlineoftheinterface,One
b*tecanbesenttotheSPIperipheralusin"SPISE$Dstatement,Torecei)eab*tefromthe
peripheralSPIRECEI(Estatementshoul&beuse&,Tosen&thespecifie&numberofbitsthereis
SPISE$DBITSstatementa)ailable,Itsfirstar"umentshoul&bethenumberofbitstobesentH;@>I
an&thesecon&ar"umentisab*te)ariableorconstant,-ereisonee1ampleforusin"3ECA=ASPI
eeprom:
E1ample;:
17
A''Digit$'
De+ine ./-64.6R87 = /0R"4
De+ine ./-64.6B-" = 0
De+ine ./-6.4G6R87 = /0R"4
De+ine ./-6.4G6B-" = ;
De+ine ./-6.D-6R87 = /0R"4
De+ine ./-6.D-6B-" = <
De+ine ./-6.D06R87 = /0R"4
De+ine ./-6.D06B-" = 5
./-/re:$re
De+ine L4D6B-". = N
De+ine L4D6DR87 = /0R"D
De+ine L4D6DB-" = 0
De+ine L4D6R.R87 = /0R"8
De+ine L4D6R.B-" = 0
De+ine L4D6RWR87 = /0R"8
De+ine L4D6RWB-" = 1
De+ine L4D68R87 = /0R"8
De+ine L4D68B-" = 1
De+ine L4D6R8AD6B2.I65LA7 = 1
L)dinit
Dim $ddr As Byte
Dim d$t$ As Byte
5or $ddr = 0 "o 10
d$t$ = 100 > $ddr
./-4.0n
./-.end 0x0,
./-4.0++
./-4.0n
./-.end 0x01
./-.end $ddr
./-.end d$t$
./-4.0++
L)d)mdo&t L)d4'e$r
L)do&t LWrite "o 88/R0?L
L)d)mdo&t L)dLine1ome
L)do&t L(LJ O$ddrJ L) = LJ Od$t$
W$it?s 500
3ext $ddr
5or $ddr = 0 "o 10
./-4.0n
./-.end 0x0;
./-.end $ddr
./-Re)eive d$t$
./-4.0++
L)d)mdo&t L)d4'e$r
L)do&t LRe$d 5rom 88/R0?L
L)d)mdo&t L)dLine1ome
L)do&t L(LJ O$ddrJ L) = LJ Od$t$
W$it?s 500
3ext $ddr
-ereisthesamee1amplerittenforF<C>?MicroireEEPROM:
E1ample3:
A''Digit$'
18
De+ine ./-64.6R87 = /0R"4
De+ine ./-64.6B-" = 0
De+ine ./-4.6-3A8R" = 1
De+ine ./-6.4G6R87 = /0R"4
De+ine ./-6.4G6B-" = ;
De+ine ./-6.D-6R87 = /0R"4
De+ine ./-6.D-6B-" = <
De+ine ./-6.D06R87 = /0R"4
De+ine ./-6.D06B-" = 5
./-/re:$re
De+ine L4D6B-". = N
De+ine L4D6DR87 = /0R"D
De+ine L4D6DB-" = 0
De+ine L4D6R.R87 = /0R"8
De+ine L4D6R.B-" = 0
De+ine L4D6RWR87 = /0R"8
De+ine L4D6RWB-" = 1
De+ine L4D68R87 = /0R"8
De+ine L4D68B-" = 1
De+ine L4D6R8AD6B2.I65LA7 = 1
L)dinit
Dim $ddr As Byte
Dim d$t$ As Byte
./-4.0n
./-.endBits ,J 9100110
./-.endBits NJ 900000000
./-4.0++
5or $ddr = 0 "o 10
d$t$ = 100 > $ddr
./-4.0n
./-.endBits ,J 9101000
./-.endBits NJ $ddr
./-.end d$t$
./-4.0++
./-4.0n
./-.end 0x00
./-4.0++
L)d)mdo&t L)d4'e$r
L)do&t LWrite "o 88/R0?L
L)d)mdo&t L)dLine1ome
L)do&t L(LJ O$ddrJ L) = LJ Od$t$
W$it?s 500
3ext $ddr
5or $ddr = 0 "o 10
./-4.0n
./-.endBits ,J 9110000
./-.endBits NJ $ddr
./-Re)eive d$t$
./-4.0++
L)d)mdo&t L)d4'e$r
L)do&t LRe$d 5rom 88/R0?L
L)d)mdo&t L)dLine1ome
L)do&t L(LJ O$ddrJ L) = LJ Od$t$
W$it?s 500
3ext $ddr
19
CInterfacin""raphical+CDsith;3>1?=&otmatri1
Interfacin""raphical+CDsith&otmatri1resolution;3>1?=controlle&b*4SA;A>orcompatible
chipissupporte&iththefolloin"listofBasiclan"ua"eelements:G+CDI$IT#G+CDC+EAR#
G+CDPSET#G+CDPRESET#G+CDPOSITIO$#G+CD!RITE#G+CDC+EA$#G+CDO%T#G+CDI$#
G+CDCMDO%T,Priortousin"Graphical+CDsrelate&statements#usershoul&setuptheinterface
iththe"raphical+CDmo&uleusin"DE.I$E&irecti)es,-ereisthelistofa)ailableparameters:
G+CD2DREG@&efinestheporthere&atalinesareconnecte&to8ithastobeafull>@pinsport9
G+CD2RSREG@&efinestheporthereRSlineisconnecte&to
G+CD2RSBIT@&efinesthepinhereRSlineisconnecte&to
G+CD2EREG@&efinestheporthereElineisconnecte&to
G+CD2EBIT@&efinesthepinhereElineisconnecte&to
G+CD2R!REG@&efinestheporthereR:!lineisconnecte&to
G+CD2R!BIT@&efinesthepinhereR:!lineisconnecte&to
G+CD2CS;REG@&efinestheporthereCS;lineisconnecte&to
G+CD2CS;BIT@&efinesthepinhereCS;lineisconnecte&to
G+CD2CS3REG@&efinestheporthereCS3lineisconnecte&to
G+CD2CS3BIT@&efinesthepinhereCS3lineisconnecte&to
G+CDI$ITstatementshoul&beplace&somehereatthebe"innin"ofthebasicpro"rambefore
an*other"raphical+CDrelate&stetementsareuse&,Graphical+CDrelate&statementsillta7e
controlo)erTRISre"istersconnecte&ithpinsuse&for+CDinterface#butif*ouusepinsthatare
setupasanalo"inputsatpoer@upon&e)icesithA:DCon)erteran&:orComparatormo&ules#*ou
shoul&ta7econtrolo)ertheappropriatere"ister8s98ADCO$;#A$SE+#CMCO$9tosetuse&pinsas
&i"italI:O,
G+CDC+EARstatementillclearthehole&ispla*,Itcanbeuse&ithoneoptionalconstant
ar"umentintheran"eA@3EEthatillbeplace&one)er*b*tepositiononthe&ispla*8;3>1?=
"raphical&ispla*sareinternal*&i)i&e&into?=1?=hal)esJbothhal)esare&i)i&e&inei"ht?=1>
hori'ontalpa"esJe)er*pa"ehasitsa&&ressin"numberintheran"eA@;EJpa"einupper@leftcorner
hasnumberAJpa"einloer@leftcornerhasnumberGJpa"einupper@ri"htcornerhasnumber>J
pa"einloer@ri"htcornerhasnumber;EJe)er*pa"ehas?=b*tepositionsa&&resse&ith
numbersintheran"eA@?<Je)er*b*tepositionhas>bitsJtheuppermostbitis+SBan&the
loermostbitisMSB9,.ore1ample:
7L)dinit
'oo:@
7L)d)'e$r 0x$$
W$it?s 1000
7L)d)'e$r 0x55
W$it?s 1000
7oto 'oo:
G+CDPSETan&G+CDPRESETstatementsareuse&toturnonan&turnoffoneofthe&otsonthe
"raphical&ispla*,Thefirstar"umentisthehori'ontalcoor&inatean&itmustbeab*te&atat*pe
)ariableorconstantintheran"eA@;3G,Thesecon&ar"umentisthe)erticalcoor&inatean&itmust
beab*te&atat*pe)ariableorconstantintheran"eA@?<,The&otintheupper@leftcornerofthe
&ispla*istheori"inithcoor&inatesA#A,.ore1ample:
Dim i As Byte
Dim j As Byte
7L)dinit
5or i = 0 "o 117
5or j = 0 "o ,;
7L)d:set iJ j
3ext j
3ext i
G+CDC+EA$statementisuse&toclearasectionofthepa"eonthe&ispla*,Ithasthree
ar"uments,Thefirstar"umentispa"ea&&ressan&itmustbeab*te&atat*pe)ariableorconstant
intheran"eA@;E,Thesecon&ar"umentisthefirstb*tepositiononthepa"ethatillbecleane&
an&itmustbeab*te&atat*pe)ariableorconstantintheran"eA@?<,Thethir&ar"umentisthelast
b*tepositiononthepa"ethatillbecleane&an&itmustbeab*te&atat*pe)ariableorconstantin
20
theran"eA@?<,Ifthelasttoar"umentsareomitte&theholepa"eillbecleare&,.ore1ample:
Dim i As Byte
7L)dinit
7L)d)'e$r 0x++
5or i = 0 "o 15
7L)d)'e$n i
W$it?s 500
3ext i
G+CDPOSITIO$statementisuse&toa&&ressab*tepositiononthe&ispla*,Itmustbeuse&before
an*oftheG+CD!RITE#G+CDI$#G+CDO%Tan&G+CDCMDO%Tstatements,Thefirstar"ument
ispa"ea&&ressan&itmustbeab*te&atat*pe)ariableorconstantintheran"eA@;E,Thesecon&
ar"umentisthetar"etb*tepositiononthepa"ean&itmustbeab*te&atat*pe)ariableorconstant
intheran"eA@?<,Ifthesecon&ar"umentisomitte&#'erob*tepositionisuse&,
G+CD!RITEstatementisuse&toritete1tonthe&ispla*,Itillstartritin"fromthecurrentb*te
positiononthe&ispla*,Itmustbeuse&carefull*#becausehentheb*teposition8?<9ofthepa"eis
reache&#theritin"illcontinuefromtheb*tepositionAsta*in"onthesamepa"e,Thei&thof
e)er*characterrittenisEb*tepositionsplusoneclearb*teposition,Afterthestatementis
e1ecute&thecurrentb*tepositionillbeattheen&ofthete1tritten,G+CD!RITEstatementma*
ha)emultiplear"umentsseparate&b*D#D,Strin"s#constantsan&b*te)ariablescanbeuse&asits
ar"uments,Constantsan&)ariable)aluesareinterprete&asASCIIco&es,IfDPDsi"nisuse&before
thenameofa)ariable8b*teoror&&atat*pe9thenits&ecimalrepresentationisritten,.or
e1ample:
Dim i As Byte
7L)dinit
5or i = 0 "o 15
7L)d:osition iJ 0
7L)d(rite L/$ge@ LJ Oi
W$it?s 150
3ext i
G+CDO%Tstatementisuse&toritethe)alueoftheb*te)ariableorconstantatthecurrentb*te
positiononthe&ispla*,Thecurrentb*tepositionillbeincremente&b*one,G+CDI$statementill
rea&the)aluefromthecurrentb*tepositiononthe&ispla*an&putitintheb*te)ariablespecifie&
asitsar"ument,G+CDCMDO%Tstatementisuse&tosen&lo@le)elcomman&stothe"raphical
+CD,Itsar"umentcanbeaconstantorb*te&atat*pe)ariable,Allthesethreestatementscanbe
use&ithmultiplear"umentsseparate&b*D#D,
C%sin"internalP!Mmo&ules
InternalP!Mmo&ules8moreprecisel*:P!Mmo&esofCCPmo&ules9areturne&onusin"
P!MO$statement,Thisstatementhastoar"uments,Thefirstar"umentismo&ulenumberan&it
mustbeaconstantintheran"e;@<,Thesecon&ar"umentisuse&formo&eselection,Internal
P!Mmo&ulecanbeuse&onthree&ifferentoutputfre/uenciesforeachoffour&ut*c*cle
resolutionssupporte&b*P!MO$statement8;A@bit#F@bit#>@bitan&G@bit9,So#P!Mmo&ulecanbe
turne&onithP!MO$statementin;3mo&es,-ereisthelistofallmo&esat=M-'cloc7
fre/uenc*8forothercloc7fre/uencies#the)aluesshoul&beproportionall*a&Nuste&9:
mo&e;:;A@bit#3==-'
mo&e3:;A@bit#FGG-'
mo&e<:;A@bit#<FA?-'
mo&e=:F@bit#=>>-'
mo&eE:F@bit#;FE<-'
mo&e?:F@bit#G>;<-'
mo&eG:>@bit#FGG-'
mo&e>:>@bit#<FA?-'
mo&eF:>@bit#;E?3E-'
mo&e;A:G@bit#;FE<-'
mo&e;;:G@bit#G>;<-'
mo&e;3:G@bit#<;3EA-'
21
TheP!Mmo&uleisinitiall*starte&ithA&ut*c*cle#sotheoutputillsta*lountilthe&ut*c*cle
ischan"e&,P!Mmo&ulecanbeturne&offithP!MO..statement,Ithasonl*onear"ument@
mo&ulenumber,
The&ut*c*cleofP!Msi"nalcanbechan"e&ithP!MD%T6statement,Itsfirstar"umentis
mo&ulenumber,Thesecon&ar"umentis&ut*c*clean&itcanbeaconstantintheran"eA@;A3<or
b*teoror&&atat*pe)ariable,%sermustta7ecaretousetheproper)alueran"esforallP!M
mo&es8A@;A3<for;A@bitresolution#A@E;;forF@bitresolution#A@3EEfor>@bitresolutionan&A@;3G
forG@bitresolution9,-ereisonee1amplee1ample:
Dim d&ty As Byte
/W?on 1J K
'oo:@
Ad)in 0J d&ty
/W?d&ty 1J d&ty
7oto 'oo:
CInterfacin"Ra&ioControl8R:C9ser)os
.orritin"applicationstointerfaceR:Cser)ostherearetostatementsa)ailable:SER(OI$an&
SER(OO%T,R:Cser)oiscontrolle&b*atrainofpulses8;E@3Apulsespersecon&9hoselen"th
&efinethepositionoftheser)oarm,The)ali&len"thofpulsesisintheran"e;@3ms,Theseto
statementsha)etoar"uments,Thefirstar"umentofbothstatementsisthemicrocontrollerpin
heretheser)osi"nalisrecei)e&ortransmitte&,.orSER(OI$statementthatpinshoul&be
pre)iousl*setupasaninputpinan&forSER(OO%Tstatementthepinshoul&besetupforoutput,
Thesecon&ar"umentofSER(OI$statementmustbeaB*te)ariableherethelen"thofthepulse
illbesa)e&,Thepulsesaremeasure&in;Ausunits#soitispossibletomeasurepulsesinthe
ran"eA,A;@3,EEms,The)aluestore&inthe)ariablefornormalser)osshoul&beintheran"e;AA@
3AA,Thesecon&ar"umentoftheSER(OO%Tstatementshoul&beaB*te)ariableorconstantthat
&eterminesthelen"thofthe"enerate&pulse,.orproperoperationofthetar"etser)oSER(OO%T
statementshoul&bee1ecute&;E@3Atimes&urin"onesecon&,-ereisane1ampleoftheser)o
re)erseoperation:
Dim 'engt# As Byte
"R-.B.0 = 1
"R-.B.1 = 0
'oo:@
.ervo-n /0R"B.0J 'engt#
-+ 'engt# F 100 "#en 'engt# = 100
-+ 'engt# E 100 "#en 'engt# = 100
'engt# = 'engt# > 100
'engt# = 100 > 'engt#
'engt# = 'engt# = 100
.ervo0&t /0R"B.1J 'engt#
7oto 'oo:
CInterfacin"StepperMotors
Priortousin"steppermotorrelate&statements#itsconnectionan&&esire&&ri)emo&eshoul&be
setupusin"DE.I$E&irecti)es,Thereareei"hta)ailableparametersto&efinetheconnectionofA#
B#Can&Dcoils:
STEP2A2REG@&efinestheporthereAcoilisconnecte&to
STEP2A2BIT@&efinesthepinhereAcoilisconnecte&to
STEP2B2REG@&efinestheporthereBcoilisconnecte&to
STEP2B2BIT@&efinesthepinhereBcoilisconnecte&to
STEP2C2REG@&efinestheporthereCcoilisconnecte&to
STEP2C2BIT@&efinesthepinhereCcoilisconnecte&to
STEP2D2REG@&efinestheporthereDcoilisconnecte&to
STEP2D2BIT@&efinesthepinhereAcoilisconnecte&to
CoilsAan&Careactuall*partsofonesin"lecoilithcommonconnection,Thesameis)ali&forB
an&Dcoilconnections,ThereisalsoSTEP2MODEparameteruse&to&efinethe&ri)emo&e,Ifitis
setto;8&efault9themotorillbe&ri)eninfull@stepmo&e,The)alue3shoul&beuse&forhalf@step
22
mo&e,Thefirstbasicstatementthatshoul&beuse&isSTEP-O+D,Itillconfi"ureuse&pinsas
outputsan&alsoener"i'eAan&Bcoilstofi1therotorinitsinitialposition,.ormo)in"rotorin
cloc7isean&countercloc7ise&irectionsthereareSTEPC!an&STEPCC!statements
a)ailable,Theirfirstar"umentisthenumberofrotorstepsthatillbeperforme&an&itcanbeB*te
&atat*peconstantor)ariable,Thesecon&ar"ument&efinesthe&ela*beteenconsecuti)esteps
e1presse&inmicrosecon&sb*aB*teor!or&&atat*pe)ariableorconstant,Ifusin"STEPC!
statementresultsinrotormo)ementincountercloc7ise&irectionthenconnectionsettin"sforBan&
Dcoilsshoul&bee1chan"e&,-erearetoe1amples8thesecon&e1ampleuses&ela*ssuitablefor
simulationinthesimulator9:
E1ample;:
A''Digit$'
AD4031 = 0x0e
De+ine ."8/6A6R87 = /0R"B
De+ine ."8/6A6B-" = 7
De+ine ."8/6B6R87 = /0R"B
De+ine ."8/6B6B-" = ,
De+ine ."8/646R87 = /0R"B
De+ine ."8/646B-" = 5
De+ine ."8/6D6R87 = /0R"B
De+ine ."8/6D6B-" = <
De+ine ."8/6?0D8 = 1
W$it?s 1000
.te:o'd
W$it?s 1000
Dim $n0 As Word
'oo:@
Ad)in 0J $n0
$n0 = $n0 B ,0
$n0 = $n0 = 1000
.te:4W 1J $n0
7oto 'oo:
E1ample3:
A''Digit$'
De+ine ."8/6A6R87 = /0R"B
De+ine ."8/6A6B-" = 7
De+ine ."8/6B6R87 = /0R"B
De+ine ."8/6B6B-" = ,
De+ine ."8/646R87 = /0R"B
De+ine ."8/646B-" = 5
De+ine ."8/6D6R87 = /0R"B
De+ine ."8/6D6B-" = <
De+ine ."8/6?0D8 = 1
W$it2s ;00
.te:o'd
W$it2s 1000
'oo:@
.te:44W 1,J ;00
W$it2s 1000
.te:4W 1<J ;00
W$it2s 1000
7oto 'oo:
CInterfacin";@!IRE&e)ices
Priortousin";@!IRErelate&statements#usershoul&&efinethepinherethe&e)iceisconnecte&
23
tousin"DE.I$E&irecti)es,A)ailableparametersare;!IRE2REGan&;!IRE2BIT,.ore1ample:
De+ine 1W-R86R87 = /0R"B
De+ine 1W-R86B-" = 0
Initiali'ationse/uencecanbeperforme&b*;!IREI$ITstatement,Itcanha)eanoptional
ar"ument8Bit&atat*pe)ariable9thatillbesettoAifthepresenceofthe&e)icehasbeen&etecte&
an&setto;ifthereisno&e)iceontheline,
In&i)i&ualbits8timeslots9canbesenttoan&recei)e&fromthe&e)iceusin";!IRESE$DBITan&
;!IREGETBITstatements,Bothstatementscanha)emultiplear"uments@commaseparate&listof
Bit&atat*pe)ariables8orBitconstantsfor;!IRESE$DBITstatement9,
;!IRESE$DB6TEan&;!IREGETB6TEstatementscanbeuse&tosen&toan&recei)eb*tes
fromthe&e)ice,Bothstatementscanha)emultiplear"uments@commaseparate&listofB*te&ata
t*pe)ariables8orB*teconstantsfor;!IRESE$DB6TEstatement9,-ereisonee1amplefor
measurin"temperatureusin"DS;>S3A&e)ice:
Dim +inis# As Bit
Dim tem: As Byte
Dim sign As Byte
1(ire-nit
1(ire.endByte 0x))J 0x<<
W$it?s 1
'oo:@
1(ire7etBit +inis#
-+ +inis# = 0 "#en 7oto 'oo:
1(ire-nit
1(ire.endByte 0x))J 0x*e
1(ire7etByte tem:J sign
Thise1amplecanbe)er*shortb*usin"toDS;>S3Aspecifichi"hle)elbasicstatements,
DS;>S3ASTARTstatementillinitiateasin"letemperaturecon)ersion,Accor&in"tothe&e)ice
&atasheetthecon)ersionillbecomplete&inatmostGEAms,Afterthatperio&themeasure&)alue
canberea&b*DS;>S3AREADTstatementthatre/uirestoB*te&atat*pe)ariablesas
ar"uments,Thefirstar"umentillcontainthetemperature)alueinA,E&e"reescenti"ra&eunits8for
e1ample#the)alue;AArepresentsthetemperatureofEA&e"rees9,Thesecon&ar"umentill
containthe)alueA1AAifthetemperatureispositi)ean&A1..)alueifitisne"ati)e,.ore1ample:
Dim tem: As Byte
Dim sign As Byte
D.1N.10.t$rt
W$it?s 1000
D.1N.10Re$d" tem:J sign
CA&)ance&features
IfSTART.ROMBERO&irecti)eisuse&thecompilerillstartthepro"ramfrom'eroflashpro"ram
memor*location8reset)ector9an&usethea)ailablepro"rammemor*continuousl*,Interrupt
routineifuse&shoul&beimplemente&b*usin"inlineassemblerco&e,Thecompilerillalsolea)e
controlo)erPC+AT-re"istertotheusersupposin"thatallco&eisplace&inthesamepro"ram
memor*pa"e,Thisa&)ance&featurecanbeuse&hen&e)elopin"bootloa&erapplications#for
e1ample,
24

You might also like