Fox (LP3500)
User's Manual
PREV INDEX NEXT


4. Software

Dynamic C is an integrated development system for writing embedded software. It runs on an IBM-compatible PC and is designed for use with single-board computers and other devices based on the Rabbit microprocessor.

Chapter 4 provides the libraries, function calls, and sample programs related to the LP3500.

You have a choice of doing your software development in the flash memory or in the static RAM included on the LP3500. The flash memory and SRAM options are selected with the Options > Project Options > Compiler menu.

The advantage of working in RAM is to save wear on the flash memory, which is limited to about 100,000 write cycles. The disadvantage is that the code and data might not both fit in RAM.

NOTE An application can be developed in RAM, but cannot run standalone from RAM after the programming cable is disconnected. All standalone applications can only run from flash memory.
NOTE Do not depend on the flash memory sector size or type. Due to the volatility of the flash memory market, the LP3500 and Dynamic C were designed to accommodate flash devices with various sector sizes.

Developing software with Dynamic C is simple. Users can write, compile, and test C and assembly code without leaving the Dynamic C development environment. Debugging occurs while the application runs on the target. Alternatively, users can compile a program to an image file for later loading. Dynamic C runs on PCs under Windows 2000/NT and later. Rabbit's Technical Note TN257, Running Dynamic C® With Windows Vista®, in the online documentation set provides additional information about using Windows Vista® with versions of Dynamic C prior to v. 9.60.

Programs can be downloaded at baud rates of up to 460,800 bps after the program compiles.

Dynamic C has a number of standard features.

4.1 Upgrading Dynamic C

4.1.1 Patches and Bug Fixes

Dynamic C patches that focus on bug fixes are available from time to time. Check the Web site www.rabbit.com/support/ for the latest patches, workarounds, and bug fixes.

The default installation of a patch or bug fix is to install the file in a directory (folder) different from that of the original Dynamic C installation. Rabbit recommends using a different directory so that you can verify the operation of the patch without overwriting the existing Dynamic C installation. If you have made any changes to the BIOS or to libraries, or if you have programs in the old directory (folder), make these same changes to the BIOS or libraries in the new directory containing the patch. Do not simply copy over an entire file since you may overwrite a bug fix; of course, you may copy over any programs you have written. Once you are sure the new patch works entirely to your satisfaction, you may retire the existing installation, but keep it available to handle legacy applications.

4.1.2 Extras

Dynamic C installations are designed for use with the board they are included with, and are included at no charge as part of our low-cost kits.

Starting with Dynamic C version 9.60, Dynamic C includes the popular µC/OS-II real-time operating system, point-to-point protocol (PPP), FAT file system, RabbitWeb, and other select libraries. Rabbit also offers for purchase the Rabbit Embedded Security Pack featuring the Secure Sockets Layer (SSL) and a specific Advanced Encryption Standard (AES) library.

In addition to the Web-based technical support included at no extra charge, a one-year telephone-based technical support subscription is also available for purchase.

Visit our Web site at www.rabbit.com for further information and complete documentation.

4.2 Sample Programs

Sample programs are provided in the Dynamic C Samples folder. The sample program PONG.C demonstrates the output to the STDIO window.

The various directories in the Samples folder contain specific sample programs that illustrate the use of the corresponding Dynamic C libraries.

The LP3500 folder provides sample programs specific to the LP3500. Each sample program has comments that describe the purpose and function of the program. Follow the instructions at the beginning of the sample program.

To run a sample program, open it with the File menu (if it is not still open), compile it using the Compile menu, and then run it by selecting Run in the Run menu. The LP3500 must be in the Program mode (see Section 3.9, "Serial Programming Cable") and must be connected to a PC using the programming cable as described in Section 2.1, "LP3500 Connections."

Appendix F, "Running a Sample Program," takes you through the steps of running one of the sample programs.

4.2.1 Power Modes

