我用的STM32F103采集摄像头OV7670(带FIFO)的图像,在LCD上显示的图像没什么问题,但是当把图片存到SD卡里,颜 {MOD}就不对了。我往SD卡里存,用到了文件系统,首先新建一个文件,先写入54个字节的BMP文件字头,然后再写入图像数据,生成的bmp图像颜 {MOD}有问题,请教一下是怎么回事。
这是BMP文件字头:const unsigned char bmp_header[54]={
0x42,0x4D,0x36,0x58,0x02,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
0x00,0x00,0x40,0x01,0x00,0x00,0xF0,0x00,0x00,0x00,0x01,0x00,16,0x00,0x00,0x00,
0x00,0x00,0x00,0x58,0x02,0x00,0x12,0x0B,0x00,0x00,0x12,0x0B,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00
};
这是拍照的程序
if(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_2)==0)
{
delay(100);
if(GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_2)==0)
{
while(Vsync_Flag!=2);
//EXTI->IMR&=~(1<<4); //½ûÖ1ía2¿ÖD¶Ï£¬×¼±¸′óFIFOÖDè¡êy¾Y
//EXTI->EMR&=~(1<<4);
while(index<0XFFFF)
{
sprintf((char*)pnam,"0:/PHOTO/PIC%05d.bmp",index);
res=f_open(&fsrc,(char*)pnam,FA_READ|FA_WRITE);//3¢êÔ′ò¿aÕa¸öÎļt
if(res==FR_NO_FILE)
break; //¸ÃÎļtÃû2»′æÔú=ÕyêÇÎòÃÇDèòaμÄ.
f_close(&fsrc);
index++;
}
printf("ÕyÔúÅÄéãμú%dÕÅ
",index);
res=f_open(&fsrc,(char*)pnam,FA_CREATE_NEW|FA_WRITE);
f_close(&fsrc);
res=f_open(&fsrc,(char*)pnam,FA_OPEN_EXISTING|FA_WRITE);
//printf("%d
",res);
res=f_write(&fsrc,bmp_header,54,&bw);
//printf("%d
",res);
Vsync_Flag=0;
FIFO_RRST=0; //FIFO¶áÖ¸Õë¸′λ
FIFO_RCK=0;
FIFO_RCK=1;
FIFO_RCK=0;
FIFO_RRST=1;
FIFO_RCK=1;
for(j=0;j<200;j++)
{
read_data(96,receive_data);
res=f_write(&fsrc,receive_data,192,&bw);
read_data(96,receive_data);
res=f_write(&fsrc,receive_data,192,&bw);
read_data(96,receive_data);
res=f_write(&fsrc,receive_data,192,&bw);
read_data(96,receive_data);
res=f_write(&fsrc,receive_data,192,&bw);
}
f_close(&fsrc);
printf("finished
");
EXTI->PR=1<<4;
Vsync_Flag=0;
//EXTI->IMR|=(1<<4); //ÔêDíía2¿ÖD¶Ï£¬òÔ±ã½óêÕÏÂÖ¡í¼Ïñêy¾Y
//EXTI->EMR|=(1<<4);
}
}
void read_data(unsigned int len,unsigned char *pbuf)
{
unsigned int i;
for(i=0;i<len;i++)
{
FIFO_RCK=0;
*(pbuf+1)=(0x00ff&GPIOB->IDR);
FIFO_RCK=1;
FIFO_RCK=0;
*(pbuf)=(0x00ff&GPIOB->IDR);
FIFO_RCK=1;
pbuf+=2;
}
}
我觉的应该不是程序问题
此帖出自
小平头技术问答
一周热门 更多>