Main Page   Modules   File List   Globals  

gp3lib.h File Reference

This is the header included by the GP3 library and all programs that use it. More...

Go to the source code of this file.

Functions

int gp3openport (char *port)
 Open the GP3 serial port.

void gp3closeport ()
 Close the GP3 port.

int gp3write (int byte)
 Write a byte to the GP3.

unsigned int gp3read (void)
 Read a byte from the GP3.

int gp3ready (void)
 Optional function reads the CTS input to determine if the GP3 is ready.

unsigned int gp3readword (void)
 Read a 16-bit word from the GP3.

void gp3setLED (int onoff)
 Set the GP3's onboard LED.

unsigned int gp3a2d (int chan)
 Read an analog channel.

void gp3high (int pin)
 Set a GP3 pin High The pin is automatically made an output.

void gp3low (int pin)
 Set a GP3 pin Low The pin is automatically made an output.

void gp3toggle (int pin)
 Toggle a GP3 output pin (that is set from low to high or high to low) The pin is automatically made an output.

int gp3input (int pin)
 Read a GP3 input pin.

void gp3settris (int tris)
 Set the GP3 direction register.

unsigned int gp3gettris (void)
 Get the GP3 direction register.

void gp3setpins (int byte)
 Set all output pins at once (does not affect input pins).

unsigned int gp3getpins (void)
 Read all input pins at once.

void gp3writeee (int address, int byte)
 Write to EEPROM.

unsigned int gp3readee (int address)
 Read from EEPROM.

void gp3pwm (int chan, int dc, int dfreq)
 Generate PWM.

unsigned int gp3count (int pin, unsigned int ms)
 Count transitions on a digital input.

unsigned int gp3rctime (int pin, int state)
 Read an RC charge/discharge time.

unsigned int gp3pulsein (int pin, int state)
 Measure a single pulse.

void gp3pulseout (int pin, int duration)
 Generate a single pulse.

void gp3freq (int pin, int ms, int freq)
 Generate a psuedo sine wave.

void gp3setcounter (int prescale, int ext)
 Set hardware counter options.

unsigned int gp3counter (void)
 Read hardware counter and reset to 0.

void gp3resetall (void)
 Reset GP3 to power up state.

void gp3reset (void)
 Reset GP3's communicatios state.

void gp3repeat (int count)
 Repeat next command.

void gp3argincr (void)
 Increment the internal argument.

void gp3argdecr (void)
 Decrement the internal argument.

unsigned int gp3check (void)
 Check the GP3 status.


Detailed Description

This is the header included by the GP3 library and all programs that use it.

Author:
Al Williams alw@al-williams.com
Version:
1.1
Date:
17 Feb 2004

Definition in file gp3lib.h.


Function Documentation

unsigned int gp3a2d int    chan
 

Read an analog channel.

Parameters:
chan  Channel number (0-4)
Returns:
A value between 0 (0V) and 1023 (5V)

Definition at line 74 of file gp3lib.c.

References gp3readword(), and gp3write().

Referenced by main().

void gp3argdecr void   
 

Decrement the internal argument.

You should not need to call this function under normal circumstances.

Definition at line 224 of file gp3lib.c.

References gp3write().

void gp3argincr void   
 

Increment the internal argument.

You should not need to call this function under normal circumstances.

Definition at line 218 of file gp3lib.c.

References gp3write().

unsigned int gp3check void   
 

Check the GP3 status.

If the GP3 is ready and connected it will return a version number (currently 0x33).

Returns:
0x33

Definition at line 229 of file gp3lib.c.

References gp3read(), and gp3write().

Referenced by main().

unsigned int gp3count int    pin,
unsigned int    ms
 

Count transitions on a digital input.

The pin automatically becomes an input. This command always counts rising edges. Sampling occurs every 4uS.

Parameters:
pin  The pin to use
ms  The time to sample in milliseconds

Definition at line 146 of file gp3lib.c.

References gp3readword(), and gp3write().

unsigned int gp3counter void   
 

Read hardware counter and reset to 0.

Returns:
16-bit counter value.

Definition at line 195 of file gp3lib.c.

References gp3readword(), and gp3write().

void gp3freq int    pin,
int    ms,
int    freq
 

Generate a psuedo sine wave.

Parameters:
pin  The pin to use (forced to output)
ms  The duration of the sine wave in milliseconds
freq  The frequency in Hz (32767 maximum)

Definition at line 172 of file gp3lib.c.

References gp3write().

unsigned int gp3getpins void   
 

Read all input pins at once.

Returns:
Input state.

Definition at line 119 of file gp3lib.c.

References gp3read(), and gp3write().

unsigned int gp3gettris void   
 

Get the GP3 direction register.

The tris parameter has 8 bits that each correspond to a GP3 digital I/O pin A 0 in a tris bit indicates an output bit and a 1 indicates an input bit

Returns:
The direction bits

Definition at line 107 of file gp3lib.c.

References gp3read(), and gp3write().

void gp3high int    pin
 

Set a GP3 pin High The pin is automatically made an output.

Parameters:
pin  The pin number (0-7)

Definition at line 80 of file gp3lib.c.

References gp3write().

Referenced by main().

