参考原子哥发的f429+ov5640识别二维码的代码,我修改部分代码后想在407上跑,然而编译能通过但是显示的是一坨黑 {MOD},lcd也没有摄像头传来数据。
ov5640是没问题的,应该是我代码的问题,所以想请各位大佬帮忙看一下:
[mw_shl_code=applescript,true]#include "sys.h"
#include "delay.h"
#include "lcd.h"
#include "usart.h"
#include "sram.h"
#include "malloc.h"
#include "string.h"
#include "dcmi.h"
#include "ov5640.h"
#include "led.h"
#include "key.h"
#include "beep.h"
#include "sdio_sdcard.h"
#include "ff.h"
#include "w25qxx.h"
#include "exfuns.h"
#include "fontupd.h"
#include "text.h"
#include "atk_qrdecode.h"
//////////////////////////////////////////////////////////////////////////////////
//±¾3ìDòÖ»1©Ñ§Ï°ê1óã¬Î′¾-×÷ÕßDí¿é£¬2»μÃóÃóúÆäËüèÎoÎóÃí¾
//ALIENTEK STM32F407¿a·¢°å à©Õ1êμÑéSE01
//¶tάÂëìõDÎÂë궱eêμÑé
//ÕyμãÔ-×ó@ALIENTEK
//¼¼êõÂÛì3:
www.openedv.com
//′′½¨èÕÆú:2016/6/7
//°æ±¾£oV1.0
//°æè¨ËùóD£¬μá°æ±Ø¾¿¡£
//Copyright(C) 1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾ 2014-2024
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
u16 qr_image_width; //êäèë궱eí¼ÏñμÄ¿í¶è£¨3¤¶è=¿í¶è£©
u8 readok=0; //2é¼ˉíêò»Ö¡êy¾Y±êê¶
u32 *dcmi_line_buf[2]; //éãÏñí·2éóÃò»DDò»DD¶áè¡,¶¨òåDD»o′æ
u16 *rgb_data_buf; //RGB565Ö¡»o′æbuf
u16 dcmi_curline=0; //éãÏñí·êä3öêy¾Y,μ±Ç°DD±àoÅ
//éãÏñí·êy¾YDMA½óêÕíê3éÖD¶Ï»Øμ÷oˉêy
void qr_dcmi_rx_callback(void)
{
u32 *pbuf;
u16 i;
pbuf=(u32*)(rgb_data_buf+dcmi_curline*qr_image_width);//½«rgb_data_bufμØÖ·Æ«òƸ3Öμ¸øpbuf
if(DMA2_Stream1->CR&(1<<19))//DMAê1óÃbuf1,¶áè¡buf0
{
for(i=0;i<qr_image_width/2;i++)
{
pbuf
=dcmi_line_buf[0];
}
}else //DMAê1óÃbuf0,¶áè¡buf1
{
for(i=0;i<qr_image_width/2;i++)
{
pbuf=dcmi_line_buf[1];
}
}
dcmi_curline++;
}
//ÏÔê¾í¼Ïñ
//imagewidth:<=240;′óóú240ê±,êÇ240μÄÕûêy±¶
//imagebuf:RGBí¼Ïñêy¾Y»o3åÇø
void qr_decode(u16 imagewidth,u16 *imagebuf)
{
static u8 bartype=0;
u8 *bmp;
u8 *result=NULL;
u16 Color;
u16 i,j;
u16 qr_img_width=0; //êäèë궱eÆ÷μÄí¼Ïñ¿í¶è,×î′ó2»3¬1y240!
u8 qr_img_scale=0; //Ñ1Ëõ±èàyòò×ó
if(imagewidth>240)
{
if(imagewidth%240)return ; //2»êÇ240μı¶êy,Ö±½óíË3ö
qr_img_width=240;
qr_img_scale=imagewidth/qr_img_width;
}else
{
qr_img_width=imagewidth;
qr_img_scale=1;
}
result=mymalloc(SRAMIN,1536);//éêÇë궱e½á1û′æ·ÅÄú′æ
bmp=mymalloc(SRAMCCM,qr_img_width*qr_img_width);//CCM1üàíÄú′æÎa60K£¬Õaàï×î′ó¿ééêÇë240*240=56K
mymemset(bmp,0,qr_img_width*qr_img_width);
for(i=0;i<qr_img_width;i++)
{
for(j=0;j<qr_img_width;j++) //½«RGB565í¼Æ¬×a3é»ò¶è
{
Color=*(imagebuf+((i*imagewidth)+j)*qr_img_scale); //°′ÕÕqr_img_scaleÑ1Ëõ3é240*240
*(bmp+i*qr_img_width+j)=(((Color&0xF800)>> 8)*76+((Color&0x7E0)>>3)*150+((Color&0x001F)<<3)*30)>>8;
}
}
atk_qr_decode(qr_img_width,qr_img_width,bmp,bartype,result);//궱e»ò¶èí¼Æ¬£¨×¢òa£oμ¥′ÎoÄê±Ô¼0.2S£©
if(result[0]==0)//ûóD궱e3öà′
{
bartype++;
if(bartype>=5)bartype=0;
}
else if(result[0]!=0)//궱e3öà′áË£¬ÏÔê¾½á1û
{
BEEP=1;//′ò¿a·äÃùÆ÷
delay_ms(100);
BEEP=0;
POINT_COLOR=BLUE;
LCD_Fill(0,(lcddev.height+qr_image_width)/2+20,lcddev.width,lcddev.height,BLACK);
Show_Str(0,(lcddev.height+qr_image_width)/2+20,lcddev.width,
(lcddev.height-qr_image_width)/2-20,(u8*)result,16,0
);//LCDÏÔê¾ê¶±e½á1û
printf("
result:
%s
",result);//′®¿ú′òó¡ê¶±e½á1û
}
myfree(SRAMCCM,bmp); //êí·Å»ò¶èí¼bmpÄú′æ
myfree(SRAMIN,result); //êí·Å궱e½á1û
}
int main(void)
{
float fac;
u8 key;
u8 i;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÏμí3ÖD¶ÏóÅÏ輶·Ö×é2
delay_init(168); //3õê¼»ˉÑóê±oˉêy
uart_init(115200);
LED_Init();
BEEP_Init();
KEY_Init();
LCD_Init();
FSMC_SRAM_Init(); //3õê¼»ˉía2¿SRAM.
my_mem_init(SRAMIN); //3õê¼»ˉÄú2¿Äú′æ3Ø
my_mem_init(SRAMEX); //3õê¼»ˉÄú2¿Äú′æ3Ø
my_mem_init(SRAMCCM); //3õê¼»ˉCCMÄú′æ3Ø
W25QXX_Init(); //3õê¼»ˉW25Q128
POINT_COLOR=RED; //éèÖÃ×ÖìåÎaoìé«
LCD_Clear(BLACK);
while(font_init()) //¼ì2é×Ö¿a
{
LCD_ShowString(60,50,lcddev.width,16,16,(u8*)"Font Error!");
delay_ms(200);
LCD_Fill(60,50,lcddev.width,66,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
Show_Str_Mid(0,0,(u8*)"ì½Ë÷ÕßF4¿a·¢°å",16,lcddev.width);
Show_Str_Mid(0,20,(u8*)"¶tάÂë/ìõDÎÂë궱eêμÑé",16,lcddev.width);
while(OV5640_Init()) //3õê¼»ˉOV2640
{
LCD_ShowString(60,50,lcddev.width,16,16,(u8*)"OV2640 Error!");
delay_ms(200);
LCD_Fill(60,50,lcddev.width,66,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
OV5640_RGB565_Mode(); //RGB565Ä£ê½
OV5640_Focus_Init();
OV5640_Light_Mode(0); //×Ô¶ˉÄ£ê½
OV5640_Color_Saturation(3); //é«2ê±¥oí¶è0
OV5640_Brightness(4); //áá¶è0
OV5640_Contrast(3); //¶Ô±è¶è0
OV5640_Sharpness(33); //×Ô¶ˉèñ¶è
OV5640_Focus_Constant();//Æô¶ˉ3ÖDø¶Ô½1
My_DCMI_Init(); //DCMIÅäÖÃ
qr_image_width=lcddev.width;
if(qr_image_width>480)qr_image_width=480;//Õaàïqr_image_widthéèÖÃÎa240μı¶êy
if(qr_image_width==320)qr_image_width=240;
Show_Str(0,(lcddev.height+qr_image_width)/2+4,240,16,(u8*)"궱e½á1û£o",16,1);
dcmi_line_buf[0]=mymalloc(SRAMIN,qr_image_width*2); //ÎaDD»o′æ½óêÕéêÇëÄú′æ
dcmi_line_buf[1]=mymalloc(SRAMIN,qr_image_width*2); //ÎaDD»o′æ½óêÕéêÇëÄú′æ
rgb_data_buf=mymalloc(SRAMEX,qr_image_width*qr_image_width*2);//ÎargbÖ¡»o′æéêÇëÄú′æ
dcmi_rx_callback=qr_dcmi_rx_callback;//DMAêy¾Y½óêÕÖD¶Ï»Øμ÷oˉêy
DCMI_DMA_Init(
(u32)dcmi_line_buf[0],(u32)dcmi_line_buf[1],
qr_image_width/2,DMA_MemoryDataSize_HalfWord,DMA_MemoryInc_Enable
);//DCMI DMAÅäÖÃ
fac=800/qr_image_width; //μÃμ½±èàyòò×ó
OV5640_OutSize_Set((1280-fac*qr_image_width)/2,(800-fac*qr_image_width)/2,qr_image_width,qr_image_width);
DCMI_Start();
printf("SRAM IN:%d
",my_mem_perused(SRAMIN));
printf("SRAM EX:%d
",my_mem_perused(SRAMEX));
printf("SRAM CCM:%d
",my_mem_perused(SRAMCCM));
atk_qr_init();//3õê¼»ˉ궱e¿a£¬ÎaËã·¨éêÇëÄú′æ
printf("1SRAM IN:%d
",my_mem_perused(SRAMIN));
printf("1SRAM EX:%d
",my_mem_perused(SRAMEX));
printf("1SRAM CCM:%d
",my_mem_perused(SRAMCCM));
while(1)
{
key=KEY_Scan(0);//2»Ö§3Öᬰ′
if(key)
{
OV5640_Focus_Single(); //°′KEY0¡¢KEY1¡¢KEYUPêÖ¶ˉμ¥′Î×Ô¶ˉ¶Ô½1
if(key==KEY2_PRES)break;//°′KEY2½áêø궱e
}
if(readok==1) //2é¼ˉμ½áËò»Ö¡í¼Ïñ
{
readok=0;
LCD_Color_Fill((lcddev.width-qr_image_width)/2,(lcddev.height-qr_image_width)/2,(qr_image_width+(lcddev.width-qr_image_width)/2)-1,(qr_image_width+(lcddev.height-qr_image_width)/2)-1,rgb_data_buf );//????
qr_decode(qr_image_width,rgb_data_buf);
}
i++;
if(i==20)//DS0éá˸.
{
i=0;
LED0=!LED0;
}
}
atk_qr_destroy();//êí·ÅËã·¨Äú′æ
printf("3SRAM IN:%d
",my_mem_perused(SRAMIN));
printf("3SRAM EX:%d
",my_mem_perused(SRAMEX));
printf("3SRAM CCM:%d
",my_mem_perused(SRAMCCM));
while(1)
{
LED0=!LED0;
delay_ms(200);
}
}
[/mw_shl_code]
文字都是乱码,我直接附上工程
一周热门 更多>