智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 2946|回复: 2
打印 上一主题 下一主题

[软件类] 谁帮看看这程序不能实现跟踪黑线

[复制链接]

0

主题

7

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
373
QQ
威望
259
贡献
92
兑换币
52
注册时间
2009-1-3
在线时间
11 小时
跳转到指定楼层
1#
发表于 2009-4-14 23:06:11 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1贡献
#include <hidef.h>      /* common defines and macros */
#include <MC9S12XS128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12xs128"

#define LINE_MAX 107              // 每行采集的点数,即列数
#define ROW_MAX 2                // 采集到的行数

unsigned char Image[ROW_MAX][LINE_MAX];//图像数据。
//static unsigned int rowjd;//记录行中断
//static unsigned char space;
unsigned char      g_SampleFlag=0,f;

void PWMout(int Direction, int Velocity);
void Init_PWMout(void);
int SignalProcess( unsigned int signal );
void SignalTest(void);
void DV_set(void);
int Direction;
int Velocity;
/***************************************************************/
void Init_PWMout(void)
{   
PWME = 0x22; /*01:50Hz 45:1kHz */
PWMPOL = 0x22;
PWMCTL = 0x50;
PWMCLK = 0x02;
PWMSCLA = 10;
}
/***************************************************************/
void PWMout(int Direction, int Velocity)
{
Direction = Direction/3 + 1800;
Direction = Direction+20;
//if(Direction<1200) Direction=1200;
//if(Direction>1800) Direction=1800;
PWMPER01 = 60000; /* Center 1500ms*3 */
PWMDTY01 = Direction; /* 设置舵机角度 */
if(Velocity>24000) Velocity=24000;
PWMPER45 = 24000; /* 1kHz ( <10kHz ) */
PWMDTY45 = Velocity; /* 设置电机速度 */
}
/************************************************************************************/
/***************************行场中断初始化************************************/
void vinterruptsinit(void)
{
TIOS=0x00; //外部输入捕捉0,1通道
TCTL4=0x09; //通道0上升沿触发,通道1下降沿触发
TSCR1=0x80;
TIE_C1I = 1;
TIE_C0I = 1;
}

/******************************倍频*****************************************/
void PLLInit(void)
{ //BUS-CLOCK=PLL-CLOCK/2=24M
  REFDV = 1;
  SYNR =2;
  while (!CRGFLG_LOCK); // wait here till the PLL is locked.
  CLKSEL|=0x80; // switch the bus clock to the PLL.
}
/***************************IO口初始化************************************/
void IOPortInit(void)
{
  DDRB=0X00;
  
}
/*-------串口初始化----------------------*/
void SciInit(){
  SCI0BDL = (unsigned char)((24000000UL /* OSC freq */ ) / 9600 /* baud rate */ / 16 /*factor*/);
  SCI0CR1=0;     /*normal,no parity*/
  SCI0CR2=0X2C;       /*RIE=1,TE=1,RE=1*/
}
/*-------发射端程序----------------------*/
void SciTx(unsigned char text){
      while (!(SCI0SR1&0x80));  /* wait for output buffer empty */
  SCI0DRH=0;
  SCI0DRL=text;
}

void Delay(int delay)
{ int i,j;
for(i=0;i<delay;i++)
{for(j=0;j<10;j++)
  asm nop;
}
}

/************************************主函数************************************/
void main(void)
{

  DisableInterrupts;
  PLLInit();
  vinterruptsinit();
  IOPortInit();
  Init_PWMout() ;
  SciInit();
   
  EnableInterrupts;  
/* Delay(4000);
  for(i=0;i<ROW_MAX;i++)
  {  space=0xee;
    for(j=0;j<LINE_MAX;j++)
      SciTx(Image[i][j]);
    for(k=0;k<10;k++)
    SciTx(space);
  } */      

  for(;;)
  {
   
        SignalTest();
DV_set();
PWMout(Direction,Velocity);
   
  }
}

/************************************************************************/
void DV_set(void)
{
switch(f)
  { case 0x01irection=1200 ; Velocity=4000 ;break;
    case 0x02:Direction=800 ; Velocity=6000 ;break;
    case 0x04:Direction=400 ; Velocity=8000  ;break;
    case 0x08:Direction=100 ; Velocity=10000 ;break;
    case 0x10:Direction=-100; Velocity=10000 ;break;
    case 0x20:Direction=-400 ;Velocity=8000  ;break;
    case 0x40:Direction=-800 ;Velocity=4000 ;break;
    case 0x80:Direction=-1200; Velocity=6000 ;break;
    default: break;         
  
  }
}
/************************************************************************/
void SignalTest(void)
{
  
if(Image[1][65]<0x18)
{
  f=0x01;
}


if(Image[1][70]<0x18)
{
  f=0x02;
}


if(Image[1][75]<0x18)
{
  f=0x04;
}


if(Image[1][80]<0x18)
{
  f=0x08;
}


if(Image[1][90]<0x18)
{
  f=0x10;
}

if(Image[1][95]<0x18)
{
  f=0x20;
}

if(Image[1][100]<0x18)
{
  f=0x40;
}


if(Image[1][104]<0x18)
{
  f=0x80;
}

}

