智能车制作
标题:
采集到底需要那几个步骤!
[打印本页]
作者:
Make_it!
时间:
2012-5-23 08:42
标题:
采集到底需要那几个步骤!
关于图像采集 虽然把一些别人的程序看懂了但作为新手还是我还是不则怎么清楚其中的编程
请问是不是主要有如下几个部分组成:
1、设置频率 如void PLL_Init(void) {}
2、行场中断初始化函数 即输入捕捉 如void TIM_Init(void) {}
3、串口初始化程序 SCI0_Init() {}
4、串口发送程序 void SCI0_Transmit(void) {}
5、行场中断函数
#pragma CODE_SEG NON_BANKED
interrupt 8 void HREF_Count(void)
{
}
interrupt 9 void VSYN_Interrupt(void)
{
}
#pragma CODE_SEG DEFAULT
6、主函数 void mian(void) {}
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#include <MC9S12XS128.h>
//-----------函数声明-----------------//
void SCI0_Transmit(void);
#define ROW 47 //47行 缺省分辨率640X480
#define COLUMN 120 //每行采集120个数据 使用分辨率120X47
//unsigned char Buffer[ROW][COLUMN];
unsigned char Image_Data[ROW][COLUMN]; //为图像数据开辟存储空间,二维数组
unsigned char Point_C, VSYN_C=0, Line_Flag, m = 0,n=0;
unsigned int Line_C=0;
unsigned char Interval;
unsigned char THRESHOLD=0x45;
/***************************************************
** 函数名称: PLL_Init
** 功能描述: 时钟初始化函数
** 说明:
****************************************************/
void PLL_Init(void)
{
CLKSEL=0x00; //48mhz
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=0x21; //0捕捉上升沿 2 捕捉下降沿 改动了的原程序 TCTL4=0x09; //通道0 捕捉上升沿通道1 捕捉下降沿
TIE=0x05; //使能 改动了原程序 TIE=0x03; // 通道0,1 中断使能
TFLG1=0xFF; //清中断标志位
}
/***************************************************
** 函数名称: SCI0_Init
** 功能描述: 串口1初始化函数
** 说明:
****************************************************/
void SCI0_Init()
{
SCI0BDL = (byte)((48000000 /* OSC freq *//2) / 57600 /* baud rate */ / 16 /*factor*/);
//波特率是57600吧 ?
SCI0CR1 = 0X00; /*normal,no parity*/
SCI0CR2 = 0X0C; /*RIE=1,TE=1,RE=1, */
}
#pragma CODE_SEG NON_BANKED
/**************************************************
** 函数名称: 中断处理函数
** 功能描述: 行中断处理函数
** 输 入: 无
** 输 出: 无
** 说明:
***************************************************/
interrupt 8 void HREF_Count(void)
{
TFLG1_C0F = 1;
Line_Flag = 0;
m++;
if ( m<12 || m>288 )
{
return;//判断是否从新的一场开始
}
/*if(m<=144) Interval=12;
else if(m>144&&m<=200) Interval=8;
else if(m>200&&m<=252) Interval=6;
else Interval=4; */
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++;
}
// Image_Binaryzation(Line_C);
}
/**************************************************
** 函数名称: 中断处理函数
** 功能描述: 场中断处理函数
** 输 入: 无
** 输 出: 无
** 说明:
***************************************************/
interrupt 9 void VSYN_Interrupt(void)
{
TFLG1_C2F = 1; //清场中断 //原程序改动的 TFLG1_C1F = 1;
TFLG1_C0F = 1; //清行中断
Point_C = 0;
Line_C = 0; //行计数器
VSYN_C = ++VSYN_C;
}
#pragma CODE_SEG DEFAULT
/**************************************************
** 函数名称: 串口发射端程序
** 功能描述: 发送赛道信息 1为黑线 0为白板
** 输 入: 无
** 输 出: 无
** 说明:
***************************************************/
void SCI0_Transmit(void)
{
byte temp;
unsigned char i,j;
temp = SCI0SR1; //清零
SCI0DRH = 0;
for(i = 0;i< ROW-8;i++)
{
for(j = 0;j < COLUMN ;j++)
{
//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; //黑线 灰度值小于69
while (!(SCI0SR1&0x80));
}
SCI0DRL = 0X0A; //回车
while (!(SCI0SR1&0x80));
SCI0DRL = 0X0D; //换行
while (!(SCI0SR1&0x80));
}
}
/***************************************************
** 函数名称: main
** 功能描述: 主函数
** 说明:
****************************************************/
void main(void)
{
/* put your own code here */
DisableInterrupts;
DDRA = 0X00;
PLL_Init();
SCI0_Init();
TIM_Init();
EnableInterrupts;
for(;;)
{
if(VSYN_C)
{
SCI0_Transmit();
VSYN_C=0;
EnableInterrupts;
}
//_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
我用串口调试好像没有什么用啊 请大侠帮帮忙解决下啊!!!
作者:
Make_it!
时间:
2012-5-23 11:51
求大侠帮帮忙 指点下啊!
作者:
兰亭星落
时间:
2013-1-21 01:00
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2