⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sioservo2.c

📁 瑞萨智能车大赛源码。High-performance Embedded Workshop
💻 C
字号:
/****************************************************************************/
/* Searching for the maximum steering turn of the servo by personal         */
/* computer.    乽sioservo2.c乿                                             */
/* Comunication cable <-> personal computer,PB<-Motor drive board (Vol.3)   */
/* Motor drive board (Vol.3) <- Servo motor                                 */
/* Comunication : 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 the actual maximum steering turn of the
servo 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 -5
'S' key     丗the value of servo motor offset +5
*/

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

/*======================================*/
/* Symbol definition                    */
/*======================================*/
#define         SERVO_CENTER    5000    /* The value of servo motor center */

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

/*======================================*/
/* Global variable declaration          */
/*======================================*/
int             servo_angle;            /* The angle of servo */

/************************************************************************/
/* 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_angle = 0;
    printf(
        "Servo Angle Check Soft\n"
        "'Z' key   : Angle Value -1\n"
        "'X' key   : Angle Value +1\n"
        "\n"
        "'A' key   : Angle Value -5\n"
        "'S' key   : Angle Value +5\n"
        "\n"
    );
    printf( "%3d\r", servo_angle );

    while( 1 ) {
        ITU4_BRB = SERVO_CENTER - servo_angle * 26;

        i = get_sci( &c );
        if( i == 1 ) {
            switch( c ) {
            case 'Z':
            case 'z':
                servo_angle--;
                if( servo_angle < -50 ) servo_angle = -50;
                printf( "%3d\r", servo_angle );
                break;

            case 'X':
            case 'x':
                servo_angle++;
                if( servo_angle > 50 ) servo_angle = 50;
                printf( "%3d\r", servo_angle );
                break;

            case 'A':
            case 'a':
                servo_angle -= 5;
                if( servo_angle < -50 ) servo_angle = -50;
                printf( "%3d\r", servo_angle );
                break;

            case 'S':
            case 's':
                servo_angle += 5;
                if( servo_angle > 50 ) servo_angle = 50;
                printf( "%3d\r", servo_angle );
                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 = SERVO_CENTER; /* 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -