PicBasic Pro Compiler Ver. 2.43 NEW.TXT Copyright 2002 microEngineering Labs, Inc. This software and accompanying documentation is copyright (c) microEngineering Labs, Inc. and may only be used by owners of the microEngineering Labs, Inc. PicBasic Pro Compiler. Please contact microEngineering Labs, Inc. to license this software. Contact information is listed at the end of this file. Version 2.4 of the PicBasic Pro Compiler adds several new commands and limited support for the 12-bit code PICmicro microcontrollers. The new commands include support for Dallas one-wire devices, low-speed USB, a special purpose 31-bit x 15-bit divide function, hardware PWM and Select Case statements. New Defines The compiler normally inserts clrwdt instructions throughout the program to keep the Watchdog Timer from timing out, if enabled. A new Define tells the compiler not to insert these clrwdt instructions: Define NO_CLRWDT 1 Adding support for the PIC16C745 and 765 low-speed USB devices meant raising the maximum oscillator speed to 24MHz. Therefore, a new oscillator Define is available for these devices: Define OSC 24 On devices with 2 hardware serial ports, Hserin and Hserout will only use the first port. The second port may be set up and read by accessing the registers directly. Or a Define may be added to tell Hserin and Hserout to use the second serial port instead of the first: Define HSER_PORT 2 A new Define has been added to set a maximum count for Pulsin and Rctime before it stops waiting for a pulse or the end of a pulse: Define PULSIN_MAX 1000 The new HPWM instruction has a few new Defines to go along with it. The first specifies which pin is the CCP pin for devices that have alternate places for the pin, such as the PIC18C452: Define CCP1_REG PORTC Define CCP1_BIT 2 Define CCP2_REG PORTC Define CCP2_BIT 1 The following specify which timer, 1 or 2, to use with PWM2 and PWM3 for the PIC17C7xx devices. The default is timer 1 if no Define is specified. Define HPWM2_TMR 1 Define HPWM3_TMR 1 New Div32 Function PBPs multiply (*) function operates as a 16-bit x 16-bit multiply yielding a 32-bit result. However, since the compiler only supports a maximum variable size of 16 bits, access to the result had to happen in 2 steps: c = b * a returns the lower 16 bits of the multiply while d = b ** a returns the upper 16 bits. There was no way to access the 32-bit result as a unit. In many cases it is desirable to be able to divide the entire 32-bit result of the multiply by a 16-bit number for averaging or scaling. A new function has been added for this purpose: Div32. Div32 is actually limited to dividing a 31-bit unsigned integer (max 2147483647) by a 15-bit unsigned integer (max 32767). This should suffice in most circumstances. As the compiler only allows a maximum variable size of 16 bits, Div32 relies that a multiply was just performed and that the internal compiler variables still contain the 32-bit result of the multiply. No other operation may occur between the multiply and the Div32 or the internal variables may be altered, destroying the 32-bit multiplication result. This means, among other things, that On Interrupt must be Disabled from before the multiply until after the Div32. If On Interrupt is not used, there is no need to add Disable to the program. Interrupts in assembler should have no effect on the internal variables so they may be used without regard to Div32. The following code fragment shows the operation of Div32: a Var Word b Var Word c Var Word dummy Var Word b = 500 c = 1000 Disable ' Necessary if On Interrupt used dummy = b * c ' Could also use ** or */ a = Div32 100 Enable ' Necessary if On Interrupt used This program assigns b the value 500 and c the value 1000. When multiplied together, the result would be 500000. This number exceeds the 16-bit word size of a variable (65535). So the dummy variable contains only the lower 16 bits of the result. In any case, it is not used by the Div32 function. Div32 uses variables internal to the compiler as the operands. In this example, Div32 divides the 32-bit result of the multiplication b * c by 100 and stores the result of this division, 5000, in the word-sized variable a. New Erasecode Command Erasecode Block Some flash PICmicro MCUs, like the PIC16F81x and PIC18Fxxx series, require a portion of the code space to be erased before it can be rewritten with WRITECODE. On these devices, an erase is performed a block at a time. An erase block may be 32 words (64 bytes) or another size, depending on the device. See the Microchip data sheet for information on the size of the erase block for the particular PICmicro MCU you are using. The first location of the block to be erased should be specified by Block. Block is a byte address, rather than a word address, for PIC18Fxxx devices. Be careful not to specify a Block that contains program code. Flash program writes must be enabled in the configuration for the PICmicro MCU at device programming time for ERASECODE to be able to erase. Using this instruction on devices that do not support block erase will cause a compilation error. Erasecode $100 ' Erase code block starting at location $100 New Hardware PWM Command A new hardware PWM command sets up the PWM hardware available on some PICmicro MCUs. It can run continuously in the background while the program is doing other things. Hpwm Channel, Dutycycle, Frequency Channel specifies which hardware PWM channel to use. Some devices have 1, 2 or 3 PWM channels. On devices with 2 channels, the Frequency must be the same on both channels. Dutycycle specifies the on/off (high/low) ratio of the signal. It ranges from 0 to 255, where 0 is off (low all the time) and 255 is on (high) all the time. A value of 127 gives a 50% duty cycle (square wave). Frequency is the desired frequency of the PWM signal. Not all frequencies are available at all oscillator settings. The lowest frequency at 4MHz is 245Hz. The highest frequency at any oscillator speed is 32767Hz. See the Microchip data sheet for the device for more information on the PWM hardware. Hpwm 1,127,1000 ' Send a 50% duty cycle PWM signal at 1kHz Hpwm 1,64,200 ' Send a 25% duty cycle PWM signal at 2kHz New Hardware Serial 2 Commands New hardware serial commands Hserin2 and Hserout2 have been added for access to the second hardware serial ports on some PICmicro MCUs such as the PIC17C7xx and PIC18Fxx20. Hserin2 {ParityLabel,}{Timeout, Label,}[Item{,Item...}] Hserout2 [Item{,Item...}] These new commands work the same as Hserin and Hserout on the first hardware serial port. There are new Defines that go with Hserin2 and Hserout2: Define HSER2_RCSTA 90h Define HSER2_TXSTA 20h Define HSER2_BAUD 2400 Define HSER2_SPBRG 25 Define HSER2_EVEN 1 Define HSER2_ODD 1 New One-Wire Commands Two new commands have been added to simplify access to Dallas Semiconductor one-wire devices: OWin and OWOut. Each command is discussed below. OWIn Pin, Mode, [Item{, Item...}] OWIn optionally sends a reset pulse to the one-wire device and then reads one or more bits or bytes of data from it, optionally ending with another reset pulse. Pin is a constant or variable that specifies which I/O pin the one-wire device is connected to. Mode specifies whether a reset is sent before and/or after the operation and the size of the data items, either bit or byte. Mode bit number Effect 0 1 = send reset pulse before data 1 1 = send reset pulse after data 2 0 = byte-sized data, 1 = bit-sized data Some Mode examples would be: Mode of 0 means no reset and byte-sized data, Mode of 1 means reset before data and byte-sized data, Mode of 4 means no reset and bit-sized data. Item is one or more variables or modifiers separated by commas. The allowable modifiers are Str for reading data into a byte array variable and Skip for skipping a number of input values. OWIn PORTC.0, 0, [temperature\2, Skip 4, count_remain, count_per_c] This statement would receive bytes from a one-wire device on PORTC pin 0 with no reset pulse being sent. It would receive 2 bytes and put them into the byte array temperature, skip the next 4 bytes and then read the final 2 bytes into separate variables. OWOut Pin, Mode, [Item{, Item...}] OWOut optionally sends a reset pulse to the one-wire device and then writes one or more bits or bytes of data to it, optionally ending with another reset pulse. Pin is a constant or variable that specifies which I/O pin the one-wire device is connected to. Mode specifies whether a reset is sent before and/or after the operation and the size of the data items, either bit or byte. Mode bit number Effect 0 1 = send reset pulse before data 1 1 = send reset pulse after data 2 0 = byte-sized data, 1 = bit-sized data Some Mode examples would be: Mode of 0 means no reset and byte-sized data, Mode of 1 means reset before data and byte-sized data, Mode of 4 means no reset and bit-sized data. Item is one or more constants, variables or modifiers separated by commas. The allowable modifiers are Str for sending data from a byte array variable and Rep for sending a number of repeated values. OWOut PORTC.0, 1, [$cc, $be] This statement would send a reset pulse to a one-wire device on PORTC pin 0 followed by the bytes $cc and $be. Peek and Poke Command Changes Peek and Poke have been changed...
fred1144