sioservo.c

来自「瑞萨智能车大赛源码。High-performance Embedded Work」· C语言 代码 · 共 139 行

C
139
字号
/****************************************************************************/
/* Adjusting sevo-center from PC乽sioservo.c乿                              */
/* Communication cable 仼仺PC, PB仼Motor drive board 仼servo motor          */
/* Communication :Tera-term-pro 2005.04 Renesas Technology Micom Car Rally Executive Committee */
/****************************************************************************/
/*
First of all, Start up the Tera-term-pro.
This is the check program by which servo center of micom car is adjusted
with using key board.
The servo motor moves like below every pushing each key as the following.

'Z' key     丗the value of servo motor offset +1
'X' key     丗the value of servo motor offset -1
'A' key     丗the value of servo motor offset +10
'S' key     丗the value of servo motor offset -10
*/

/*======================================*/
/* Include                              */
/*======================================*/
#include    <no_float.h>                /* The simplification of stdio is put first. */
#include    <stdio.h>
#include    <machine.h>
#include    "h8_3048.h"

/*======================================*/
/* Symbol definition                    */
/*======================================*/

/*======================================*/
/* Prototype declaration                */
/*======================================*/
void init( void );

/*======================================*/
/* Global variable declaration          */
/*======================================*/
unsigned int    servo_offset;           /* sevo motor offset           */

/************************************************************************/
/* Main program                                                         */
/************************************************************************/
void main( void )
{
    int     i, ret;
    char    c;

    /*  Microcomputer function initialization */
    init();                             /* Initialization function     */
    init_sci1( 0x00, 79 );              /* Initialization of SCI1      */
    set_ccr( 0x00 );                    /* Entire interrupt permission */

    servo_offset = 5000;
    printf(
        "Servo Center Adjustment Soft\n"
        "'Z' key   : Center Value +1\n"
        "'X' key   : Center Value -1\n"
        "\n"
        "'A' key   : Center Value +10\n"
        "'S' key   : Center Value -10\n"
        "\n"
    );
    printf( "%5d\r", servo_offset );

    while( 1 ) {
        ITU4_BRB = servo_offset;

        i = get_sci( &c );
        if( i == 1 ) {
            switch( c ) {
            case 'Z':
            case 'z':
                servo_offset++;
                if( servo_offset > 10000 ) servo_offset = 10000;
                printf( "%5d\r", servo_offset );
                break;

            case 'A':
            case 'a':
                servo_offset += 10;
                if( servo_offset > 10000 ) servo_offset = 10000;
                printf( "%5d\r", servo_offset );
                break;

            case 'X':
            case 'x':
                servo_offset--;
                if( servo_offset < 1000 ) servo_offset = 1000;
                printf( "%5d\r", servo_offset );
                break;

            case 'S':
            case 's':
                servo_offset -= 10;
                if( servo_offset < 1000 ) servo_offset = 1000;
                printf( "%5d\r", servo_offset );
                break;

            default:
                break;
            }
        }
    }
}

/************************************************************************/
/*  H8/3048F-ONE Built-in Peripheral Functions Initialization           */
/************************************************************************/
void init( void )
{
    /*  I/O setting of port */
    P1DDR = 0xff;
    P2DDR = 0xff;
    P3DDR = 0xff;
    P4DDR = 0xff;
    P5DDR = 0xff;
    P6DDR = 0xf0;                       /* DIP Switch on the CPU board      */
    P8DDR = 0xff;
    P9DDR = 0xf7;
    PADDR = 0xff;
    PBDR  = 0xc0;
    PBDDR = 0xfe;                       /* Motor drive board(Vol.3)         */
    /* There is no I/O setting because port 7 is for the input alone.       */

    /* ITU3,4 Reset-synchronized PWM mode for left morter, right morter, and servo */
    ITU3_TCR = 0x23;                    /* Setting of counter clear         */
    ITU_FCR  = 0x3e;                    /* Reset-synchronized PWM mode      */
    ITU3_GRA = 49151;                   /* Setting of Period of PWM         */
    ITU3_GRB = ITU3_BRB = 0;            /* Setting of left morter PWM       */
    ITU4_GRA = ITU4_BRA = 0;            /* Setting of right morter PWM      */
    ITU4_GRB = ITU4_BRB = 5000;         /* Setting of sevo motor PWM        */
    ITU_TOER = 0x38;                    /* Setting of out put pins          */
    ITU_STR  = 0x08;                    /* Starting of timer count register */
}

/************************************************************************/
/* end of file                                                          */
/************************************************************************/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?