中级会员
- 积分
- 332
- 威望
- 176
- 贡献
- 88
- 兑换币
- 102
- 注册时间
- 2013-3-13
- 在线时间
- 34 小时
|
这是我参照别人程序写的图像采集,但是老是出不来图像,求懂得人指导,谢谢了!!!!
#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
#define ROW 30
#define COLUMN 130
#define ROW_START 40
#define ROW_MAX 304
#define COLUMN_MIN 1
#define COLUMN_MAX 100
#define ROW1_MIN 2
#define ROW1_MAX (ROW-3)
#define WHITE 1
#define BLACK 0
#define THRESHOLD 0x20
unsigned char Image_Data[ROW][COLUMN];
unsigned char Image_Data1[ROW][COLUMN];
unsigned char *puc_Process = &Image_Data1[0][0];
unsigned char *puc_Process1 = &Image_Data[0][0];
unsigned int Line = 0;
unsigned char SampleFlag = 0;
unsigned char m = 0;
/****************************************************************
** 函数名称: PLL_init
** 函数功能: 锁相环初始化
*****************************************************************/
void PLL_init(void)
{
CLKSEL = 0x00;
PLLCTL_PLLON = 1;
SYNR = 4;
REFDV = 1;
POSTDIV = 0x00;
_asm(nop);
_asm(nop);
while(0 == CRGFLG_LOCK);
CLKSEL_PLLSEL = 1;
}
/***************************************************************
** 函数名称: TIM_init
** 函数功能: 行场中断初始化
****************************************************************/
void TIM_init(void)
{
TIOS = 0x00;
TCTL4 = 0x09;
TSCR1 = 0x80;
TIE = 0x03;
TFLG1 = 0xFF;
}
/**************************************************************
** 函数名称: SCI_init
** 函数功能: 串口初始化
***************************************************************/
void SCI_init(void)
{
SCI0BD = 260;
SCI0CR1 = 0;
SCI0CR2 = 0x2C;
}
/***************************************************************
** 函数名称: IO_init
** 函数功能: IO初始化
****************************************************************/
void IO_init(void)
{
DDRA = 0x00;
}
/**************************************************************
** 图像名称: SCI_Write
** 函数功能: 串口发送数据
***************************************************************/
void SCI_Write(unsigned char sendchar)
{
while(!(SCI0SR1&80));
SCI0DRH = 0;
SCI0DRL = sendchar;
}
/*************************************************************
** 函数功能: 膨胀法去除噪声
** 函数名称: vImageCalcute
**************************************************************/
void vImageCalcute(void)
{
unsigned char ucRow,ucColumn;
unsigned char *pucTemp;
for(ucColumn = COLUMN_MIN; ucColumn < COLUMN_MAX; ucColumn++)
{
for(ucRow = ROW1_MIN; ucRow < ROW1_MAX; ucRow++)
{
pucTemp = puc_Process + ucRow*COLUMN+ucColumn;
if(*(pucTemp) == WHITE)
{
if(*(pucTemp - COLUMN) == BLACK && *(pucTemp + COLUMN) == BLACK)
{
*pucTemp = BLACK;
ucRow++;
}
}
}
}
for(ucColumn = COLUMN_MIN; ucColumn < COLUMN_MAX; ucColumn++)
{
for(ucRow = ROW1_MIN; ucRow < ROW1_MAX; ucRow++)
{
pucTemp = puc_Process + ucRow*COLUMN+ucColumn;
if(*(pucTemp) == BLACK)
{
if(*(pucTemp - COLUMN) == WHITE && *(pucTemp + COLUMN) == WHITE)
{
*pucTemp = BLACK;
ucRow++;
}
}
}
}
}
/*************************************************************
** 函数名称: delayms
** 函数功能: 延时函数
**************************************************************/
void delayms(long ms)
{
while(ms--);
}
/**************************************************************
** 函数名称: Binaryzation
** 函数功能: 图像二值化
***************************************************************/
void Binaryzation(unsigned char row)
{
unsigned char *q_Image,*p_Image;
q_Image = &Image_Data1[row][0];
for(p_Image = &Image_Data[row][0]; p_Image <= &Image_Data[row][COLUMN-1]; p_Image++)
{
if(*(p_Image) < THRESHOLD && *(p_Image+1) < THRESHOLD)
*(q_Image++) = BLACK;
else
*(q_Image++) = WHITE;
}
}
/************************************************************
** 函数名称: Process
** 函数功能: 将数据传送到上位机
*************************************************************/
void Process(void)
{
unsigned char i,j;
unsigned char *Temp;
SCI_Write(0x01);
for(i = 0; i < ROW; i++)
{
Temp = &Image_Data[i][0];
for(j = 3; j < COLUMN; j++)
{
if(*Temp > THRESHOLD) SCI_Write('1');
else SCI_Write('0');
}
}
SCI_Write(0x0D);
SCI_Write(0X0A);
}
void main(void) {
/* put your own code here */
PLL_init();
TIM_init();
SCI_init();
IO_init();
EnableInterrupts;
for(;;) {
vImageCalcute();
Process();
_FEED_COP(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave main */
}
/****************************************************************
** Interrupt functions start HERE!!!
****************************************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
void interrupt 8 PT0_Interrupt()
{
unsigned char Interval;
unsigned char *pucTemp;
TFLG1_C0F=1;
delayms(3);
Line++;
if ( SampleFlag == 0 || Line<ROW_START || Line>ROW_MAX )
{
return;
}
if(Line<=132) Interval= 16;
if(Line>132&&Line<=200) Interval= 12;
if(Line>200&&Line<=248) Interval= 8;
if(Line > 248) Interval=4;
if(Line % Interval == 0 && m < ROW)
{
pucTemp = &Image_Data[m][0];
*(pucTemp + 0) = PORTA;_asm();*(pucTemp + 1) = PORTA;_asm();*(pucTemp + 2) = PORTA;_asm();*(pucTemp + 3) = PORTA;_asm();
*(pucTemp + 4) = PORTA;_asm();*(pucTemp + 5) = PORTA;_asm();*(pucTemp + 6) = PORTA;_asm();*(pucTemp + 7) = PORTA;_asm();
*(pucTemp + 8) = PORTA;_asm();*(pucTemp + 9) = PORTA;_asm();*(pucTemp + 10) = PORTA;_asm();*(pucTemp + 11) = PORTA;_asm();
*(pucTemp + 12) = PORTA;_asm();*(pucTemp + 13) = PORTA;_asm();*(pucTemp + 14) = PORTA;_asm();*(pucTemp + 15) = PORTA;_asm();
*(pucTemp + 16) = PORTA;_asm();*(pucTemp + 17) = PORTA;_asm();*(pucTemp + 18) = PORTA;_asm();*(pucTemp + 19) = PORTA;_asm();
*(pucTemp + 20) = PORTA;_asm();*(pucTemp + 21) = PORTA;_asm();*(pucTemp + 22) = PORTA;_asm();*(pucTemp + 23) = PORTA;_asm();
*(pucTemp + 24) = PORTA;_asm();*(pucTemp + 25) = PORTA;_asm();*(pucTemp + 26) = PORTA;_asm();*(pucTemp + 27) = PORTA;_asm();
*(pucTemp + 28) = PORTA;_asm();*(pucTemp + 29) = PORTA;_asm();*(pucTemp + 30) = PORTA;_asm();*(pucTemp + 31) = PORTA;_asm();
*(pucTemp + 32) = PORTA;_asm();*(pucTemp + 33) = PORTA;_asm();*(pucTemp + 34) = PORTA;_asm();*(pucTemp + 35) = PORTA;_asm();
*(pucTemp + 36) = PORTA;_asm();*(pucTemp + 37) = PORTA;_asm();*(pucTemp + 38) = PORTA;_asm();*(pucTemp + 39) = PORTA;_asm();
*(pucTemp + 40) = PORTA;_asm();*(pucTemp + 41) = PORTA;_asm();*(pucTemp + 42) = PORTA;_asm();*(pucTemp + 43) = PORTA;_asm();
*(pucTemp + 44) = PORTA;_asm();*(pucTemp + 45) = PORTA;_asm();*(pucTemp + 46) = PORTA;_asm();*(pucTemp + 47) = PORTA;_asm();
*(pucTemp + 48) = PORTA;_asm();*(pucTemp + 49) = PORTA;_asm();*(pucTemp + 50) = PORTA;_asm();*(pucTemp + 51) = PORTA;_asm();
*(pucTemp + 52) = PORTA;_asm();*(pucTemp + 53) = PORTA;_asm();*(pucTemp + 54) = PORTA;_asm();*(pucTemp + 55) = PORTA;_asm();
*(pucTemp + 56) = PORTA;_asm();*(pucTemp + 57) = PORTA;_asm();*(pucTemp + 58) = PORTA;_asm();*(pucTemp + 59) = PORTA;_asm();
*(pucTemp + 60) = PORTA;_asm();*(pucTemp + 61) = PORTA;_asm();*(pucTemp + 62) = PORTA;_asm();*(pucTemp + 63) = PORTA;_asm();
*(pucTemp + 64) = PORTA;_asm();*(pucTemp + 65) = PORTA;_asm();*(pucTemp + 66) = PORTA;_asm();*(pucTemp + 67) = PORTA;_asm();
*(pucTemp + 68) = PORTA;_asm();*(pucTemp + 69) = PORTA;_asm();*(pucTemp + 70) = PORTA;_asm();*(pucTemp + 71) = PORTA;_asm();
*(pucTemp + 72) = PORTA;_asm();*(pucTemp + 73) = PORTA;_asm();*(pucTemp + 74) = PORTA;_asm();*(pucTemp + 75) = PORTA;_asm();
*(pucTemp + 76) = PORTA;_asm();*(pucTemp + 77) = PORTA;_asm();*(pucTemp + 78) = PORTA;_asm();*(pucTemp + 79) = PORTA;_asm();
*(pucTemp + 80) = PORTA;_asm();*(pucTemp + 81) = PORTA;_asm();*(pucTemp + 82) = PORTA;_asm();*(pucTemp + 83) = PORTA;_asm();
*(pucTemp + 84) = PORTA;_asm();*(pucTemp + 85) = PORTA;_asm();*(pucTemp + 86) = PORTA;_asm();*(pucTemp + 87) = PORTA;_asm();
*(pucTemp + 88) = PORTA;_asm();*(pucTemp + 89) = PORTA;_asm();*(pucTemp + 90) = PORTA;_asm();*(pucTemp + 91) = PORTA;_asm();
*(pucTemp + 92) = PORTA;_asm();*(pucTemp + 93) = PORTA;_asm();*(pucTemp + 94) = PORTA;_asm();*(pucTemp + 95) = PORTA;_asm();
*(pucTemp + 96) = PORTA;_asm();*(pucTemp + 97) = PORTA;_asm();*(pucTemp + 98) = PORTA;_asm();*(pucTemp + 99) = PORTA;_asm();
*(pucTemp + 100) = PORTA;_asm();*(pucTemp + 101) = PORTA;_asm();*(pucTemp + 102) = PORTA;_asm();*(pucTemp + 103) = PORTA;_asm();
*(pucTemp + 104) = PORTA;_asm();*(pucTemp + 105) = PORTA;_asm();*(pucTemp + 106) = PORTA;_asm();*(pucTemp + 107) = PORTA;_asm();
*(pucTemp + 108) = PORTA;_asm();*(pucTemp + 109) = PORTA;_asm();*(pucTemp + 110) = PORTA;_asm();*(pucTemp + 111) = PORTA;_asm();
*(pucTemp + 112) = PORTA;_asm();*(pucTemp + 113) = PORTA;_asm();*(pucTemp + 114) = PORTA;_asm();*(pucTemp + 115) = PORTA;_asm();
*(pucTemp + 116) = PORTA;_asm();*(pucTemp + 117) = PORTA;_asm();*(pucTemp + 118) = PORTA;_asm();*(pucTemp + 119) = PORTA;_asm();
*(pucTemp + 120) = PORTA;_asm();*(pucTemp + 121) = PORTA;_asm();*(pucTemp + 122) = PORTA;_asm();*(pucTemp + 123) = PORTA;_asm();
*(pucTemp + 124) = PORTA;_asm();*(pucTemp + 125) = PORTA;_asm();*(pucTemp + 126) = PORTA;_asm();*(pucTemp + 127) = PORTA;_asm();
*(pucTemp + 128) = PORTA;_asm();*(pucTemp + 129) = PORTA;_asm();
//Process(m);
m++;
}
else return;
Binaryzation(m);
}
#pragma CODE_SEG __NEAR_SEG NON_BANKED//场中断处理函数
void interrupt 9 PT1_Interrupt()
{
TFLG1_C1F=1;
TFLG1_C0F=1;
m=0;
Line=0;
SampleFlag=1;
}
|
|