Programme d'utilisation servomotors MX12 V1

Committer:
R66Y
Date:
Fri May 19 14:32:14 2017 +0000
Revision:
0:80df663dd15e
programme pour utiliser les servomoteurs MX12.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
R66Y 0:80df663dd15e 1 /* mbed Microcontroller Library - SerialHalfDuplex
R66Y 0:80df663dd15e 2 * Copyright (c) 2010-2011 ARM Limited. All rights reserved.
R66Y 0:80df663dd15e 3 */
R66Y 0:80df663dd15e 4
R66Y 0:80df663dd15e 5 #ifndef MBED_SERIALHALFDUPLEX_H
R66Y 0:80df663dd15e 6 #define MBED_SERIALHALFDUPLEX_H
R66Y 0:80df663dd15e 7
R66Y 0:80df663dd15e 8 #include "device.h"
R66Y 0:80df663dd15e 9
R66Y 0:80df663dd15e 10 #if DEVICE_SERIAL
R66Y 0:80df663dd15e 11
R66Y 0:80df663dd15e 12 #include "Serial.h"
R66Y 0:80df663dd15e 13 #include "PinNames.h"
R66Y 0:80df663dd15e 14 #include "PeripheralNames.h"
R66Y 0:80df663dd15e 15
R66Y 0:80df663dd15e 16 namespace mbed {
R66Y 0:80df663dd15e 17
R66Y 0:80df663dd15e 18 /* Class: SerialHalfDuplex
R66Y 0:80df663dd15e 19 * A serial port (UART) for communication with other devices using
R66Y 0:80df663dd15e 20 * Half-Duplex, allowing transmit and receive on a single
R66Y 0:80df663dd15e 21 * shared transmit and receive line. Only one end should be transmitting
R66Y 0:80df663dd15e 22 * at a time.
R66Y 0:80df663dd15e 23 *
R66Y 0:80df663dd15e 24 * Both the tx and rx pin should be defined, and wired together.
R66Y 0:80df663dd15e 25 * This is in addition to them being wired to the other serial
R66Y 0:80df663dd15e 26 * device to allow both read and write functions to operate.
R66Y 0:80df663dd15e 27 *
R66Y 0:80df663dd15e 28 * Example:
R66Y 0:80df663dd15e 29 * > // Send a byte to a second HalfDuplex device, and read the response
R66Y 0:80df663dd15e 30 * >
R66Y 0:80df663dd15e 31 * > #include "mbed.h"
R66Y 0:80df663dd15e 32 * >
R66Y 0:80df663dd15e 33 * > // p9 and p10 should be wired together to form "a"
R66Y 0:80df663dd15e 34 * > // p28 and p27 should be wired together to form "b"
R66Y 0:80df663dd15e 35 * > // p9/p10 should be wired to p28/p27 as the Half Duplex connection
R66Y 0:80df663dd15e 36 * >
R66Y 0:80df663dd15e 37 * > SerialHalfDuplex a(p9, p10);
R66Y 0:80df663dd15e 38 * > SerialHalfDuplex b(p28, p27);
R66Y 0:80df663dd15e 39 * >
R66Y 0:80df663dd15e 40 * > void b_rx() { // second device response
R66Y 0:80df663dd15e 41 * > b.putc(b.getc() + 4);
R66Y 0:80df663dd15e 42 * > }
R66Y 0:80df663dd15e 43 * >
R66Y 0:80df663dd15e 44 * > int main() {
R66Y 0:80df663dd15e 45 * > b.attach(&b_rx);
R66Y 0:80df663dd15e 46 * > for(int c = 'A'; c < 'Z'; c++) {
R66Y 0:80df663dd15e 47 * > a.putc(c);
R66Y 0:80df663dd15e 48 * > printf("sent [%c]\n", c);
R66Y 0:80df663dd15e 49 * > wait(0.5); // b should respond
R66Y 0:80df663dd15e 50 * > if(a.readable()) {
R66Y 0:80df663dd15e 51 * > printf("received [%c]\n", a.getc());
R66Y 0:80df663dd15e 52 * > }
R66Y 0:80df663dd15e 53 * > }
R66Y 0:80df663dd15e 54 * > }
R66Y 0:80df663dd15e 55 *
R66Y 0:80df663dd15e 56 * For Simplex and Full-Duplex Serial communication, see <Serial>
R66Y 0:80df663dd15e 57 */
R66Y 0:80df663dd15e 58 class SerialHalfDuplex : public Serial {
R66Y 0:80df663dd15e 59
R66Y 0:80df663dd15e 60 public:
R66Y 0:80df663dd15e 61 /* Constructor: SerialHalfDuplex
R66Y 0:80df663dd15e 62 * Create a half-duplex serial port, connected to the specified transmit
R66Y 0:80df663dd15e 63 * and receive pins.
R66Y 0:80df663dd15e 64 *
R66Y 0:80df663dd15e 65 * These pins should be wired together, as well as to the target device
R66Y 0:80df663dd15e 66 *
R66Y 0:80df663dd15e 67 * Variables:
R66Y 0:80df663dd15e 68 * tx - Transmit pin
R66Y 0:80df663dd15e 69 * rx - Receive pin
R66Y 0:80df663dd15e 70 */
R66Y 0:80df663dd15e 71 SerialHalfDuplex(PinName tx, PinName rx, const char *name = NULL);
R66Y 0:80df663dd15e 72
R66Y 0:80df663dd15e 73 #if 0 // Inherited from Serial class, for documentation
R66Y 0:80df663dd15e 74 /* Function: baud
R66Y 0:80df663dd15e 75 * Set the baud rate of the serial port
R66Y 0:80df663dd15e 76 *
R66Y 0:80df663dd15e 77 * Variables:
R66Y 0:80df663dd15e 78 * baudrate - The baudrate of the serial port (default = 9600).
R66Y 0:80df663dd15e 79 */
R66Y 0:80df663dd15e 80 void baud(int baudrate);
R66Y 0:80df663dd15e 81
R66Y 0:80df663dd15e 82 enum Parity {
R66Y 0:80df663dd15e 83 None = 0
R66Y 0:80df663dd15e 84 , Odd
R66Y 0:80df663dd15e 85 , Even
R66Y 0:80df663dd15e 86 , Forced1
R66Y 0:80df663dd15e 87 , Forced0
R66Y 0:80df663dd15e 88 };
R66Y 0:80df663dd15e 89
R66Y 0:80df663dd15e 90 /* Function: format
R66Y 0:80df663dd15e 91 * Set the transmission format used by the Serial port
R66Y 0:80df663dd15e 92 *
R66Y 0:80df663dd15e 93 * Variables:
R66Y 0:80df663dd15e 94 * bits - The number of bits in a word (5-8; default = 8)
R66Y 0:80df663dd15e 95 * parity - The parity used (Serial::None, Serial::Odd,
R66Y 0:80df663dd15e 96 Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None)
R66Y 0:80df663dd15e 97 * stop - The number of stop bits (1 or 2; default = 1)
R66Y 0:80df663dd15e 98 */
R66Y 0:80df663dd15e 99 void format(int bits = 8, Parity parity = Serial::None, int stop_bits
R66Y 0:80df663dd15e 100 = 1);
R66Y 0:80df663dd15e 101
R66Y 0:80df663dd15e 102 /* Function: putc
R66Y 0:80df663dd15e 103 * Write a character
R66Y 0:80df663dd15e 104 *
R66Y 0:80df663dd15e 105 * Variables:
R66Y 0:80df663dd15e 106 * c - The character to write to the serial port
R66Y 0:80df663dd15e 107 */
R66Y 0:80df663dd15e 108 int putc(int c);
R66Y 0:80df663dd15e 109
R66Y 0:80df663dd15e 110 /* Function: getc
R66Y 0:80df663dd15e 111 * Read a character
R66Y 0:80df663dd15e 112 *
R66Y 0:80df663dd15e 113 * Read a character from the serial port. This call will block
R66Y 0:80df663dd15e 114 * until a character is available. For testing if a character is
R66Y 0:80df663dd15e 115 * available for reading, see <readable>.
R66Y 0:80df663dd15e 116 *
R66Y 0:80df663dd15e 117 * Variables:
R66Y 0:80df663dd15e 118 * returns - The character read from the serial port
R66Y 0:80df663dd15e 119 */
R66Y 0:80df663dd15e 120 int getc();
R66Y 0:80df663dd15e 121
R66Y 0:80df663dd15e 122 /* Function: printf
R66Y 0:80df663dd15e 123 * Write a formated string
R66Y 0:80df663dd15e 124 *
R66Y 0:80df663dd15e 125 * Variables:
R66Y 0:80df663dd15e 126 * format - A printf-style format string, followed by the
R66Y 0:80df663dd15e 127 * variables to use in formating the string.
R66Y 0:80df663dd15e 128 */
R66Y 0:80df663dd15e 129 int printf(const char* format, ...);
R66Y 0:80df663dd15e 130
R66Y 0:80df663dd15e 131 /* Function: scanf
R66Y 0:80df663dd15e 132 * Read a formated string
R66Y 0:80df663dd15e 133 *
R66Y 0:80df663dd15e 134 * Variables:
R66Y 0:80df663dd15e 135 * format - A scanf-style format string,
R66Y 0:80df663dd15e 136 * followed by the pointers to variables to store the results.
R66Y 0:80df663dd15e 137 */
R66Y 0:80df663dd15e 138 int scanf(const char* format, ...);
R66Y 0:80df663dd15e 139
R66Y 0:80df663dd15e 140 /* Function: readable
R66Y 0:80df663dd15e 141 * Determine if there is a character available to read
R66Y 0:80df663dd15e 142 *
R66Y 0:80df663dd15e 143 * Variables:
R66Y 0:80df663dd15e 144 * returns - 1 if there is a character available to read, else 0
R66Y 0:80df663dd15e 145 */
R66Y 0:80df663dd15e 146 int readable();
R66Y 0:80df663dd15e 147
R66Y 0:80df663dd15e 148 /* Function: writeable
R66Y 0:80df663dd15e 149 * Determine if there is space available to write a character
R66Y 0:80df663dd15e 150 *
R66Y 0:80df663dd15e 151 * Variables:
R66Y 0:80df663dd15e 152 * returns - 1 if there is space to write a character, else 0
R66Y 0:80df663dd15e 153 */
R66Y 0:80df663dd15e 154 int writeable();
R66Y 0:80df663dd15e 155
R66Y 0:80df663dd15e 156 /* Function: attach
R66Y 0:80df663dd15e 157 * Attach a function to call whenever a serial interrupt is generated
R66Y 0:80df663dd15e 158 *
R66Y 0:80df663dd15e 159 * Variables:
R66Y 0:80df663dd15e 160 * fptr - A pointer to a void function, or 0 to set as none
R66Y 0:80df663dd15e 161 */
R66Y 0:80df663dd15e 162 void attach(void (*fptr)(void));
R66Y 0:80df663dd15e 163
R66Y 0:80df663dd15e 164 /* Function: attach
R66Y 0:80df663dd15e 165 * Attach a member function to call whenever a serial interrupt is generated
R66Y 0:80df663dd15e 166 *
R66Y 0:80df663dd15e 167 * Variables:
R66Y 0:80df663dd15e 168 * tptr - pointer to the object to call the member function on
R66Y 0:80df663dd15e 169 * mptr - pointer to the member function to be called
R66Y 0:80df663dd15e 170 */
R66Y 0:80df663dd15e 171 template<typename T>
R66Y 0:80df663dd15e 172 void attach(T* tptr, void (T::*mptr)(void));
R66Y 0:80df663dd15e 173
R66Y 0:80df663dd15e 174 #endif
R66Y 0:80df663dd15e 175
R66Y 0:80df663dd15e 176 protected:
R66Y 0:80df663dd15e 177 PinName _txpin;
R66Y 0:80df663dd15e 178
R66Y 0:80df663dd15e 179 virtual int _putc(int c);
R66Y 0:80df663dd15e 180 virtual int _getc(void);
R66Y 0:80df663dd15e 181
R66Y 0:80df663dd15e 182 }; // End class SerialHalfDuplex
R66Y 0:80df663dd15e 183
R66Y 0:80df663dd15e 184 } // End namespace
R66Y 0:80df663dd15e 185
R66Y 0:80df663dd15e 186 #endif
R66Y 0:80df663dd15e 187
R66Y 0:80df663dd15e 188 #endif