智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 1475|回复: 3
打印 上一主题 下一主题

串口问题,,求大神

[复制链接]

3

主题

20

帖子

0

精华

高级会员

Rank: 4

积分
627
威望
327
贡献
178
兑换币
202
注册时间
2013-5-27
在线时间
61 小时
毕业学校
湖北工业大学
跳转到指定楼层
1#
发表于 2013-7-30 19:37:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5贡献
为嘛,我的图像采集程序是例程,但是用232的线接收回来始终没有对啊,,求大神解答。。。。。。。。。。。。而且我用单片机历程的串口接收也接受不到,求解

#include <hidef.h>          /* common defines and macros */
#include "derivative.h"     /* derivative-specific definitions */
#include <MC9S12XS128.h>

#define ROW     40          //定义图像采集行数:40行
#define COLUMN  120         //定义图像采集列数:120列

unsigned char Image_Data[ROW][COLUMN];    //图像数组
unsigned char VSYN_C=0;         //场数统计值
unsigned int Line_C=0;          //行数统计值
unsigned char m = 0;
unsigned char  Interval;        //采集有效行数间隔
unsigned char  THRESHOLD=0x45;  //黑白二值化图像阈值(经验值,随环境光变换而变化)

void  Delay_1us(unsigned char t)
{
unsigned char i;
t=9*t;
for(i=0;i<t;i++)
{;}
}



/***************************************************
** 函数名称: PLL_Init
** 功能描述: 时钟初始化函数
** 说明:     总线时钟选定24M
****************************************************/
void PLL_Init(void)
{
  CLKSEL=0x00; //24mhz
  SYNR=0XC0 | 0X05;
  REFDV=0XC0 | 0X03;
  PLLCTL_PLLON=1;
  POSTDIV=0X00;
  asm(nop);
  asm(nop);
  while(0==CRGFLG_LOCK); //锁相环锁定
  CLKSEL_PLLSEL=1; //选定PLL时钟
}
/***************************************************
** 函数名称: TIM_Init
** 功能描述: 行场中断初始化函数
** 说明:     行中断上升沿触发  场中断下降沿触发
****************************************************/
void TIM_Init(void)
{
TIOS =0x00;        //定时器通道0,1 为输入捕捉
TSCR1=0x80;        //定时器使能
TCTL4=0x09;        //通道0 捕捉上升沿通道1 捕捉下降沿
TIE=0x03;          //通道0,1 中断使能
TFLG1=0xFF;        //清中断标志位
}
/***************************************************
** 函数名称: SCI0_Init
** 功能描述: 串口1初始化函数
** 说明:     波特率115200  串口SCI0
****************************************************/
void SCI0_Init()
{
SCI0BDL = (byte)((24000000 /* OSC freq /2*/) /115200  /* 115200baud rate */ / 16 /*factor*/);
SCI0CR1 = 0X00;  //设置SCI0为正常模式,八位数据位,无奇偶校验                                
SCI0CR2 = 0X0C;                                      /*RIE=1,TE=1,RE=1, */
}

/*void Image_Binaryzation(unsigned int row)  ////双数组模式 图像处理时选用
{
  unsigned char *p_Image;
  unsigned char *q_Image;
  q_Image=&Buffer[row][0];
  
  for(p_Image=&Image_Data[row][0];p_Image<=&Image_Data[row][COLUMN-1];p_Image++)      
    {*(q_Image++)=*p_Image; }  
}*/

/**************************************************
** 函数名称: 串口发射端程序
** 功能描述: 发送图像采集像素到DEMOKtool
** 说明:    在发送图像数据前要按照协议发送0XFF图像头
***************************************************/
void SCI0_Transmit(void)
{
  byte temp;
  unsigned char i,j;
  temp = SCI0SR1; //清零
  SCI0DRH = 0;
  
  
  SCI0DRL = 0XFF;             //图像头0XFF
  while (!(SCI0SR1&0x80));
  
  for(i = 0;i< ROW;i++)
  {
   
    for(j = 0;j < COLUMN ;j++)
    {
    //---------------发送二值化数据到SSCOM---------------------//
     //if(Image_Data[j]>THRESHOLD && Image_Data[j+1]>THRESHOLD && Image_Data[j-1]>THRESHOLD)  SCI0DRL = 0x30;
     //if(Image_Data[j]>THRESHOLD)  SCI0DRL = 0x30;
     // else SCI0DRL = 0X31;    //黑线
    //---------------发送二值化数据到SSCOM---------------------//
   
    //---------------发送像素数据到DEMOKTOOL---------------------//
      if(Image_Data[j] == 0xFF)  Image_Data[j] = 0xFE;  //若为图像头 自减
      SCI0DRL =  Image_Data[j];
      
      while (!(SCI0SR1&0x80));
     //---------------发送像素数据到DEMOKTOOL---------------------//
    }
  
// SCI0DRL = 0X0A;           //回车
// while (!(SCI0SR1&0x80));
//  SCI0DRL = 0X0D;           //换行
//while (!(SCI0SR1&0x80));
  }
}

