飞思卡尔智能车程序

  • 格式:doc
  • 大小:48.00 KB
  • 文档页数:12

下载文档原格式

  / 12
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Main.c

#include /* common defines and macros */

#include /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12db128b"

#include "define.h"

#include "init.h"

// variable used in video process

volatile unsigned char image_data[ROW_MAX][LINE_MAX] ; // data array of picture unsigned char black_x[ROW_MAX] ; // 0ne-dimensional array

unsigned char row ; // x-position of the array

unsigned char line ; // y-position of the array

unsigned int row_count ; // row counter

unsigned char line_sample ; // used to counter in AD

unsigned char row_image ;

unsigned char line_temp ; // temperary variable used in data transfer

unsigned char sample_data[LINE_MAX] ; // used to save one-dimension array got in interruption

// variables below are used in speed measure

Unsigned char pulse[5] ; // used to save data in PA process

Unsigned char counter; // temporary counter in Speed detect

Unsigned char cur_speed; // current speed

short stand;

short data;

unsigned char curve ; // valve used to decide straight or turn

short Bounds(short data);

short FuzzyLogic(short stand);

/*----------------------------------------------------------------------------*\

receive_sci

\*----------------------------------------------------------------------------*/

unsigned char receive_sci(void) // receive data through sci

{ unsigned char sci_data;

while(SCI0SR1_RDRF!=1);

sci_data=SCI0DRL;

return sci_data;

}

/*----------------------------------------------------------------------------*\

transmit_sci

\*----------------------------------------------------------------------------*/

void transmit_sci(unsigned char transmit_data) // send data through sci

{

while(SCI0SR1_TC!=1);

while(SCI0SR1_TDRE!=1);

SCI0DRL=transmit_data;

}

/***************************************************************************** ***/

/*----------------------------------------------------------------------------*\

abs_sub

\*----------------------------------------------------------------------------*/ unsigned char abs_sub(unsigned char num1, unsigned char num2) { unsigned char difference;

if(num1>=num2){

difference=num1-num2;

}else{

difference=num2-num1;

}

return difference;

}

void pwm_set(unsigned int dutycycle)

{

PWMDTY1=dutycycle&0x00FF;

PWMDTY0=dutycycle>>8;

}

void get_black_wire(void) // used to extract black wire

{ unsigned char i;

for(row=0;row

for(line=LINE_MIN;line

if(image_data[row][line]>image_data[row][line+3]+VALVE){

for(i=3;i<10;i++){

if(image_data[row][line+i]+VALVE

i=10;

}

}

line=LINE_MAX;

} else{

//black_x[row]=(black_x[row]/45)*78;

}

}

}

}

/*----------------------------------------------------------------------------*\

speed_control

\*----------------------------------------------------------------------------*/