Positron Compiler Documentation

Original printed contents

Positron8 · Revision 4.0.6.5 · PDF pages 4–16

Table of Contents.

Positron8 Compiler Overview .................................................................................. 17 PICmicro™ Devices.........................................................................................................18 Device Specific issues ....................................................................................................18 Identifiers.....................................................................................................................19 Line Labels ...................................................................................................................19 Commenting Lines of Code.............................................................................................19 Standard Variables ........................................................................................................20 Pre-Assigning Variables. ....................................................................................................................... 20 Static Variables .............................................................................................................23 Global Variables ............................................................................................................25 Shared Variables ...........................................................................................................26 Pin Variables.................................................................................................................27 Floating Point Mathematics.............................................................................................28 Floating Point to Integer Rounding ........................................................................................................ 31 Floating Point Exception Flags............................................................................................................... 32 Aliases..........................................................................................................................33 Constants .....................................................................................................................38 Symbols .......................................................................................................................38 Numeric Representations ...............................................................................................39 Quoted String of Characters ...........................................................................................39 Ports and other Registers...............................................................................................39 General Format .............................................................................................................40 Procedures ...................................................................................................................41 Parameters.......................................................................................................................................... 41 Parameter as an Alias to a Global Variable or SFR................................................................................... 42 Local Variable and Label Names ............................................................................................................ 44 Procedure Return Variable .................................................................................................................... 45 Procedure Return Variable as an Alias to an SFR or Global Variable ..........................................................47 A Typical Procedural BASIC Program Layout ....................................................................48 A Typical flat BASIC Program Layout...............................................................................49 Line Continuation Character '_' .......................................................................................50 Creating and using Arrays ..............................................................................................51 Creating and using Strings .............................................................................................59 Creating and using Flash Memory Strings ........................................................................65 Creating Constant value Flash Memory Tables of different data sizes........................................................ 67 Creating and using EEPROM Strings with Edata................................................................69 String Comparisons .......................................................................................................71 Limited 12-bit Core Device Compatibility..........................................................................74

View original PDF page 4Open page in PDFOriginal PDF page 4

Programming Considerations for 12-bit core Devices. ...................................................... 75 Relational Operators ..................................................................................................... 76 Boolean Logic Operators ............................................................................................... 77

View original PDF page 5Open page in PDFOriginal PDF page 5

Mathematic Operations and Functions .................................................................... 78 Standard operators........................................................................................................79 Logical operators...........................................................................................................79 Positron8 functions........................................................................................................79 Trigonometry functions..................................................................................................79 Bitwise Reverse '@' .......................................................................................................93 Decimal Digit extract '?' .................................................................................................94 Abs ..............................................................................................................................95 fAbs .............................................................................................................................96 Acos.............................................................................................................................97 Asin .............................................................................................................................98 Atan.............................................................................................................................99 Cos ............................................................................................................................100 Dcd............................................................................................................................101 Exp ............................................................................................................................102 fRound .......................................................................................................................103 ISin............................................................................................................................104 ICos ...........................................................................................................................105 ISqr ...........................................................................................................................106 Log ............................................................................................................................107 Log10.........................................................................................................................108 Ncd............................................................................................................................109 Pow ...........................................................................................................................110 Sin .............................................................................................................................111 Sqr.............................................................................................................................112 Tan ............................................................................................................................113 Div32 .........................................................................................................................114

View original PDF page 6Open page in PDFOriginal PDF page 6

Peripheral and Interfacing Commands.................................................................. 119 ADin...........................................................................................................................120 Bstart .........................................................................................................................122 Bstop .........................................................................................................................123 Brestart ......................................................................................................................123 BusAck .......................................................................................................................123 BusNack .....................................................................................................................123 Busin..........................................................................................................................124 Busout........................................................................................................................127 Button........................................................................................................................131 Counter ......................................................................................................................133 DTMFout ....................................................................................................................134 Freqout ......................................................................................................................135 HbStart.......................................................................................................................137 HbStop.......................................................................................................................138 HbRestart ...................................................................................................................138 HbusAck .....................................................................................................................138 HbusNack ...................................................................................................................138 Hbusin........................................................................................................................139 Hbusout......................................................................................................................143 High (PinHigh) ............................................................................................................147 HPWM ........................................................................................................................149 I2Cin..........................................................................................................................151 I2Cout........................................................................................................................153 Inkey .........................................................................................................................156 Input (PinInput) ..........................................................................................................157 Low (PinLow)..............................................................................................................159 Output (PinOutput)......................................................................................................161 Oread.........................................................................................................................163 Owrite ........................................................................................................................168 PinClear......................................................................................................................170 PinGet (GetPin) ...........................................................................................................172 PinMode .....................................................................................................................173 PinPullup ....................................................................................................................175 PinSet.........................................................................................................................176

View original PDF page 7Open page in PDFOriginal PDF page 7