/***************************************************
** 函数名称: main
** 功能描述: 主函数
** 说明:
****************************************************/  
void main(void)
{
/* put your own code here */
  DisableInterrupts;
  DDRA = 0X00;
  DDRB = 0xFF;
  PORTB= 0xFF;
  PLL_Init();
  SCI0_Init();
  TIM_Init();
  EnableInterrupts;
  for(;;)
  {
  if(VSYN_C)
  {
      
    SCI0_Transmit();
   
    VSYN_C=0;
    EnableInterrupts;
  }
  PORTB = ~PORTB;    //指示程序运行
  //_FEED_COP(); /* feeds the dog */
  } /* loop forever */
/* please make sure that you never leave main */
}
//---------------------中断定义---------------------
#pragma CODE_SEG NON_BANKED
/**************************************************
** 函数名称: 中断处理函数
** 功能描述: 行中断处理函数
** 输    入: 无
** 输    出: 无
** 说明:  
***************************************************/
interrupt 8 void HREF_Count(void)
{
  TFLG1_C0F = 1;
  m++;
  if ( m<6 || m>240 )      
  {
    return;//判断是否从新的一场开始
  }
  
  Interval=6;
  if(m%Interval==0)
  {
   
   
Image_Data[Line_C][0] = PORTA;
Image_Data[Line_C][1] = PORTA;
Image_Data[Line_C][2] = PORTA;
Image_Data[Line_C][3] = PORTA;
Image_Data[Line_C][4] = PORTA;
Image_Data[Line_C][5] = PORTA;
Image_Data[Line_C][6] = PORTA;
Image_Data[Line_C][7] = PORTA;
Image_Data[Line_C][8] = PORTA;
Image_Data[Line_C][9] = PORTA;
Image_Data[Line_C][10] = PORTA;
Image_Data[Line_C][11] = PORTA;
Image_Data[Line_C][12] = PORTA;
Image_Data[Line_C][13] = PORTA;
Image_Data[Line_C][14] = PORTA;
Image_Data[Line_C][15] = PORTA;
Image_Data[Line_C][16] = PORTA;
Image_Data[Line_C][17] = PORTA;
Image_Data[Line_C][18] = PORTA;
Image_Data[Line_C][19] = PORTA;
Image_Data[Line_C][20] = PORTA;
Image_Data[Line_C][21] = PORTA;
Image_Data[Line_C][22] = PORTA;
Image_Data[Line_C][23] = PORTA;
Image_Data[Line_C][24] = PORTA;
Image_Data[Line_C][25] = PORTA;
Image_Data[Line_C][26] = PORTA;
Image_Data[Line_C][27] = PORTA;
Image_Data[Line_C][28] = PORTA;
Image_Data[Line_C][29] = PORTA;
Image_Data[Line_C][30] = PORTA;
Image_Data[Line_C][31] = PORTA;
Image_Data[Line_C][32] = PORTA;
Image_Data[Line_C][33] = PORTA;
Image_Data[Line_C][34] = PORTA;
Image_Data[Line_C][35] = PORTA;
Image_Data[Line_C][36] = PORTA;
Image_Data[Line_C][37] = PORTA;
Image_Data[Line_C][38] = PORTA;
Image_Data[Line_C][39] = PORTA;
Image_Data[Line_C][40] = PORTA;
Image_Data[Line_C][41] = PORTA;
Image_Data[Line_C][42] = PORTA;
Image_Data[Line_C][43] = PORTA;
Image_Data[Line_C][44] = PORTA;
Image_Data[Line_C][45] = PORTA;
Image_Data[Line_C][46] = PORTA;
Image_Data[Line_C][47] = PORTA;
Image_Data[Line_C][48] = PORTA;
Image_Data[Line_C][49] = PORTA;
Image_Data[Line_C][50] = PORTA;
Image_Data[Line_C][51] = PORTA;
Image_Data[Line_C][52] = PORTA;
Image_Data[Line_C][53] = PORTA;
Image_Data[Line_C][54] = PORTA;
Image_Data[Line_C][55] = PORTA;
Image_Data[Line_C][56] = PORTA;
Image_Data[Line_C][57] = PORTA;
Image_Data[Line_C][58] = PORTA;
Image_Data[Line_C][59] = PORTA;
Image_Data[Line_C][60] = PORTA;
Image_Data[Line_C][61] = PORTA;
Image_Data[Line_C][62] = PORTA;
Image_Data[Line_C][63] = PORTA;
Image_Data[Line_C][64] = PORTA;
Image_Data[Line_C][65] = PORTA;
Image_Data[Line_C][66] = PORTA;
Image_Data[Line_C][67] = PORTA;
Image_Data[Line_C][68] = PORTA;
Image_Data[Line_C][69] = PORTA;
Image_Data[Line_C][70] = PORTA;
Image_Data[Line_C][71] = PORTA;
Image_Data[Line_C][72] = PORTA;
Image_Data[Line_C][73] = PORTA;
Image_Data[Line_C][74] = PORTA;
Image_Data[Line_C][75] = PORTA;
Image_Data[Line_C][76] = PORTA;
Image_Data[Line_C][77] = PORTA;
Image_Data[Line_C][78] = PORTA;
Image_Data[Line_C][79] = PORTA;
Image_Data[Line_C][80] = PORTA;
Image_Data[Line_C][81] = PORTA;
Image_Data[Line_C][82] = PORTA;
Image_Data[Line_C][83] = PORTA;
Image_Data[Line_C][84] = PORTA;
Image_Data[Line_C][85] = PORTA;
Image_Data[Line_C][86] = PORTA;
Image_Data[Line_C][87] = PORTA;
Image_Data[Line_C][88] = PORTA;
Image_Data[Line_C][89] = PORTA;
Image_Data[Line_C][90] = PORTA;
Image_Data[Line_C][91] = PORTA;
Image_Data[Line_C][92] = PORTA;
Image_Data[Line_C][93] = PORTA;
Image_Data[Line_C][94] = PORTA;
Image_Data[Line_C][95] = PORTA;
Image_Data[Line_C][96] = PORTA;
Image_Data[Line_C][97] = PORTA;
Image_Data[Line_C][98] = PORTA;
Image_Data[Line_C][99] = PORTA;
Image_Data[Line_C][100] = PORTA;
Image_Data[Line_C][101] = PORTA;
Image_Data[Line_C][102] = PORTA;
Image_Data[Line_C][103] = PORTA;
Image_Data[Line_C][104] = PORTA;
Image_Data[Line_C][105] = PORTA;
Image_Data[Line_C][106] = PORTA;
Image_Data[Line_C][107] = PORTA;
Image_Data[Line_C][108] = PORTA;
Image_Data[Line_C][109] = PORTA;
Image_Data[Line_C][110] = PORTA;
Image_Data[Line_C][111] = PORTA;
Image_Data[Line_C][112] = PORTA;
Image_Data[Line_C][113] = PORTA;
Image_Data[Line_C][114] = PORTA;
Image_Data[Line_C][115] = PORTA;
Image_Data[Line_C][116] = PORTA;
Image_Data[Line_C][117] = PORTA;
Image_Data[Line_C][118] = PORTA;
Image_Data[Line_C][119] = PORTA;
   
    Line_C++;
Delay_1us(1000);
  }
  
}
/**************************************************
** 函数名称: 中断处理函数
** 功能描述: 场中断处理函数
** 输    入: 无
** 输    出: 无
** 说明:  
***************************************************/
interrupt 9 void VSYN_Interrupt(void)
{
  TFLG1_C1F = 1; //清场中断
  TFLG1_C0F = 1; //清行中断
  Line_C = 0; //行计数器
  VSYN_C = ++VSYN_C;
   
}
#pragma CODE_SEG DEFAULT

9

主题

123

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
2058
威望
1054
贡献
600
兑换币
694
注册时间
2013-3-31
在线时间
202 小时
2#
发表于 2013-8-1 14:09:18 | 只看该作者
232直接连单片机?不是吧。。。
回复

使用道具 举报

3

主题

20

帖子

0

精华

高级会员

Rank: 4

积分
627
威望
327
贡献
178
兑换币
202
注册时间
2013-5-27
在线时间
61 小时
毕业学校
湖北工业大学
3#
 楼主| 发表于 2013-8-2 15:27:46 | 只看该作者
是啊
回复

使用道具 举报

8

主题

105

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1972
威望
906
贡献
586
兑换币
594
注册时间
2013-4-7
在线时间
240 小时
4#
发表于 2013-10-2 09:32:43 | 只看该作者
应该用usb转串口
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-21 11:09 , Processed in 0.197235 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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