智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 6404|回复: 14
打印 上一主题 下一主题

一个图像采集中串口的问题,快疯了,急求助

[复制链接]

0

主题

29

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
377
威望
214
贡献
113
兑换币
0
注册时间
2009-1-15
在线时间
25 小时
跳转到指定楼层
1#
发表于 2009-2-21 17:21:24 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
以下是整个程序,运行后并没有输出期望的结果,应该是64*107个数,但输出的不对。另外我设置了一个变量K,赋值02输出却是FF。求助高手,主要是串口部分。
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dg128.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"


#define VIDEO_SAMPLE   INTCR_IRQEN=1 //外部中断使能
#define NO_SAMPLE     INTCR_IRQEN=0
#define LINE_MAX 107              // 每行采集的点数,即列数
#define ROW_MAX 64                // 采集到的行数


static unsigned char Video_flag;//行信号,采集标志信号。
unsigned char Image[ROW_MAX][LINE_MAX];//图像数据。
unsigned char black_x[ROW_MAX];//存放黑点
static unsigned char Image_get=0;//记录采集图像行数
static unsigned char row1;//图像数组行数


/************************************************************************************/
void Video_Init(void)
{
        HPRIO        = (unsigned char)(Virq & 0xff); //将IRQ优先级置为最高
        INTCR       |= INTCR_IRQE_MASK;                                                                // Failing sensitive only
//        INTCR       &=~INTCR_IRQEN_MASK;                                                            // Disable IRQ
        INTCR_IRQEN=0;          //Disable IRQ interrupt

        PERH  |=0X01;                //PULL UP  H0 上拉,
        PUCR_PUPAE=1;               // PortA Pull up 上拉,接收图像数据
        PIEH_PIEH0=0;                //0000 0001 H0 口中断使能
}


/******************************倍频*****************************************/
void PLLInit(void)
{ //BUS-CLOCK=PLL-CLOCK/2=32M
  REFDV = 1;
  SYNR =3;
  while (!CRGFLG_LOCK); // wait here till the PLL is locked.
  CLKSEL|=0x80; // switch the bus clock to the PLL.
}

/***************************IO口初始化************************************/
void IOPortInit(void)
{
  DDRA=0X00;
  DDRB=0XFF;
  
}

/*-------串口初始化----------------------*/
void SciInit(){
  SCI0BDL = (unsigned char)((16000000UL /* OSC freq */ / 2) / 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<250;j++)
         asm nop;
        }
}


/************************************主函数************************************/
void main(void)
{
  unsigned char i,j;
  unsigned char k;
  DisableInterrupts;
  PLLInit();
  IOPortInit();
  SciInit();  
  EnableInterrupts;  
  Delay(4000);
  DisableInterrupts;
  PORTB=0xf0;
  for(i=0;i<ROW_MAX;i++)
  {
    for(j=0;j<LINE_MAX;j++)
      SciTx(Image[i][j]);
  }
      
  PORTB=0x0f;
  k=0x02;
  SciTx(k);   
  for(;;)
  {
     
  }
}
/*****************************图像获得 *************************************/
/******************************行中断*****************************************/
#pragma CODE_SEG NON_BANKED
void interrupt 6 Port0_interrupt(void)
{
  TFLG1=0x01; //清除行中断标志
        if(Video_flag&&(row1%9)==0)
        {
                Video_flag=0;
                return;
        }

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

}
#pragma CODE_SEG  DEFAULT_ROM
/********场信号中断入口***************/
#pragma CODE_SEG NON_BANKED
void interrupt 25 PortH_ISR(void)
{
  PIFH=0XFF;       //Clear Flag H 中断标志位,1 有变化信号产生
        row1 = 0;
       
  if(Image_get==1)
        {
          NO_SAMPLE;
    PIEH_PIEH0=0;
    Image_get=0;
        }
  else
  {
    Image_get++;
  }

  if(Image_get>1)
  {
    Image_get=0;
  }        
}
#pragma CODE_SEG  DEFAULT_ROM

14

主题

929

帖子

1

精华

功勋会员

WJ

Rank: 10Rank: 10Rank: 10

积分
6304

特殊贡献奖章

威望
1456
贡献
4674
兑换币
17
注册时间
2008-4-6
在线时间
87 小时
2#
发表于 2009-2-21 19:11:13 | 只看该作者
把程序简化,先把串口调好再弄.
把板子搞干净,波特率对应好.
回复 支持 反对

使用道具 举报

0

主题

13

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
404
威望
278
贡献
80
兑换币
58
注册时间
2008-10-16
在线时间
23 小时
3#
发表于 2009-2-24 18:29:27 | 只看该作者
应该就是波特率问题,我也碰到过,但是现在解决了。
回复 支持 反对

使用道具 举报

9

主题

358

帖子

42

精华

金牌会员

Rank: 6Rank: 6

积分
1296
威望
80
贡献
506
兑换币
206
注册时间
2008-9-18
在线时间
355 小时
4#
发表于 2009-2-24 19:05:58 | 只看该作者
你的这个程序好像写的太麻烦了啊,优化一下。
建议采集数据时候用指针,这样你以后的图像处理和控制程序就有很多的时间。
你这样写的话效率很低的,你想一想!代码不优化的话,后面会很难做的,我刚开始也和你一样后面发现问题越来越多!

补充内容 (2015-4-23 09:36):
真人游戏|足球篮球|时时彩| 六合投注| 网络赚钱去SO娱乐城:顶级信用,提现百分百即时到账SO.CC


回复 支持 反对

使用道具 举报

0

主题

29

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
377
威望
214
贡献
113
兑换币
0
注册时间
2009-1-15
在线时间
25 小时
5#
 楼主| 发表于 2009-3-1 00:05:08 | 只看该作者
4# cys179 多谢诸位提意见,是波特率的问题。优化问题我会好好看看,再次感谢各位
回复 支持 反对

使用道具 举报

1

主题

41

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
276
威望
216
贡献
46
兑换币
2
注册时间
2009-10-17
在线时间
7 小时
6#
发表于 2010-2-8 11:17:54 | 只看该作者
这么长的程序
回复 支持 反对

使用道具 举报

1

主题

19

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
304
威望
260
贡献
20
兑换币
0
注册时间
2010-1-16
在线时间
12 小时
7#
发表于 2010-3-8 21:52:15 | 只看该作者
回复 5# 共和国之辉

你用的是OV6620?
回复 支持 反对

使用道具 举报

1

主题

28

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
282
QQ
威望
244
贡献
22
兑换币
0
注册时间
2010-3-5
在线时间
8 小时
8#
发表于 2010-3-15 22:47:11 | 只看该作者
怎么能踩到107个点的?
回复 支持 反对

使用道具 举报

6

主题

185

帖子

0

精华

高级会员

Rank: 4

积分
963
威望
435
贡献
438
兑换币
0
注册时间
2010-1-11
在线时间
45 小时
9#
发表于 2010-3-16 22:06:51 | 只看该作者
端口h的中断号不是26???
回复 支持 反对

使用道具 举报

2

主题

32

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1143
威望
268
贡献
827
兑换币
0
注册时间
2009-3-6
在线时间
24 小时
10#
发表于 2010-5-3 22:40:35 | 只看该作者
波特率的问题?是不是把下面这个语句中的16M改为32M吗?
SCI0BDL = (unsigned char)((16000000UL /* OSC freq */ / 2) / 9600 /* baud rate */ / 16 /*factor*/);
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-20 20:29 , Processed in 0.115515 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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