Pot.............................................................................................................................178 PulseIn.......................................................................................................................179 PulseOut.....................................................................................................................180 PWM ..........................................................................................................................181 RC5in .........................................................................................................................182 RCin...........................................................................................................................183 Servo .........................................................................................................................186 Shin ...........................................................................................................................188 Shout .........................................................................................................................190 SonyIn .......................................................................................................................192 Sound ........................................................................................................................193 Sound2.......................................................................................................................194 Toggle........................................................................................................................195 USBinit .......................................................................................................................196 USBin.........................................................................................................................197 USBout.......................................................................................................................199 USBpoll ......................................................................................................................203 Xin.............................................................................................................................204 Xout...........................................................................................................................206

View original PDF page 8Open page in PDFOriginal PDF page 8

Async Serial Commands......................................................................................... 208 HRsin, HRsin2, HRsin3, HRsin4, Hrsin5..........................................................................209 HRsout, HRsout2, HRsout3, HRsout4, HRsout5 ..............................................................215 HRsoutLn, HRsout2Ln, HRsout3Ln, HRsout4Ln, HRsout5Ln.............................................219 HSerin, HSerin2, HSerin3, Hserin4, Hserin5 ...................................................................220 HSerout, HSerout2, HSerout3, HSerout4, HSerout5 ........................................................226 HSeroutLn, HSerout2Ln, HSerout3Ln, HSerout4Ln, HSerout5Ln.......................................230 HSerialx_ChangeBaud..................................................................................................231 Rsin ...........................................................................................................................232 Rsout .........................................................................................................................238 RsoutLn......................................................................................................................243 Serin ..........................................................................................................................244 Serout ........................................................................................................................252

View original PDF page 9Open page in PDFOriginal PDF page 9

LCD Commands ......................................................................................................260 Box ............................................................................................................................261 Circle..........................................................................................................................262 Cls .............................................................................................................................263 Cursor ........................................................................................................................264 LCDread .....................................................................................................................265 LCDwrite ....................................................................................................................267 Line............................................................................................................................269 LineTo........................................................................................................................270 Pixel...........................................................................................................................271 Plot ............................................................................................................................272 Print...........................................................................................................................274 Using a KS0108 Graphic LCD............................................................................................................... 280 Using a Toshiba T6963 Graphic LCD .................................................................................................... 285 Toshiba_Command......................................................................................................288 Toshiba_UDG..............................................................................................................292 UnPlot ........................................................................................................................294

View original PDF page 10Open page in PDFOriginal PDF page 10

Comparison and Loop Commands.......................................................................... 295 Branch........................................................................................................................296 BranchL......................................................................................................................297 Break .........................................................................................................................298 Bound ........................................................................................................................300 Continue.....................................................................................................................301 Do...Loop....................................................................................................................302 For...Next...Step..........................................................................................................304 If..Then..ElseIf..Else..EndIf ..........................................................................................306 On GoTo.....................................................................................................................308 On GoToL ...................................................................................................................310 On GoSub...................................................................................................................311 Repeat...Until..............................................................................................................313 Select..Case..EndSelect................................................................................................314 SizeOf ........................................................................................................................316 Tern...........................................................................................................................317 While...Wend ..............................................................................................................318

View original PDF page 11Open page in PDFOriginal PDF page 11

General BASIC Commands .....................................................................................319 AddressOf...................................................................................................................320 Call ............................................................................................................................321 Clear ..........................................................................................................................322 ClearBit ......................................................................................................................323 Dec ............................................................................................................................324 DelayCs......................................................................................................................325 DelayMs .....................................................................................................................326 DelayUs......................................................................................................................327 Dig.............................................................................................................................328 GetBit.........................................................................................................................329 GoSub ........................................................................................................................330 GoTo..........................................................................................................................334 Inc.............................................................................................................................335 LoadBit.......................................................................................................................336 Pop ............................................................................................................................337 Ptr8, Ptr16, Ptr24, Ptr32...............................................................................................339 Push...........................................................................................................................342 Random......................................................................................................................347 Return........................................................................................................................348 Rol.............................................................................................................................350 Ror ............................................................................................................................351 Seed ..........................................................................................................................352 SetBit .........................................................................................................................353 Set.............................................................................................................................354 Snooze .......................................................................................................................355 Sleep..........................................................................................................................356 Stop...........................................................................................................................358 Swap..........................................................................................................................359

View original PDF page 12Open page in PDFOriginal PDF page 12

RAM String Variable Commands ............................................................................ 360 Len ............................................................................................................................361 Left$ ..........................................................................................................................363 Mid$...........................................................................................................................365 Right$ ........................................................................................................................367 Strn............................................................................................................................369 Str$............................................................................................................................370 ToLower .....................................................................................................................372 ToUpper .....................................................................................................................374 Val .............................................................................................................................376

View original PDF page 13Open page in PDFOriginal PDF page 13