/*****************************图像获得 *************************************/
/******************************行中断*****************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 8 Port0_interrupt(void)
{
  TFLG1=0x01; //清除行中断标志
if ( g_SampleFlag == 0 )
{
Delay(1);
return;
}
  TIE_C1I = 0;

  Image[1][0]  = PORTB;
Image[1][1]  = PORTB;
Image[1][2]  = PORTB;
Image[1][3]  = PORTB;
Image[1][4]  = PORTB;
Image[1][5]  = PORTB;
Image[1][6]  = PORTB;
Image[1][7]  = PORTB;
Image[1][8]  = PORTB;
Image[1][9]  = PORTB;
Image[1][10] = PORTB;
Image[1][11] = PORTB;
Image[1][12] = PORTB;
Image[1][13] = PORTB;
Image[1][14] = PORTB;
Image[1][15] = PORTB;
Image[1][16] = PORTB;
Image[1][17] = PORTB;
Image[1][18] = PORTB;
Image[1][19] = PORTB;
Image[1][20] = PORTB;
Image[1][21] = PORTB;
Image[1][22] = PORTB;
Image[1][23] = PORTB;
Image[1][24] = PORTB;
Image[1][25] = PORTB;
Image[1][26] = PORTB;
Image[1][27] = PORTB;
Image[1][28] = PORTB;
Image[1][29] = PORTB;
Image[1][30] = PORTB;
Image[1][31] = PORTB;
Image[1][32] = PORTB;
Image[1][33] = PORTB;
Image[1][34] = PORTB;
Image[1][35] = PORTB;
Image[1][36] = PORTB;
Image[1][37] = PORTB;
Image[1][38] = PORTB;
Image[1][39] = PORTB;
Image[1][40] = PORTB;   
Image[1][41] = PORTB;
Image[1][42] = PORTB;
Image[1][43] = PORTB;
Image[1][44] = PORTB;
Image[1][45] = PORTB;
Image[1][46] = PORTB;
Image[1][47] = PORTB;
Image[1][48] = PORTB;
Image[1][49] = PORTB;
Image[1][50] = PORTB;
Image[1][51] = PORTB;
Image[1][52] = PORTB;
Image[1][53] = PORTB;
Image[1][54] = PORTB;
Image[1][55] = PORTB;
Image[1][56] = PORTB;
Image[1][57] = PORTB;
Image[1][58] = PORTB;
Image[1][59] = PORTB;
Image[1][60] = PORTB;
Image[1][61] = PORTB;
Image[1][62] = PORTB;
Image[1][63] = PORTB;
Image[1][64] = PORTB;
Image[1][65] = PORTB;
Image[1][66] = PORTB;
Image[1][67] = PORTB;
Image[1][68] = PORTB;
Image[1][69] = PORTB;
Image[1][70] = PORTB;
Image[1][71] = PORTB;
Image[1][72] = PORTB;
Image[1][73] = PORTB;
Image[1][74] = PORTB;
Image[1][75] = PORTB;
Image[1][76] = PORTB;
Image[1][77] = PORTB;
Image[1][78] =PORTB;
Image[1][79] = PORTB;
Image[1][80] = PORTB;
Image[1][81] = PORTB;
Image[1][82] = PORTB;
Image[1][83] = PORTB;
Image[1][84] = PORTB;
Image[1][85] = PORTB;
Image[1][86] = PORTB;
Image[1][87] = PORTB;
Image[1][88] = PORTB;
Image[1][89] = PORTB;
Image[1][90] = PORTB;
Image[1][91] = PORTB;
Image[1][92] = PORTB;
Image[1][93] = PORTB;
Image[1][94] = PORTB;
Image[1][95] = PORTB;
Image[1][96] = PORTB;
Image[1][97] = PORTB;
Image[1][98] = PORTB;
Image[1][99] = PORTB;
Image[1][100] = PORTB;
Image[1][101] = PORTB;
Image[1][102] = PORTB;
Image[1][103] = PORTB;
Image[1][104] = PORTB;
Image[1][105] = PORTB;
Image[1][106] = PORTB;
    SignalTest();
DV_set();
PWMout(Direction,Velocity);
g_SampleFlag = 0;
TIE_C2I = 1;
}



/**********场中断处理******************************************/
//#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 9 Port1_interrupt(void)
{
TFLG1=0x02;
g_SampleFlag = 1;
}

附件: 您需要 登录 才可以下载或查看,没有帐号?注册

14

主题

929

帖子

1

精华

功勋会员

WJ

Rank: 10Rank: 10Rank: 10

积分
6304

特殊贡献奖章

威望
1456
贡献
4674
兑换币
17
注册时间
2008-4-6
在线时间
87 小时
2#
发表于 2009-4-15 10:35:06 | 只看该作者
太长了,你自己都不能确定哪里对哪里错,别人会怎么看呢.
回复

使用道具 举报

6

主题

130

帖子

0

精华

高级会员

Rank: 4

积分
727
威望
508
贡献
105
兑换币
0
注册时间
2009-12-2
在线时间
57 小时
3#
发表于 2010-3-15 19:29:47 | 只看该作者
是啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

关于我们|联系我们|小黑屋|智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-9-21 08:31 , Processed in 0.050617 second(s), 30 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表