![AWC GP3 Скачать руководство пользователя страница 20](http://html.mh-extra.com/html/awc/gp3/gp3_manual_3035292020.webp)
inp(pin) –
Switches a pin to an input and reads the value. The raw command version returns an ASCII "0" or
ASCII "1". The library versions return 0 or 1 as you would expect.
Raw command: 0 0 1 0 P P P 1 where P P P
is the pin number.
tris –
This property sets the direction bits for the 8 digital I/O pins. Each 1 in this byte sets the corresponding
pin to an input (the default). A 0 sets the corresponding pin to an output. You only need to use this property if
you want to manage the pin directions all at the same time (in other words, you don't need to use tris if you are
making calls like high, low, etc.). As an example, if you wanted to set all pins to inputs except for pins 0 and 1
you might write:
io.tris = &HFC ' FC hex = 11111100
Raw commands: To read use 0 1 0 1 0 1 1 0; to set use 0 0 0 0 0 0 1 L where L is the LSB of the value to set.
pins -
This property sets and reads the I/O pins as a single byte. You only need to use this property if you want
to manage the pin data all at the same time (in other words, you don't need to use pins if you are making calls
like high, low, etc.). As an example, if you wanted to set all output pins to 0 except for pins 7 and 1 you might
write:
io.pins = &H7D ' 7D hex = 01111101
Naturally, in this case, the command only affects pins already set as outputs.
Raw commands: To read use 0 1 0 1 0 1 1 1; to set use 0 0 0 0 0 1 0 L where L is the LSB of the value to set.
a2d
– This function accepts an A/D channel number (from 0 to 4) and returns a 16-bit number that contains the
10-bit A/D result. The first byte sent by the GP3 is the top 8 bits of the result.
Raw command: 0 0 1 1 P P P 0
where P P P is the A/D channel number
.
a2dconf
– Configure the A/D for result justification and voltage reference selection. The function call allows
you to set the justify parameter to get results right or left justified (default is left and has value 0; a 1 selects
right justification). The cselect argument can be 0, 1, or 4. The default, 0, uses ground and the supply voltage as
references. A value of 1 selects analog input 3 as the positive reference (the negative reference is still ground in
this case). A value of 4 uses analog input 2 as the negative reference and analog input 3 as the positive
reference. This is useful for expanding the sensitivity of the A/D converter. So using 0V and 3.3V as references
would mean that a count of 1023 would be equal to 3.3V instead of 5V. Note that the minimum reference
voltage allowable is 2.7V. Also note that the clkx2 argument is no longer used, but remains for historical
reasons.
Raw command: 0 0 1 1 0 0 0 1 1 J 0 0 0 R R R where J is the justification bit and RRR is the cselect
argument.
eeprom
– This property allows you to access the 128 bytes of EEPROM available in the GP3. Keep in mind
that EEPROM eventually wears out (about one million write cycles) so EEPROM is best for storing values that
don't change frequently such as serial numbers or configuration parameters. For the library, simply provide the
address as a parameter: eeprom(0)=41. When using raw commands, the address comes from ARG and the data
byte to store is sent after the command (or read, if reading).
Raw command: to set – 0 1 0 1 0 0 0 L; to read – 0
1 0 1 0 0 1 0 where L is the LSB of the data byte.
pwm –
This function has two different capabilities. If you supply a pin number, a duty cycle, and a duration, the
GP3 will produce a PWM wave form with the indicated duty cycle on any of the 8 general I/O pins. This will
force the pin to output status and also tie up the GP3 for the indicated duration. If you supply a pin number of
-1, the GP3 will set its hardware PWM output to the indicated duty cycle and use the duration as a frequency.
The hardware PWM output runs continuously without stopping the GP3. The frequency can be as low as 1225
Hz or as high as 32767Hz. In either case, the duty cycle runs from 0 to 255 (0 to 100%).
Raw command:
software PWM – 0 1 1 0 P P P L; hardware PWM – 0 1 0 1 0 1 0 L where P P P is the pin number and L is the
-17-