智能车制作
标题:
摄像头采集问题
[打印本页]
作者:
cjinxing
时间:
2011-6-10 18:20
标题:
摄像头采集问题
我是个菜鸟,图像搞了很久都搞不出来,求助各位大哥!!
这是我根据上位机通信协议写的采集程序,但是什么都看不到,麻烦大家帮我看看。
#include <hidef.h>
#include <MC9S12XS128.h>
/*************宏定义****************************/
#define LINE_MAX 75 // 每行采集的点数,即列数
#define ROW_MAX 95 // 采集到的行数
/*************变量定义**************************/
uchar a,b,c,temp;
unsigned char Image[ROW_MAX][LINE_MAX];//图像数据
uchar John[ROW_MAX][LINE_MAX];
uchar row1; //图像数组行数
uchar rowjd;
uchar counter2;
uint i;
uint j;
uint k;
uint h;
uint l;
uint sign;
static unsigned char space=0; //记录行中断
/***************变量及数组初始化****************/
void InitVariable(void)
{
counter2=0;
// k=550;
for(i=0;i<ROW_MAX;i++)
for(j=0;j<LINE_MAX;j++)
Image[i][j]=0;
}
/*************主频设置**************************/
void Busclock(void) //05,01 48MHz 06,01 56MHz 07,01 64MHz 08,01 72MHz
{
CLKSEL=0x00;
PLLCTL_PLLON=1;
SYNR=0xC0 | 0x08;
REFDV=0xC0 | 0x01;
POSTDIV=0x00;
_asm(nop);
_asm(nop);
while(!(CRGFLG_LOCK==1));
CLKSEL_PLLSEL =1;
}
/*************定时器初始化***********************/
void InitEct(void)
{
TIOS=0x00; //外部输入捕捉0,1通道
TCTL4=0x09; //通道0上升沿触发,通道1下降沿触发
TSCR1=0x80;
TIE_C1I = 1; //场中断使能
TIE_C0I = 1; //行中断使能
}
unsigned char SciRead()
{
if(SCI0SR1_RDRF==1) //表明数据从位移寄存器传输到SCI 数据寄存器
{
SCI0SR1_RDRF=1; //读取数据寄存器会将RDRF 清除重新置位
return SCI0DRL; //返回数据寄存器的数据
}
}
/*************串口初始化*************************/
void SciInit()
{
SCI0BD=52; //9600bps Baud Rate=BusClock/(16*SCIBD)
SCI0CR1=0; //正常8 位模式,无奇偶校验
SCI0CR2=0X2C; //发送允许接受中断允许
}
/*************I/O初始化*************************/
void InitIoport(void)
{
DDRA=0x00;
}
/**************发射端程序************************/
void SciTx(uchar text)
{
while (!(SCI0SR1&0x80));
SCI0DRH=0;
SCI0DRL=text;
}
/**************发射端程序************************/
void SciTxs(uchar *s)
{
while (!(SCI0SR1&0x80));
SCI0DRH=0;
while(*s!='\0'){
SCI0DRL=*s;
s++;
}
}
/**************延时******************************/
void Delay(int delay)
{ int i,j;
for(i=0;i<delay;i++)
{for(j=0;j<500;j++)
asm nop;
}
}
/*************主函数*****************************/
void main()
{
DisableInterrupts;
Busclock();
InitEct();
SciInit();
InitVariable();
InitIoport();
EnableInterrupts;
Delay(4000);
for(;;)
{
}
}
/**********场中断处理******************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 9 Port1_interrupt(void)
{
TFLG1=0x02;
TIE_C0I = 1; //开行中断
row1 = 0;
rowjd=0;
sign=0;
if(counter2==1)
{
TIE_C1I = 0;
TIE_C0I = 0;
}
counter2++;
}
/**************行中断采集*************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED //开始一段赋值是起延时的作用,调中心是加减就行了
void interrupt 8 Port0_interrupt(void)
{
TFLG1=0x01; //清除行中断标志
rowjd++;
if(rowjd%2==0)
{
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][0] = PORTA;
Image[row1][1] = PORTA;
Image[row1][1] = PORTA;
Image[row1][2] = PORTA;
Image[row1][2] = PORTA;
Image[row1][3] = PORTA;
Image[row1][3] = PORTA;
Image[row1][4] = PORTA;
Image[row1][4] = PORTA;
Image[row1][5] = PORTA;
Image[row1][5] = PORTA;
Image[row1][6] = PORTA;
Image[row1][6] = PORTA;
Image[row1][7] = PORTA;
Image[row1][7] = PORTA;
Image[row1][8] = PORTA;
Image[row1][8] = PORTA;
Image[row1][9] = PORTA;
Image[row1][9] = PORTA;
Image[row1][10] = PORTA;
Image[row1][10] = PORTA;
Image[row1][11] = PORTA;
Image[row1][11] = PORTA;
Image[row1][12] = PORTA;
Image[row1][12] = PORTA;
Image[row1][13] = PORTA;
Image[row1][13] = PORTA;
Image[row1][14] = PORTA;
Image[row1][14] = PORTA;
Image[row1][15] = PORTA;
Image[row1][15] = PORTA;
Image[row1][16] = PORTA;
Image[row1][16] = PORTA;
Image[row1][17] = PORTA;
Image[row1][17] = PORTA;
Image[row1][18] = PORTA;
Image[row1][18] = PORTA;
Image[row1][19] = PORTA;
Image[row1][19] = PORTA;
Image[row1][20] = PORTA;
Image[row1][20] = PORTA;
Image[row1][21] = PORTA;
Image[row1][21] = PORTA;
Image[row1][22] = PORTA;
Image[row1][22] = PORTA;
Image[row1][23] = PORTA;
Image[row1][23] = PORTA;
Image[row1][24] = PORTA;
Image[row1][24] = PORTA;
Image[row1][25] = PORTA;
Image[row1][25] = PORTA;
Image[row1][26] = PORTA;
Image[row1][26] = PORTA;
Image[row1][27] = PORTA;
Image[row1][27] = PORTA;
Image[row1][28] = PORTA;
Image[row1][28] = PORTA;
Image[row1][29] = PORTA;
Image[row1][29] = PORTA;
Image[row1][30] = PORTA;
Image[row1][30] = PORTA;
Image[row1][31] = PORTA;
Image[row1][31] = PORTA;
Image[row1][32] = PORTA;
Image[row1][32] = PORTA;
Image[row1][33] = PORTA;
Image[row1][33] = PORTA;
Image[row1][34] = PORTA;
Image[row1][34] = PORTA;
Image[row1][35] = PORTA;
Image[row1][35] = PORTA;
Image[row1][36] = PORTA;
Image[row1][36] = PORTA;
Image[row1][37] = PORTA;
Image[row1][37] = PORTA;
Image[row1][38] = PORTA;
Image[row1][38] = PORTA;
Image[row1][39] = PORTA;
Image[row1][39] = PORTA;
Image[row1][40] = PORTA;
Image[row1][40] = PORTA;
Image[row1][41] = PORTA;
Image[row1][41] = PORTA;
Image[row1][42] = PORTA;
Image[row1][42] = PORTA;
Image[row1][43] = PORTA;
Image[row1][43] = PORTA;
Image[row1][44] = PORTA;
Image[row1][44] = PORTA;
Image[row1][45] = PORTA;
Image[row1][45] = PORTA;
Image[row1][46] = PORTA;
Image[row1][46] = PORTA;
Image[row1][47] = PORTA;
Image[row1][47] = PORTA;
Image[row1][48] = PORTA;
Image[row1][48] = PORTA;
Image[row1][49] = PORTA;
Image[row1][49] = PORTA;
Image[row1][50] = PORTA;
Image[row1][50] = PORTA;
Image[row1][51] = PORTA;
Image[row1][51] = PORTA;
Image[row1][52] = PORTA;
Image[row1][52] = PORTA;
Image[row1][53] = PORTA;
Image[row1][53] = PORTA;
Image[row1][54] = PORTA;
Image[row1][54] = PORTA;
Image[row1][55] = PORTA;
Image[row1][55] = PORTA;
Image[row1][56] = PORTA;
Image[row1][56] = PORTA;
Image[row1][57] = PORTA;
Image[row1][57] = PORTA;
Image[row1][58] = PORTA;
Image[row1][58] = PORTA;
Image[row1][59] = PORTA;
Image[row1][59] = PORTA;
Image[row1][60] = PORTA;
Image[row1][60] = PORTA;
Image[row1][61] = PORTA;
Image[row1][61] = PORTA;
Image[row1][62] = PORTA;
Image[row1][62] = PORTA;
Image[row1][63] = PORTA;
Image[row1][63] = PORTA;
Image[row1][64] = PORTA;
Image[row1][64] = PORTA;
Image[row1][65] = PORTA;
Image[row1][65] = PORTA;
Image[row1][66] = PORTA;
Image[row1][66] = PORTA;
Image[row1][67] = PORTA;
Image[row1][67] = PORTA;
Image[row1][68] = PORTA;
Image[row1][68] = PORTA;
Image[row1][69] = PORTA;
Image[row1][69] = PORTA;
Image[row1][70] = PORTA;
Image[row1][70] = PORTA;
Image[row1][71] = PORTA;
Image[row1][71] = PORTA;
Image[row1][72] = PORTA;
Image[row1][72] = PORTA;
Image[row1][73] = PORTA;
Image[row1][73] = PORTA;
Image[row1][74] = PORTA;
Image[row1][74] = PORTA;
row1++;
if(row1==ROW_MAX)
{
TIE_C0I = 0;
TIE_C1I = 0;
sign=1;
}
}
}
#pragma CODE_SEG NON_BANKED
void interrupt 20 SCI0_re(void)
{
if(SciRead()=='s')
{
SciTx(0x55);
SciTx(0xAA);
SciTxs("095075");
if(sign==1){
for(i=0;i<ROW_MAX;i++)
for(j=7;j<LINE_MAX-7;j++){
SciTx(Image[i][j]);
if(j=LINE_MAX-7)
SciTx('\n');
}
}
}
}
复制代码
作者:
cjinxing
时间:
2011-6-10 18:20
下面是通信协议上位机(PC机)
点击“采集图像”按钮后,将通过串口发送一个字符‘s’给下位机,表示采集图像开始。
下位机(单片机)
下位机通过串口收到采集图像命令后,先返回应答信号,应答信号为两个字节,分别为16进制的0x55,0xAA。
接着发送图像的宽度值W和高度值H,各占三个字节,比如宽度W为40,高度H为30,则发送字符串‘040030’。又如宽度W为320,高度H为240,则发送字符串‘320240’。
接下来按顺序发送W*H个图像像素点的灰度值,每个灰度值为一个字节(数值大小范围0-255)。
作者:
夏天C的微笑
时间:
2012-3-15 21:02
程序真长啊。。。。。本来打算研究一下的
作者:
wacsysys
时间:
2012-4-9 16:52
ding
欢迎光临 智能车制作 (http://dns.znczz.com/)
Powered by Discuz! X3.2