The following sample program is found in the POWER subdirectory in SAMPLES\LP3500.

4.2.2 Digital I/O

The following sample programs are found in the IO subdirectory in SAMPLES\LP3500.

4.2.3 Serial Communication

The following sample programs are found in the RS232 subdirectory in SAMPLES\LP3500.

The following sample programs are found in the RS485 subdirectory in SAMPLES\LP3500.

4.2.4 A/D Converter Inputs

The following sample programs are found in the ADC subdirectory in SAMPLES\LP3500.

4.2.5 PWM Outputs

The following sample program is found in the IO subdirectory in SAMPLES\LP3500.

4.2.6 Relay Output

The following sample program is found in the RELAY subdirectory in SAMPLES\LP3500.

4.2.7 Vcc Monitoring

The following sample program is found in the POWER subdirectory in SAMPLES\LP3500.

4.2.8 LP3500 Calibration

The following sample programs are found in the ADC subdirectory in SAMPLES\LP3500.

NOTE This sample program will overwrite the calibration constants set at the factory.

NOTE This sample program will overwrite the calibration constants set at the factory.

NOTE This sample program will overwrite the calibration constants set at the factory.

NOTE This sample program will overwrite the calibration constants set at the factory.

4.2.9 LCD/Keypad Module Sample Programs

Sample programs for the LCD/keypad module are described in Section C.8.

4.3 LP3500 Libraries

One library directory provides the function calls that are used to develop applications for the LP3500.

The LCD/keypad module functions are described in Section C.7. Other generic functions applicable to all devices based on the Rabbit 3000 microprocessor are described in the Dynamic C Function Reference Manual.

4.4 LP3500 Function Calls

4.4.1 LP3500 Power Modes

int devPowerSet(int devices, int state);


Sets individual devices to low-power or fully active states in the order listed below.
PARAMETERS
devices is a list of the following macros, which are OR'ed together, that will be affected by the state parameter, e.g., RS232DEV|ADCDEV.
RS232DEV--RS-232 devices
RS485DEV--RS-485 devices
ADCDEV--ADS7870 A/D converter devices
DISPDEV--LCD/keypad module
ALLDEVICES--all devices
state
0 = shuts or powers down listed devices
1 = activates listed devices

Macro

Description state = 0

state after Board Initialization

RS232DEV
Receivers and transmitters are disabled, RxE remains active
1
RS485DEV
Transmitter is disabled
0
ADCDEV
ADS7870 internal oscillator is turned off
0
DISPDEV
LCD/keypad module is turned off.
0
ALLDEVICES
All devices are disabled as described above
--

Table E-1 provides further information about the power consumption associated with each section.
RETURN VALUE
0 if valid parameter
-1 otherwise
SEE ALSO

int powerMode(int mode);


Sets the LP3500 operating power.
PARAMETERS
mode is the operating mode based on the following macros.

Mode

Description

Typical Current Consumption

Debug Capable?

1
CCLK = PCLK = MainOsc = 7.3728 MHz
5-16 mA
Yes
2
CCLK = PCLK = MainOsc/2 = 3.6864 MHz
3
CCLK = PCLK = MainOsc/4 = 1.8423 MHz
4
CCLK = PCLK = MainOsc/6 = 1.2288 MHz
No
5
CCLK = PCLK = MainOsc/8 = 0.9216 MHz
6
CCLK = PCLK = 32.768 kHz
2 mA
7
CCLK = PCLK = 32.768 kHz/2 = 16.384 kHz
8
CCLK = PCLK = 32.768 kHz/4 = 8.192 kHz
9
CCLK = PCLK = 32.768 kHz/8 = 4.096 kHz
10
CCLK = PCLK = 32.768 kHz/16 = 2.048 kHz

Table 2 provides more specific information on the LP3500's capabilities associated with these and other software-defined modes.
NOTE When using modes 6-10, be sure to call hitwd() explicitly since periodic interrupts, which incorporate a virtual watchdog, are disabled in these modes.

