| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | //***************************************************************************** |
| 2 | // File Name : servotest.c |
||
| 3 | // |
||
| 4 | // Title : example usage of RC servo library functions |
||
| 5 | // Revision : 1.0 |
||
| 6 | // Notes : |
||
| 7 | // Target MCU : Atmel AVR series |
||
| 8 | // Editor Tabs : 4 |
||
| 9 | // |
||
| 10 | // Revision History: |
||
| 11 | // When Who Description of change |
||
| 12 | // ----------- ----------- ----------------------- |
||
| 13 | // 10-Sep-2002 pstang Created the program |
||
| 14 | //***************************************************************************** |
||
| 15 | |||
| 16 | |||
| 17 | //----- Include Files --------------------------------------------------------- |
||
| 18 | #include <avr/io.h> // include I/O definitions (port names, pin names, etc) |
||
| 19 | #include <avr/interrupt.h> // include interrupt support |
||
| 20 | |||
| 21 | #include "global.h" // include our global settings |
||
| 22 | #include "uart.h" // include uart function library |
||
| 23 | #include "rprintf.h" // include printf function library |
||
| 24 | #include "a2d.h" // include A/D converter function library |
||
| 25 | #include "timer.h" // include timer function library (timing, PWM, etc) |
||
| 26 | #include "servo.h" // include RC servo driver library |
||
| 27 | #include "vt100.h" // include VT100 terminal library |
||
| 28 | |||
| 29 | void servoTest(void); |
||
| 30 | |||
| 31 | //----- Begin Code ------------------------------------------------------------ |
||
| 32 | int main(void) |
||
| 33 | { |
||
| 34 | // initialize our libraries |
||
| 35 | // initialize the UART (serial port) |
||
| 36 | uartInit(); |
||
| 37 | // set the baud rate of the UART for our debug/reporting output |
||
| 38 | uartSetBaudRate(9600); |
||
| 39 | // set uartSendByte as the output for all rprintf statements |
||
| 40 | rprintfInit(uartSendByte); |
||
| 41 | // initialize the timer system |
||
| 42 | timerInit(); |
||
| 43 | // initialize vt100 library |
||
| 44 | vt100Init(); |
||
| 45 | vt100ClearScreen(); |
||
| 46 | // print a little intro message so we know things are working |
||
| 47 | rprintf("\r\nWelcome to Servo Test!\r\n"); |
||
| 48 | |||
| 49 | // begin servo test |
||
| 50 | servoTest(); |
||
| 51 | |||
| 52 | return 0; |
||
| 53 | } |
||
| 54 | |||
| 55 | void servoTest(void) |
||
| 56 | { |
||
| 57 | u08 pos; |
||
| 58 | u08 channel; |
||
| 59 | |||
| 60 | // do some examples |
||
| 61 | // initialize RC servo system |
||
| 62 | servoInit(); |
||
| 63 | // setup servo output channel-to-I/Opin mapping |
||
| 64 | // format is servoSetChannelIO( CHANNEL#, PORT, PIN ); |
||
| 65 | servoSetChannelIO(0, _SFR_IO_ADDR(PORTC), PC0); |
||
| 66 | servoSetChannelIO(1, _SFR_IO_ADDR(PORTC), PC1); |
||
| 67 | servoSetChannelIO(2, _SFR_IO_ADDR(PORTC), PC2); |
||
| 68 | servoSetChannelIO(3, _SFR_IO_ADDR(PORTC), PC3); |
||
| 69 | |||
| 70 | // set port pins to output |
||
| 71 | outb(DDRC, 0x0F); |
||
| 72 | |||
| 73 | pos = 0; |
||
| 74 | |||
| 75 | #define SPEED_SERVO 1 |
||
| 76 | |||
| 77 | // spin servos sequentially back and forth between their limits |
||
| 78 | while(1) |
||
| 79 | { |
||
| 80 | for(channel=0; channel<SERVO_NUM_CHANNELS; channel++) |
||
| 81 | { |
||
| 82 | for(pos=0; pos<SERVO_POSITION_MAX; pos++) |
||
| 83 | { |
||
| 84 | servoSetPosition(channel,pos); |
||
| 85 | timerPause(SPEED_SERVO); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | for(channel=0; channel<SERVO_NUM_CHANNELS; channel++) |
||
| 90 | { |
||
| 91 | for(pos=SERVO_POSITION_MAX; pos>=1; pos--) |
||
| 92 | { |
||
| 93 | servoSetPosition(channel,pos); |
||
| 94 | timerPause(SPEED_SERVO); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | } |
Powered by WebSVN v2.8.3