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

📄 kit05test.c

📁 瑞萨智能车大赛源码。High-performance Embedded Workshop
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************/
/*  Micom Car Rally Trace Program 2005 Version                              */
/*  Sensor board Motor drive board test program                             */
/*  2005.04 Renesas Technology Micom Car Rally Executive Committee          */
/****************************************************************************/

/*
The sensor board and the motor drive board for the kit are tested.
The content of the test is changed by the DIP switch of CPU board.
   DipSW
bit3 2 1 0
   0 0 0 0 LED test             LED lights alternately every 0.5 seconds.
   0 0 0 1 Push switch test     Switch OFF丗LED0 lights, Switch ON丗LED1 lights
   0 0 1 0 Servo test           Repetition of (  0亱仺  right 30亱仺  left 30亱)
   0 0 1 1
   0 1 0 0 Right motor test     Repetition of ( normal rotation 仺 brake )
   0 1 0 1                      Repetition of ( reverse 仺 brake )
   0 1 1 0 Left motor test      Repetition of ( normal rotation 仺 brake )
   0 1 1 1                      Repetition of ( reverse 仺 brake )

   1 0 0 0 Sensor test          Sensor bit1, 0 are output to LED1, 0
   1 0 0 1                      Sensor bit3, 2 are output to LED1, 0
   1 0 1 0                      Sensor bit5, 4 are output to LED1, 0
   1 0 1 1                      Sensor bit7, 6 are output to LED1, 0

   1 1 0 0 Direct Advance test  Advances by PWM 50%   Stop after 2 seconds
   1 1 0 1 Direct Advance test  Advances by PWM 50%   Stop after 5 seconds
   1 1 1 0 Direct Advance test  Advances by PWM 100%  Stop after 2 seconds
   1 1 1 1 Direct Advance test  Advances by PWM 100%  Stop after 5 seconds
*/

/*======================================*/
/* Include                              */
/*======================================*/
#include    <machine.h>
#include    "h8_3048.h"

/*======================================*/
/* Symbol Definition                    */
/*======================================*/

/* Constant setting */
#define         TIMER_CYCLE     3071    /* Timer cycle 1ms          */
                                        /* When using at冇/8,       */
                                        /* 冇/8 = 325.5[ns]         */
                                        /* 亪TIMER_CYCLE =          */
                                        /*      1[ms] / 325.5[ns]   */
                                        /*               = 3072     */
#define         PWM_CYCLE       49151   /* PWM cycle 16ms           */
                                        /* 亪PWM_CYCLE =            */
                                        /*      16[ms] / 325.5[ns]  */
                                        /*               = 49152    */
#define         SERVO_CENTER    5000    /* Center value of Servo    */
#define         HANDLE_STEP     26      /* 1亱of value              */

/*======================================*/
/* Prototype declaration                */
/*======================================*/
void init( void );
unsigned char sensor_inp( unsigned char mask );
unsigned char dipsw_get( void );
unsigned char pushsw_get( void );
void led_out( unsigned char led );
void speed( int accele_l, int accele_r );
void handle( int angle );
char unsigned bit_change( char unsigned in );

/*======================================*/
/* Declaration of global variable       */
/*======================================*/
unsigned long   cnt0;                   /* For timer function       */
unsigned long   cnt1;                   /* Used in main             */

/************************************************************************/
/* Main program                                                         */
/************************************************************************/
void main( void )
{
    unsigned char   now_sw;             /* Present DIP switch memory    */
    unsigned char   before_sw;          /* Previous DIP switch memory   */
    unsigned char   c;                  /* For operation                */
    int             i;                  /* For operation                */

    /* Initialization of micom function */
    init();                             /* Initialization               */
    set_ccr( 0x00 );                    /* Enable all interrupts        */

    /* Variable initialization */
    before_sw = dipsw_get();
    cnt1 = 0;

    /* Micom car state initialization */
    handle( 0 );
    speed( 0, 0 );
    led_out( 0x0 );

    while( 1 ) {
        /* DIP switch reading */
        now_sw = dipsw_get();

        /* Comparison with previous switch value */
        if( before_sw != now_sw ) {
            /* If disagrees with previous value update, clear of timer value */
            before_sw = now_sw;
            cnt1 = 0;
        }

        /* Test mode selection according to the value of the DIP switch  */
        switch( now_sw ) {

            /* LED test  LED lights alternately every 0.5 seconds */
            case 0:
                if( cnt1 < 500 ) {
                    led_out( 0x1 );
                } else if( cnt1 < 1000 ) {
                    led_out( 0x2 );
                } else {
                    cnt1 = 0;
                }
                break;

            /* Push switch test   OFF丗LED0 lights,  ON丗LED1 lights */
            case 1:
                led_out( pushsw_get() + 1 );
                break;

            /* Servo test  Repetition of (  0亱仺right 30亱仺left 30亱 ) */
            case 2:
                if( cnt1 < 1000 ) {
                    handle( 0 );
                } else if( cnt1 < 2000 ) {
                    handle( 30 );
                } else if( cnt1 < 3000 ) {
                    handle( -30 );
                } else {
                    cnt1 = 0;
                }
                break;

            /* Right motor test  Repetition of ( normal rotation仺brake ) */
            case 4:
                if( cnt1 < 1000 ) {
                    speed( 0, 100 );
                } else if( cnt1 < 2000 ) {
                    speed( 0, 0 );
                } else {
                    cnt1 = 0;
                }
                break;

            /* Right motor test  Repetition of ( reverse仺brake ) */
            case 5:
                if( cnt1 < 1000 ) {
                    speed( 0, -100 );
                } else if( cnt1 < 2000 ) {
                    speed( 0, 0 );
                } else {
                    cnt1 = 0;
                }
                break;

            /* Left motor test   Repetition of ( normal rotation仺brake ) */
            case 6:
                if( cnt1 < 1000 ) {
                    speed( 100, 0 );
                } else if( cnt1 < 2000 ) {
                    speed( 0, 0 );
                } else {
                    cnt1 = 0;
                }
                break;

            /* Left Motor test  Rrepetition of ( reverse仺brake ) */
            case 7:
                if( cnt1 < 1000 ) {
                    speed( -100, 0 );
                } else if( cnt1 < 2000 ) {
                    speed( 0, 0 );
                } else {
                    cnt1 = 0;
                }
                break;

            /* Sensor test      Sensor bit1,0 is output to LED1,0 */
            case 8:
                c = sensor_inp( 0x03 );
                led_out( c );
                PADR = sensor_inp( 0xff );
                break;

            /* Sensor test      Sensor bit3,2 is output to LED1,0 */
            case 9:
                c = sensor_inp( 0x0c );
                c = c >> 2;
                led_out( c );
                PADR = sensor_inp( 0xff );
                break;

            /* Sensor test      Sensor bit5,4 is output to LED1,0 */
            case 10:
                c = sensor_inp( 0x30 );
                c = c >> 4;
                led_out( c );
                PADR = sensor_inp( 0xff );
                break;

            /* Sensor test      Sensor bit7,6 is output to LED1,0 */
            case 11:
                c = sensor_inp( 0xc0 );
                c = c >> 6;
                led_out( c );
                PADR = sensor_inp( 0xff );
                break;

            /* Direct Advance test Advances by PWM 50%, Stop after 2 seconds */
            case 12:
                if( cnt1 < 2000 ) {
                    speed( 0, 0 );
                } else if( cnt1 < 4000 ) {
                    speed( 50, 50 );

⌨️ 快捷键说明

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