RETURN VALUE
0 if valid parameter
-1 if invalid parameter
SEE ALSO

void serCommAlert(int lowpowermode, int maxpowermode, int powersource, unsigned long timeout);


Use this function to poll Serial Port E for any activity or until a timeout occurs. The function call forces the LP3500 to enter the low-power mode using the battery for polling. Upon expiration of the timeout or the receipt of a serial byte, this function will enable the normal power mode and exit.
Use devPowerSet(ALLDEVICES, int state) before and after this function call to deactivate and activate all devices to operate at less power.
PARAMETERS
lowpowermode is the low-power mode setting to enter, usually 10 (see powerMode())
maxpowermode is the maximum operating power mode setting to enter, usually 1 (see powerMode() )
powersource
1 = battery
2 = raw DC power
timeout is the timeout in seconds if no activity is detected on the RxE receiver line. Enter 0 for no timeout
SEE ALSO

void timedAlert(int lowpowermode, int maxpowermode, int powersource, unsigned long timeout)


Use this function to poll the real-time clock until a timeout occurs. The function call forces the LP3500 to enter the low-power mode, disables the normal power source, and may enable the external battery for polling. Upon expiration of the timeout this function will enable the normal power mode and exit. If the normal power source is not available, the LP3500 will not be able to resume operation at the maximum- power mode, and may reset.
Use devPowerSet(ALLDEVICES, int state) before and after this function call to deactivate and activate all devices to operate at less power.
PARAMETERS
lowpowermode is the low-power mode setting to enter, usually 10 (see powerMode())
maxpowermode is the maximum operating power mode setting to enter, usually 1 (see powerMode() )
powersource
1 = battery
2 = raw DC power
timeout is the timeout in seconds if an input is not received.
SEE ALSO

void digInAlert(int channel, int value, int lowpowermode, int maxpowermode, int powersource, unsigned long timeout)


Use this function to poll a selected digital input until a timeout occurs. The function call forces the LP3500 to enter the low-power mode using the battery for polling. Upon activation of the channel or expiration of the timeout, this function will enable the normal power mode and exit.
Use devPowerSet(ALLDEVICES, int state) before and after this function call to deactivate and activate all devices to operate at less power.
PARAMETERS
channel is the digital input channel (IN00- IN15) to poll
value is the input value of 0 or 1 to receive
lowpowermode is the low-power mode setting to enter, usually 10 (see powerMode())
maxpowermode is the maximum operating power mode setting to enter, usually 1 (see powerMode() )
powersource
1 = battery
2 = raw DC power
timeout is the timeout in seconds if an input is not received. Enter 0 for no timeout.
SEE ALSO

int rdPowerState(void);


Determines if the LP3500 is running under battery power or a raw DC power source.
RETURN VALUE
0 if on raw DC power source
1 if on battery power
SEE ALSO

int setPowerSource(int state);


Turns the linear regulator "off" or "on."
PARAMETER
0 for normal power source
1 for battery
RETURN VALUE
0 if successful
-1 if raw DC power source is not available
-2 if battery is not available
SEE ALSO

4.4.2 Board Initialization

void brdInit (void);


Call this function at the beginning of your program. This function initializes the system I/O ports and loads all the A/D converter and D/A converter calibration constants from flash memory into SRAM for use by your program. If the LCD/keypad module is installed, this function will turn off LED DS1 to indicate that the initialization was successful.
Summary of Initialization

4.4.3 Digital I/O

void digOut(int channel, int value);


Sets the state of a digital output (OUT0-OUT9).
Remember to call brdInit before executing this function.
A runtime error will occur for the following conditions:
1. channel or value out of range.
2. brdInit was not executed before executing digOut.
PARAMETERS
channel is the output channel number (0-9).
value is the output value (0 or 1).
SEE ALSO

void digBankOut(int bank, int value);


Writes the state of a block of designated digital output channels. The first bank consists of OUT0- OUT7, the second bank consists of OUT8-OUT9.
A run-time error will occur for the following conditions:
1. channel or value out of range.
2. brdInit was not executed before executing digOut.
PARAMETER
bank is 0 for OUT0-OUT7, 1 for OUT8-OUT9.
value is an 8-bit output value, where each bit corresponds to one channel. OUT0 and OUT8 are the least significant bit 0.
RETURN VALUE
None.
SEE ALSO

int digIn(int channel);


Reads the state of an input channel (IN00-IN15).
A run-time error will occur for the following conditions:
1. channel out of range.
2. brdInit was not executed before executing digIn.
PARAMETER
channel is the input channel number (0-15)
RETURN VALUE
The logic state of the input (0 or 1).
SEE ALSO

void digBankIn(int bank);


Reads the state of a block of designated digital input channels. The first bank consists of IN0-IN07, the second bank consists of IN08-IN15.
A run-time error will occur for the following conditions:
1. bank out of range.
2. brdInit was not executed before executing digIn.
PARAMETER
bank is 0 for IN00-IN07, 1 for IN08-IN15.
RETURN VALUE
An input value in the lower byte, where each bit corresponds to one channel. IN00 and IN08 are in the bit 0 place.
SEE ALSO

4.4.4 Serial Communication

Library files included with Dynamic C provide a full range of serial communications support. The LIB\Rabbit3000\RS232.LIB library provides a set of circular-buffer-based serial functions. The LIB\Rabbit3000\PACKET.LIB library provides packet-based serial functions where packets can be delimited by the 9th bit, by transmission gaps, or with user-defined special characters. Both libraries provide blocking functions, which do not return until they are finished transmitting or receiving, and nonblocking functions, which must be called repeatedly until they are finished. For more information, see the Dynamic C User's Manual and Rabbit's Technical Note TN213, Rabbit 2000 Serial Port Software.

Use the following function calls with the LP3500.

int serMode(int mode);


User interface to set up LP3500 serial communication lines. Call this function after serXOpen().
Whether you are opening one or multiple serial ports, this function must be executed after executing the last serXOpen function AND before you start using any of the serial ports. This function is non-reentrant.
If Mode 1 is selected, CTS/RTS flow control is exercised using the serBflowcontrolOn and serBflowcontrolOff functions from the RS232.LIB library.
PARAMETER
mode is the defined serial port configuration.

Mode

Serial Port

B

C

E

F

0
RS-232, 3-wire
RS-232, 3-wire
RS-232, 3-wire
RS-485
1
RS-232, 5-wire
CTS/RTS
RS-232, 3-wire
RS-485

RETURN VALUE
0 if valid mode, 1 if not.
SEE ALSO

void ser485Tx(void);


Enables the RS-485 transmitter. Transmitted data get echo'ed back into the receive data buffer. These echo'ed data could be used to know when to disable the transmitter by using one of the following methods:
Byte mode--disable the transmitter after the same byte that is transmitted is detected in the receive data buffer.
Block data mode--disable the transmitter after the same number of bytes transmitted is detected in the receive data buffer.
serMode() must be executed before running this function.
SEE ALSO

void ser485Rx(void);


Disables the RS-485 transmitter. This puts the LP3500 in listen mode, which allows it to receive data from the RS-485 interface. serMode() must be executed before running this function.
SEE ALSO

NOTE The RS-485 transceiver used on the LP3500 is only capable of supporting a maximum baud rate of 64,000 bits/s. The baud rate is set by the Dynamic C _485BAUD macro. For example, add the following line on the Defines tab in the Dynamic C Options > Project Options to set a baud rate of 57,600 bits/s, then click OK.

4.4.5 A/D Converter Inputs

The functions in this section apply only to the LP3500 model.