Flash Memory and EEPROM Commands................................................................. 378 Cdata .........................................................................................................................379 cPtr8, cPtr16, cPtr24, cPtr32.........................................................................................384 Cread .........................................................................................................................387 Cread8, Cread16, Cread24, Cread32 .............................................................................388 Cwrite ........................................................................................................................390 Edata .........................................................................................................................391 Eread .........................................................................................................................396 Ewrite ........................................................................................................................397 Ldata .........................................................................................................................398 LookDown ..................................................................................................................404 LookDownL.................................................................................................................405 LookUp.......................................................................................................................406 LookUpL .....................................................................................................................407 Lread .........................................................................................................................408 Lread8, Lread16, Lread24, Lread32...............................................................................410 Creating Flash Memory Tables using Dim as Code or Dim as Flash ..................................412

View original PDF page 14Open page in PDFOriginal PDF page 14

Compiler Directives................................................................................................ 415 Asm..EndAsm..............................................................................................................416 Config ........................................................................................................................417 Config1,Config2, Config3, Config4 and Config5..................................................................................... 418 Declare.......................................................................................................................419 Oscillator Frequency Declare............................................................................................................... 419 Misc Declares. ................................................................................................................................... 420 Variable Declares. .............................................................................................................................. 422 ADin Declares.................................................................................................................................... 423 Busin - Busout Declares...................................................................................................................... 423 Hbusin - Hbusout Declares.................................................................................................................. 424 USART1 Declares for use with HRsin, HSerin, HRsout and HSerout......................................................... 425 USART2 Declares for use with HRsin2, HSerin2, HRsout2 and HSerout2.................................................. 426 USART3 Declares for use with HRsin3, HSerin3, HRsout3 and HSerout3.................................................. 427 USART4 Declares for use with HRsin4, HSerin4, HRsout4 and HSerout4.................................................. 428 USART5 Declares for use with HRsin5, HSerin5, HRsout5 and HSerout5.................................................. 429 HPWM Declares. ................................................................................................................................ 430 Alphanumeric (Hitachi HD44780) LCD Print Declares............................................................................. 431 Graphic LCD Declares......................................................................................................................... 433 KS0108 Graphic LCD specific Declares. ................................................................................................ 433 Toshiba T6963 Graphic LCD specific Declares. ...................................................................................... 434 Keypad Declare.................................................................................................................................. 436 Rsin - Rsout Declares. ........................................................................................................................ 437 Serin - Serout Declare. ....................................................................................................................... 438 Shin - Shout Declare. ......................................................................................................................... 439 Device........................................................................................................................440 Dim............................................................................................................................441 Creating Flash Memory Tables using Dim as Code or Dim as Flash ......................................................... 446 End ............................................................................................................................449 Include.......................................................................................................................450 Using Include files to tidy up your code................................................................................................ 450 Installed Include files ......................................................................................................................... 451 Proc-EndProc ..............................................................................................................453 Parameters........................................................................................................................................ 454 Parameter as an Alias to a Global Variable or SFR................................................................................. 454 Local Variable and Label Names .......................................................................................................... 456 Procedure Return Variable .................................................................................................................. 457 Return Variable as an Alias to an SFR or Global Variable........................................................................ 459 Set_OSCCAL ...............................................................................................................460 Sub-EndSub................................................................................................................461 Symbol.......................................................................................................................462

View original PDF page 15Open page in PDFOriginal PDF page 15

Interrupt Directives ...............................................................................................463 Context ......................................................................................................................464 On_Hardware_Interrupt...............................................................................................466 Typical format of the interrupt handler with standard 14-bit core devices................................................ 467 Typical format of the interrupt handler with enhanced 14-bit core devices. ............................................. 467 Typical format of the interrupt handler with 18F devices. ...................................................................... 468 On_Low_Interrupt.......................................................................................................469

Using the Optimiser ...............................................................................................471

Using the Preprocessor ..........................................................................................474 Pre-processor Directives...............................................................................................475 Conditional Directives ($ifdef, $ifndef, $if, $endif, $else and $elseif)................................478 SFR bit access using the preprocessor’s built-in meta-macros..........................................480

Proton8 IDE Overview ...........................................................................................481

Positron8 IDE Overview......................................................................................... 483 Menu Bar....................................................................................................................485 Main Toolbar...............................................................................................................486 Edit Toolbar ................................................................................................................487 Code Explorer .............................................................................................................489 Results View ...............................................................................................................492 Editor Options.............................................................................................................493 Highlighter Options......................................................................................................496 Compile and Program Options ......................................................................................498 Installing a Programmer...............................................................................................499 Creating a custom Programmer Entry............................................................................500 IDE Plugins.................................................................................................................502 ASCII Table ................................................................................................................503 Hex View ....................................................................................................................503 Assembler Window ......................................................................................................504 Assembler Main Toolbar...............................................................................................505 Assembler Editor Options .............................................................................................506 Serial Communicator....................................................................................................507 Serial Communicator Main Toolbar................................................................................508

Protected Compiler Words .....................................................................................512

View original PDF page 16Open page in PDFOriginal PDF page 16