智能车制作
标题:
请摄像头组的朋友进来看看!!
[打印本页]
作者:
yumo_linux
时间:
2013-4-24 19:39
标题:
请摄像头组的朋友进来看看!!
有没有人使用DEMOK工作室的那个摄像头测试工具,有的话,能不能把那个摄像头采集的程序发给我,或者说下串口发送程序的方法,我们使用时总是提示找不到数据头,谢谢了!!
作者:
moopnoo
时间:
2013-4-24 21:13
#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; //黑白二值化图像阈值(经验值,随环境光变换而变化)
/***************************************************
** 函数名称: 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 /* baud rate */ / 16 /*factor*/);
SCI0CR1 = 0X00; /*normal,no parity*/
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[i][j]>THRESHOLD && Image_Data[i][j+1]>THRESHOLD && Image_Data[i][j-1]>THRESHOLD) SCI0DRL = 0x30;
//if(Image_Data[i][j]>THRESHOLD) SCI0DRL = 0x30;
// else SCI0DRL = 0X31; //黑线
//---------------发送二值化数据到SSCOM---------------------//
//---------------发送像素数据到DEMOKTOOL---------------------//
if(Image_Data[i][j] == 0xFF) Image_Data[i][j] = 0xFE; //若为图像头 自减
SCI0DRL = Image_Data[i][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++;
}
}
/**************************************************
** 函数名称: 中断处理函数
** 功能描述: 场中断处理函数
** 输 入: 无
** 输 出: 无
** 说明:
***************************************************/
interrupt 9 void VSYN_Interrupt(void)
{
TFLG1_C1F = 1; //清场中断
TFLG1_C0F = 1; //清行中断
Line_C = 0; //行计数器
VSYN_C = ++VSYN_C;
}
#pragma CODE_SEG DEFAULT
作者:
moopnoo
时间:
2013-4-24 21:14
不知道是不是你想要的
作者:
诗意人生
时间:
2013-4-25 14:59
多谢楼主分享!
欢迎光临 智能车制作 (http://111.231.132.190/)
Powered by Discuz! X3.2