unsigned int anaInConfig(unsigned int instructionbyte, unsigned int cmd, long baud);


Use this function to configure the ADS7870 A/D converter. This function will address the ADS7870 in Register Mode only, and will report an error if you try to use it in Direct Mode. Refer to ADS7870 specification for proper addressing and commands.

ADS7870 Signal

ADS7870 State

LP3500 Function/State

LN0
Input
AIN0
LN1
Input
AIN1
LN2
Input
AIN2
LN3
Input
AIN3
LN4
Input
AIN4
LN5
Input
AIN5
LN6
Input
AIN6
LN7
Input
AIN7
/RESET
Input
Board reset device
RISE/FALL
Input
Tied up for SCLK active on rising edge
PIO_0
Input
Pulled down unless driven by serial interface connection
PIO_1
Input
Pulled down unless driven by serial interface connection
PIO_2
Input
Pulled down unless driven by serial interface connection
PIO_3
Input
Pulled up unless driven by Vcc monitor
CONVERT
Input
Pulled down, not used
BUSY
Output
PF1 pulled down; 1 state converter is busy
CCLKCNTRL
Input
Tied down; 0 state sets CCLK as input
CCLK
Input
Tied down; external conversion clock
SCLK
Input
PF0; serial data transfer clock
SDI
Input
PC0; 3-wire mode for serial data input
SDO
Output
PC1; serial data output /CS driven
/CS
Input
PF3 pulled up; active-low enables serial interface
BUFIN
Input
Tied down; reference buffer amplifier

PARAMETERS
instructionbyte will initiate a read or write operation at 8 or 16 bits on the designated register address, for example:
cmd is the command data that configure the registers addressed by the instruction byte. Enter 0 if performing a read operation.
baud is the serial clock transfer rate of 9600 to 57,600 bps. baud must be set on the first call to this function. Enter 0 in this parameter thereafter.
RETURN VALUE
0 on write operations, data value on read operations.
SEE ALSO

unsigned int anaInDriver(unsigned int cmd, unsigned int len);


Reads the voltage of an analog input channel by serial- clocking an 8-bit command to the ADS7870 device by its Direct Mode method. The conversion begins as soon as the last data bit is transferred.
An exception error will occur if Direct Mode bit D7 is not set.
PARAMETER
cmd contains a gain code and a channel code as follows.
D7--1; D6-D4--Gain Code; D3-D0--Channel Code
Use the following calculation and the tables below to determine cmd:

Gain Code

Multiplier

Voltage Range

0
1
0-20 V
1
2
0-10 V
2
4
0-5 V
3
5
0-4 V
4
8
0-2.5 V
5
10
0-2 V
6
16
0-1.25 V
7
20
0-1 V

Channel Code

Differential Input Lines

Channel Code

Single-Ended Input Lines1

4-20 mA Lines

0
+AIN0 -AIN1
8
AIN0
AIN0
1
+AIN2 -AIN3
9
AIN1
AIN1
2
+AIN4 -AIN5
10
AIN2
AIN2
3
+AIN6 -AIN7
11
AIN3
AIN3
4
Reserved
12
AIN4
Reserved
5
Reserved
13
AIN5
Reserved
6
Reserved
14
AIN6
Reserved
7
Reserved
15
AIN7
Reserved
1 Negative input is ground.


len, the output bit length, is always 12 bits.
RETURN VALUE
A value corresponding to the voltage on the analog input channel, which will be:
0-2047 for 11-bit A/D conversions (bit 12 for sign)
-1 for overflow
SEE ALSO

int anaIn(unsigned int channel, int opmode, int gaincode);


Reads the value of an analog input channel using the direct method of addressing the ADS7870 A/D converter.
PARAMETERS
channel is the analog input channel number (0 to 7) corresponding to AIN0-AIN7
opmode is the mode of operation:
SINGLE--single-ended input line
DIFF--differential input line
mAMP--milliamp input line

channel