int gp3input int    pin
 

Read a GP3 input pin.

The pin is automatically made an input.

Parameters:
pin  The pin number (0-7)
Returns:
0 or 1 (depending on the state of the pin)

Definition at line 95 of file gp3lib.c.

References gp3read(), and gp3write().

void gp3low int    pin
 

Set a GP3 pin Low The pin is automatically made an output.

Parameters:
pin  The pin number (0-7)

Definition at line 85 of file gp3lib.c.

References gp3write().

Referenced by main().

unsigned int gp3pulsein int    pin,
int    state
 

Measure a single pulse.

Parameters:
pin  The pin to use (forced to input)
state  0 to read a low pulse or 1 to read a high pulse
Returns:
The pulse width measured in 2uS units

Definition at line 160 of file gp3lib.c.

References gp3readword(), and gp3write().

void gp3pulseout int    pin,
int    duration
 

Generate a single pulse.

This command inverts the output pin's state for the specified duration.

Parameters:
pin  The pin to use (forced to output)
duration  The pulse width in 2uS units

Definition at line 166 of file gp3lib.c.

References gp3write().

void gp3pwm int    chan,
int    dc,
int    dfreq
 

Generate PWM.

Parameters:
chan  The digital pin to use or -1 for hardware PWM.If a digital pin, the GP3 automatically makes the pin an output.
dc  The duty cycle (0-255, where 256=100%)
dfreq  For hardware PWM, the frequency in Hz; otherwise the duration of the PWM pulses in approximate milliseconds (frequency between 1225 and 32767; duration between 0 and 65535)

Definition at line 139 of file gp3lib.c.

References gp3write().

Referenced by main().

unsigned int gp3rctime int    pin,
int    state
 

Read an RC charge/discharge time.

This command allows you to read the amount of time required for an RC (resistor/capacitor) network to charge or discharge. It is useful for measuring resistive or capacitive sensors like thermistors, pots, etc.

Parameters:
pin  The pin to use (forced to input)
state  The desired state (0 or 1)
Returns:
The time required in 2uS units.

Definition at line 153 of file gp3lib.c.

References gp3readword(), and gp3write().

unsigned int gp3readee int    address
 

Read from EEPROM.

Parameters:
address  EEPROM address (0-127)
Returns:
Byte from EEPROM

Definition at line 132 of file gp3lib.c.

References gp3read(), and gp3write().

unsigned int gp3readword void   
 

Read a 16-bit word from the GP3.

The user may call this function after using gp3repeat and a command that returns 16-bit results.

Definition at line 60 of file gp3lib.c.

References gp3read().

Referenced by gp3a2d(), gp3count(), gp3counter(), gp3pulsein(), and gp3rctime().

void gp3repeat int    count
 

Repeat next command.

Eligible commands include gp3a2d(), gp3input(), gp3rctime(),gp3getpins(), gp3gettris(), and gp3pulsein() If you set the count to 100, for example, and then issued one gp3a2d() command, you'd follow it with 99 gp3readword() calls to fetch the other 99 A/D samples.

Note:
NOTE: For commands that return bytes, call gp3read(); for commands that return words, call gp3readword()
Parameters:
count  The number of times to repeat the next command

Definition at line 211 of file gp3lib.c.

References gp3write().

void gp3reset void   
 

Reset GP3's communicatios state.

Definition at line 206 of file gp3lib.c.

References gp3write().

void gp3resetall void   
 

Reset GP3 to power up state.

Definition at line 201 of file gp3lib.c.

References gp3write().

Referenced by main().

void gp3setcounter int    prescale,
int    ext
 

Set hardware counter options.

Parameters:
prescale  Prescale factor (1, 2, 4, or 8)
ext  Set to 1 for external counter, or 0 for internal 5MHz clock

Definition at line 181 of file gp3lib.c.

References gp3write().

void gp3setLED int    onoff
 

Set the GP3's onboard LED.

Parameters:
onoff  0 for LED off; 1 for LED on

Definition at line 69 of file gp3lib.c.

References gp3write().

Referenced by main().

void gp3setpins int    byte
 

Set all output pins at once (does not affect input pins).

Parameters:
byte  The output byte

Definition at line 113 of file gp3lib.c.

References gp3write().

void gp3settris int    tris
 

Set the GP3 direction register.

The tris parameter has 8 bits that each correspond to a GP3 digital I/O pin A 0 in a tris bit indicates an output bit and a 1 indicates an input bit This overrides previous calls to gp3high, gp3low, gp3input, etc.

Parameters:
tris  The direction bits

Definition at line 101 of file gp3lib.c.

References gp3write().

void gp3toggle int    pin
 

Toggle a GP3 output pin (that is set from low to high or high to low) The pin is automatically made an output.

Parameters:
pin  The pin number (0-7)

Definition at line 90 of file gp3lib.c.

References gp3write().

void gp3writeee int    address,
int    byte
 

Write to EEPROM.

Parameters:
address  EEPROM address (0-127)
byte  Byte to write to EEPROM

Definition at line 125 of file gp3lib.c.

References gp3write().


Generated on Wed Feb 18 00:34:20 2004 for GP3LIB by doxygen1.2.18