金牌会员
- 积分
- 1183
- 威望
- 183
- 贡献
- 1000
- 兑换币
- 0
- 注册时间
- 2011-1-31
- 在线时间
- 0 小时
|
- /****************************************************************************/
- /* "kit07_4wd.c" (武汉工程大学-copyright ) */
- /* 2009.07 */
- /****************************************************************************/
- /*======================================*/
- /* Include */
- /*======================================*/
- #include <machine.h>
- #include "h8_3048.h"
- #define PWM_CYCLE 49151 /* PWM 16ms */
- /* PWM_CYCLE = */
- /* 16[ms] / 325.5[ns] */
- /* = 49152 */
- #define F_PWM_CYCLE 3071
- #define SERVO_CENTER 5000
- #define HANDLE_STEP 26
- #define MASK2_2 0x66
- #define MASK2_0 0x60
- #define MASK0_2 0x06
- #define MASK3_3 0xe7
- #define MASK0_3 0x07
- #define MASK3_0 0xe0
- #define MASK4_0 0xf0
- #define MASK0_4 0x0f
- #define MASK4_4 0xff
- #define speed_r(x,y) speed(x,y) /* speed = speed_r */
- #define speed2_r(x,y) speed2(x,y) /* speed2 = speed2_r */
- void init( void );
- void timer( unsigned long timer_set );
- int check_crossline( void );
- int check_rightline( void );
- int check_leftline( void );
- unsigned char sensor_inp( unsigned char mask );
- unsigned char dipsw_get( void );
- unsigned char pushsw_get( void );
- unsigned char startbar_get( void );
- void led_out( unsigned char led );
- void speed( int accele_l, int accele_r );
- void speed2( int accele_l, int accele_r );
- void speed_f( int accele_l, int accele_r );
- void speed2_f( int accele_l, int accele_r );
- void handle( int angle );
- unsigned long cnt0;
- unsigned long cnt1;
- int pattern;
- void main( void )
- {
- int i;
- int m1, m2, m3, m4;
- unsigned char c;
- init();
- set_ccr( 0x00 );
- handle( 0 );
- speed( 0, 0 );
- while( 1 ) {
- if( cnt1 < 1000 ) {
- led_out( 0x1 );
- i = 50;
- } else if( cnt1 < 2000 ) {
- led_out( 0x0 );
- i = 0;
- } else if( cnt1 < 3000 ) {
- led_out( 0x2 );
- i = -50;
- } else if( cnt1 < 4000 ) {
- led_out( 0x0 );
- i = 0;
- } else {
- cnt1 = 0;
- }
- c = dipsw_get();
- if( c & 0x8) m1 = i; else m1 = 0;
- if( c & 0x4) m2 = i; else m2 = 0;
- if( c & 0x2) m3 = i; else m3 = 0;
- if( c & 0x1) m4 = i; else m4 = 0;
- speed2_f( m1, m2 );
- speed2_r( m3, m4 );
- }
- while( 1 ) {
- switch( pattern ) {
- case 0:
- if( pushsw_get() ) {
- pattern = 1;
- cnt1 = 0;
- break;
- }
- if( cnt1 < 100 ) {
- led_out( 0x1 );
- } else if( cnt1 < 200 ) {
- led_out( 0x2 );
- } else {
- cnt1 = 0;
- }
- break;
- case 1:
-
- if( !startbar_get() ) {
-
- led_out( 0x0 );
- pattern = 11;
- cnt1 = 0;
- break;
- }
- if( cnt1 < 50 ) {
- led_out( 0x1 );
- } else if( cnt1 < 100 ) {
- led_out( 0x2 );
- } else {
- cnt1 = 0;
- }
- break;
- case 11:
-
- if( check_crossline() ) {
- pattern = 21;
- break;
- }
- if( check_rightline() ) {
- pattern = 51;
- break;
- }
- if( check_leftline() ) {
- pattern = 61;
- break;
- }
- switch( sensor_inp(MASK3_3) ) {
- case 0x00:
-
- handle( 0 );
- speed( 100 ,100 );
- break;
- case 0x04:
-
- handle( 5 );
- speed( 100 ,100 );
- break;
- case 0x06:
-
- handle( 10 );
- speed( 80 ,67 );
- break;
- case 0x07:
-
- handle( 15 );
- speed( 50 ,38 );
- break;
- case 0x03:
- handle( 25 );
- speed( 30 ,19 );
- pattern = 12;
- break;
- case 0x20:
- handle( -5 );
- speed( 100 ,100 );
- break;
- case 0x60:
-
- handle( -10 );
- speed( 67 ,80 );
- break;
- case 0xe0:
- handle( -15 );
- speed( 38 ,50 );
- break;
- case 0xc0:
-
- handle( -25 );
- speed( 19 ,30 );
- pattern = 13;
- break;
- default:
- break;
- }
- break;
- case 12:
- if( check_crossline() ) {
- pattern = 21;
- break;
- }
- if( check_rightline() ) {
- pattern = 51;
- break;
- }
- if( check_leftline() ) {
- pattern = 61;
- break;
- }
- if( sensor_inp(MASK3_3) == 0x06 ) {
- pattern = 11;
- }
- break;
- case 13:
- if( check_crossline() ) { pattern = 21;
- break;
- }
- if( check_rightline() ) {
- pattern = 51;
- break;
- }
- if( check_leftline() ) {
- pattern = 61;
- break;
- }
- if( sensor_inp(MASK3_3) == 0x60 ) {
- pattern = 11;
- }
- break;
复制代码 |
|