SINGLE

DIFF

mAMP

0
+AIN0
+AIN0 -AIN1
+AIN0
1
+AIN1
--
+AIN1
2
+AIN2
+AIN2 -AIN3
+AIN2
3
+AIN3
--
+AIN3
4
+AIN4
+AIN4 -AIN5
--
5
+AIN5
--
--
6
+AIN6
+AIN6 -AIN7
--
7
+AIN7
--
--

gaincode is the gain code of 0 to 7:

Gain Code

Voltage Range

0
0-20 V
1
0-10 V
2
0-5 V
3
0-4 V
4
0-2.5 V
5
0-2 V
6
0-1.25 V
7
0-1 V

RETURN VALUE
A value corresponding to the voltage on the analog input channel, which will be:
0-2047 for 11-bit A/D conversions (signed 12th bit)
ADOVERFLOW (defined macro = -4096) if overflow or out of range
SEE ALSO

int anaInCalib(int channel, int opmode, int gaincode, int value1, float volts1, int value2, float volts2);


Calibrates the response of the A/D converter channel as a linear function using the two conversion points provided. Four values are calculated and placed into global table _adcCalib to be stored later store into simulated EEPROM using the function anaInEEWr(). Each channel will have the following information:
a linear constant,
a voltage offset,
a calculation gain code used to calculate calibrations, and
a user gain code to set voltage range (defaults to the calculation gain code).

NOTE Vcc monitoring is disabled when anaInCalib is running.

PARAMETERS
channel is the analog input channel number (0 to 7) corresponding to AIN0-AIN7
opmode is the mode of operation:
SINGLE--single-ended input line
DIFF--differential input line
mAMP--milliamp input line

channel

SINGLE

DIFF

mAMP

0
+AIN0
+AIN0 -AIN1
+AIN0
1
+AIN1
--
+AIN1
2
+AIN2
+AIN2 -AIN3
+AIN2
3
+AIN3
--
+AIN3
4
+AIN4
+AIN4 -AIN5
--
5
+AIN5
--
--
6
+AIN6
+AIN6 -AIN7
--
7
+AIN7
--
--

gaincode is the gain code of 0 to 7:

Gain Code

Voltage Range

0
0-20 V
1
0-10 V
2
0-5 V
3
0-4 V
4
0-2.5 V
5
0-2 V
6
0-1.25 V
7
0-1 V

value1 is the first A/D converter channel value (0-2047).
volts1 is the voltage or current corresponding to the first A/D converter channel value (0 to +10 V or 4 to 20 mA).
value2 is the second A/D converter channel value (0-2047).
volts2 is the voltage or current corresponding to the first A/D converter channel value (0 to +10 V or 4 to 20 mA).
RETURN VALUE
0 if successful.
-1 if not able to make calibration constants.
SEE ALSO

float anaInVolts(unsigned int channel, unsigned int gaincode);


Reads the state of a single-ended analog input channel and uses the previously set calibration constants to convert it to volts.
PARAMETER
channel is the channel number (0-7):

Channel Code

Single-Ended Input Lines1

0
+AIN0
1
+AIN1
2
+AIN2
3
+AIN3
4
+AIN4
5
+AIN5
6
+AIN6
7
+AIN7
1 Negative input is ground.


gaincode is the gain code of 0 to 7.

Gain Code

Voltage Range

0
0-20 V
1
0-10 V
2
0-5 V
3
0-4 V
4
0-2.5 V
5
0-2 V
6
0-1.25 V
7
0-1 V
RETURN VALUE
A voltage value corresponding to the voltage on the analog input channel.
ADOVERFLOW (defined macro = -4096) if overflow or out of range.
SEE ALSO

float anaInmAmps(unsigned int channel);


Reads the state of an analog input channel and uses the previously set calibration constants to convert it to current.
PARAMETER
channel is 0-3:

Channel

4-20 mA Input Lines1