金牌会员
- 积分
- 2172
- 威望
- 1119
- 贡献
- 505
- 兑换币
- 476
- 注册时间
- 2012-8-28
- 在线时间
- 274 小时
|
摄像头上位机没图像 串口发送的数据全是00
#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 waitimage(int num) //行消隐过度;
{
unsigned int i,j;
for(i=0;i<num;i++)
for(j=0;j<33;j++);
}
void imageinit()
{
for(image_row=0;image_row<48;image_row++)
for(image_column=0;image_column<100;image_column++)
{
image_buf1[image_row][image_column]=0;
image_buf2[image_row][image_column]=0;
}
image_row=0;
image_column=0;
}
/******************初始化**************************************/
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转换初始化,16位精度
LPLD_UART_Init(UART1, 9600); //串口初始化,TxdTC4 Rxd:PTC3
imageinit();
}
/******************行中断触发采样************************/
void image_collect()
{
DisableInterrupts;
int count=100;
waitimage(2);
if(image_row<48)
{
for(count=100;count>0;count--)
{
ADresult= LPLD_ADC_SE_Get(ADC0, 9); //ptb1
image_buf1[image_row][image_column++]=ADresult;
}
image_column=0;
image_row++;
}
EnableInterrupts;
}
/************将得到的像素数据通过串口发送至上位机*************************/
void image_uart_send()
{
image_row=0;
image_column=0;
for(image_row=0;image_row<48;image_row++)
for(image_column=0;image_column<100;image_column++)
LPLD_UART_PutChar(UART1,image_buf1[image_row][image_column]);
}
/***********************场中断对图像进行处理**********************************/
void image_process()
{
DisableInterrupts;
waitimage(1);
image_row=0;
image_column=0;
LPLD_UART_RIE_Disable(UART1);
image_uart_send();
EnableInterrupts;
}
/**************************主函数*************************************/
void main (void)
{
DisableInterrupts;
systeminit();
EnableInterrupts;
LPLD_GPIO_SetIsr (PTB, image_collect);
LPLD_GPIO_SetIsr (PTC, image_process);
while(1);
}
|
|