金牌会员
- 积分
- 2172
- 威望
- 1119
- 贡献
- 505
- 兑换币
- 476
- 注册时间
- 2012-8-28
- 在线时间
- 274 小时
|
用的是拉普兰德的底层库 但是上位机接收不到数据,,求大神指点
#include "common.h"
#include "HAL_ADC.h"
#include "HAL_FTM.h"
#include "HAL_GPIO.h"
#include "HAL_UART.h"
unsigned char image_buf1[48][100];
unsigned char image_buf2[48][100];
unsigned char image_trans[48][100];
unsigned int image_row=0;
unsigned int image_column=0;
uint16 ADresult;
void nop()
{}
void waitimage(int num) //行消隐过度;
{
unsigned int i,j;
for(i=0;i<num;i++)
for(j=0;j<33;j++);
}
/******************初始化**************************************/
void systeminit()
{
LPLD_GPIO_Init(PTB, 10, DIR_INPUT, INPUT_PDOWN, IRQC_RI );//行中断,PTB10
LPLD_GPIO_Init(PTC, 10, DIR_INPUT, INPUT_PDOWN, IRQC_RI );//场中断,PTC10
LPLD_ADC_Init(ADC0, MODE_16, CONV_SING);//ad转换初始化,pta7,16位精度
LPLD_UART_Init(UART1, 115200); //串口初始化,TxdTC4 Rxd:PTC3
}
/******************行中断触发采样************************/
void image_collect()
{
int count=100;
waitimage(2);
if(image_row<48)
{
for(count;count>0;count--)
{
ADresult= LPLD_ADC_SE_Get(ADC0, 10);
image_buf1[image_row][image_column++]=ADresult;
}
image_column=0;
image_row++;
waitimage(2);
}
else
nop();
}
/***********************对图像进行二值化处理*************************/
void imagetrans(unsigned char start,unsigned char end,unsigned char contrst)
{
unsigned char i,j;
unsigned char a,b,c;
unsigned char num,temp,max,min;
unsigned char max_temp,min_temp;
unsigned char Max_num[10],Min_num[10];
unsigned char hang_end,hang_start;
unsigned char total_max,total_min;
unsigned char contr;
total_max=0;
total_min=0;
contr=contrst;
hang_end=end;
hang_start=start;
for(i=hang_start;i<hang_end;i++)
{
for(j=0;j<image_column;j=j+3)
{
num=j;
a=image_buf1[15][num];
num=num+1;
b=image_buf1[15][num];
num=num+2;
c=image_buf1[15][num];
min_temp=(a+b+c)/3;
if(min>max)
{
temp=min_temp;
min_temp=max_temp;
max_temp=temp;
}
}
Max_num[i]=max_temp;
Min_num[i]=min_temp;
}
for(i=hang_start;i<hang_end;i++)
{
total_max=total_max+Max_num[i];
total_min=total_min+Min_num[i];
}
/***********************处理完毕****************************/
max=total_max/(hang_end-hang_start)*(1-contr/100) ; // white
min=total_min/(hang_end-hang_start)*(1+contr/100) ; // black
/********************将处理完毕的图像保存************************/
for(i=0;i<image_row;i++) //行
{
for(j=0; j<image_column; j++) //列
{
if(image_buf1[i][j]>=max) image_buf2[i][j]=1;
if(image_buf1[i][j]<=min) image_buf2[i][j]=0;
}
}
}
/************将得到的像素数据通过串口发送至上位机*************************/
void image_uart_send()
{
image_row=0;
image_column=0;
for(image_row;image_row<48;image_row++)
for(image_column;image_column<100;image_column++)
LPLD_UART_PutChar(UART1,image_buf2[image_row][image_column]);
}
void image_process()
{
DisableInterrupts;
waitimage(1);
image_row=0;
image_column=0;
imagetrans(4,8,10);
image_uart_send();
EnableInterrupts;
}
void main (void)
{
DisableInterrupts;
systeminit();
while(1)
{
EnableInterrupts;
LPLD_GPIO_SetIsr (PTB, image_collect);
LPLD_GPIO_SetIsr (PTC, image_process);
while(1);
}
}
|
|