找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 12584|回復(fù): 7
收起左側(cè)

stm32F407+ov7670的攝像頭識別(代碼+連接)

  [復(fù)制鏈接]
ID:488078 發(fā)表于 2019-5-12 17:16 | 顯示全部樓層 |閱讀模式
stm32F407單片機(jī)+ov7670攝像頭識別
實驗現(xiàn)象.jpg
單片機(jī)源程序如下:
  1. #include "system.h"
  2. #include "SysTick.h"
  3. #include "led.h"
  4. #include "usart.h"
  5. #include "tftlcd.h"
  6. #include "malloc.h"
  7. #include "sdio_sdcard.h"
  8. #include "flash.h"
  9. #include "ff.h"
  10. #include "fatfs_app.h"
  11. #include "key.h"
  12. #include "font_show.h"
  13. #include "exti.h"
  14. #include "time.h"
  15. #include "string.h"               
  16. #include "math.h"         
  17. #include "OV7670_DCMI.h"



  18. extern u8 ov_sta;        //在exit.c里面定義
  19. extern u8 ov_frame;        //在time.c里面定義

  20. //更新LCD顯示
  21. void camera_refresh(void)
  22. {
  23.         u32 j;
  24.         u16 i;
  25.         u16 color;
  26.         u16 temp;
  27.         if(ov_sta)//有幀中斷更新?
  28.         {
  29.                 LCD_Display_Dir(1);
  30.                 //LCD_Set_Window((tftlcd_data.width-320)/2,(tftlcd_data.height-240)/2,320,240-1);//將顯示區(qū)域設(shè)置到屏幕中央
  31.           LCD_Set_Window(0,(tftlcd_data.height-240)/2,320-1,240-1);//將顯示區(qū)域設(shè)置到屏幕中央
  32.                
  33.                 OV7670_RRST=0;                                //開始復(fù)位讀指針
  34.                 OV7670_RCK_L;
  35.                 OV7670_RCK_H;
  36.                 OV7670_RCK_L;
  37.                 OV7670_RRST=1;                                //復(fù)位讀指針結(jié)束
  38.                 OV7670_RCK_H;
  39.                 /*for(i=0;i<240;i++)   //此種方式可以兼容任何彩屏
  40.                 {
  41.                         for(j=0;j<320;j++)
  42.                         {
  43.                                 OV7670_RCK_L;
  44.                                 color=OV7670_DATA;        //讀數(shù)據(jù)
  45.                                 OV7670_RCK_H;
  46.                                 color>>=8;  
  47.                                 OV7670_RCK_L;
  48.                                 color|=OV7670_DATA;        //讀數(shù)據(jù)
  49.                                 OV7670_RCK_H;
  50.                                 LCD_WriteData_Color(color);
  51.                         }
  52.                 }*/
  53.                 for(j=0;j<76800;j++)   //此種方式需清楚TFT內(nèi)部顯示方向控制寄存器值
  54.                 {
  55.                         OV7670_RCK_L;
  56.                         color=OV7670_DATA;        //讀數(shù)據(jù)
  57.                         OV7670_RCK_H;
  58.                         color<<=8;  
  59.                         OV7670_RCK_L;
  60.                         color|=OV7670_DATA;        //讀數(shù)據(jù)
  61.                         OV7670_RCK_H;
  62.                         LCD_WriteData_Color(color);
  63.                         //printf("%x  ",color);
  64.                         //if(j%20==0)printf("\r\n");
  65.                         //delay_us(50);
  66.                 }                                                            
  67.                 ov_sta=0;                                        //清零幀中斷標(biāo)記
  68.                 ov_frame++;       //統(tǒng)計幀數(shù)
  69.                 LCD_Display_Dir(0);
  70.         }
  71. }

  72. const u8*LMODE_TBL[5]={"Auto","Sunny","Cloudy","Office","Home"};
  73. const u8 *EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"};        //7種特效

  74. int main()
  75. {       
  76.         u8 i=0;
  77.         u8 key;
  78.         u8 lightmode=0,saturation=2,brightness=2,contrast=2;
  79.         u8 effect=0;
  80.         u8 sbuf[15];
  81.         u8 count;
  82.        
  83.         SysTick_Init(168);
  84.         NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  //中斷優(yōu)先級分組 分2組
  85.         LED_Init();
  86.         KEY_Init();
  87.         USART1_Init(9600);
  88.         TFTLCD_Init();                        //LCD初始化
  89.         EN25QXX_Init();                                //初始化EN25Q128          
  90.        
  91.         my_mem_init(SRAMIN);                //初始化內(nèi)部內(nèi)存池
  92.        
  93.         FRONT_COLOR=RED;//設(shè)置字體為紅色
  94. //        while(SD_Init()!=0)
  95. //        {       
  96. //                LCD_ShowString(10,10,tftlcd_data.width,tftlcd_data.height,16,"SD Card Error!");
  97. //        }
  98. //        FATFS_Init();                                                        //為fatfs相關(guān)變量申請內(nèi)存                                 
  99. //          f_mount(fs[0],"0:",1);                                         //掛載SD卡
  100. //         f_mount(fs[1],"1:",1);                                 //掛載FLASH.
  101.                
  102.         LCD_ShowFont12Char(10, 10, "xx科技");
  103.         LCD_ShowFont12Char(10, 30, "wwwxxxxnet");   
  104.         LCD_ShowFont12Char(10, 50, "攝像頭應(yīng)用--OV7670");
  105.        
  106.         while(OV7670_Init())//初始化OV7670
  107.         {
  108.                 LCD_ShowString(10,80,tftlcd_data.width,tftlcd_data.height,16,"OV7670 Error!");
  109.                 delay_ms(200);
  110.                 LCD_Fill(10,80,239,206,WHITE);
  111.                 delay_ms(200);
  112.         }
  113.         LCD_ShowString(10,80,tftlcd_data.width,tftlcd_data.height,16,"OV7670 OK!     ");
  114.         delay_ms(1500);         
  115.         OV7670_Light_Mode(0);         //默認(rèn)設(shè)置自動白平衡
  116.         OV7670_Color_Saturation(2);   // 色度調(diào)節(jié)
  117.         OV7670_Brightness(2);         //亮度調(diào)節(jié)
  118.         OV7670_Contrast(2);           //對比度
  119.         OV7670_Special_Effects(0);    //特效
  120.                
  121.         TIM4_Init(10000,8399);                        //10Khz計數(shù)頻率,1秒鐘中斷                                                                          
  122.         EXTI7_Init();                       
  123.         OV7670_Window_Set(12,176,240,320);        //設(shè)置窗口       
  124.           OV7670_CS=0;       
  125.         LCD_Clear(BLACK);
  126.         while(1)
  127.         {
  128.                 key=KEY_Scan(0);
  129.                 if(key)count=20;
  130.                 switch(key)
  131.                 {
  132.                         case KEY_UP:           //燈光模式設(shè)置
  133.                                 lightmode++;
  134.                                 if(lightmode>4)lightmode=0;
  135.                                 OV7670_Light_Mode(lightmode);
  136.                                 sprintf((char*)sbuf,"%s",LMODE_TBL[lightmode]);
  137.                                 break;
  138.                         case KEY_DOWN:         //飽和度
  139.                                 saturation++;
  140.                                 if(saturation>4)saturation=0;
  141.                                 OV7670_Color_Saturation(saturation);
  142.                                 sprintf((char*)sbuf,"Saturation:%d",(char)saturation-2);
  143.                                 break;       
  144.                         case KEY_LEFT:        //亮度
  145.                                 brightness++;
  146.                                 if(brightness>4)brightness=0;
  147.                                 OV7670_Brightness(brightness);
  148.                                 sprintf((char*)sbuf,"Brightness:%d",(char)brightness-2);
  149.                                 break;
  150.                         case KEY_RIGHT:     //對比度
  151.                                 contrast++;
  152.                                 if(contrast>4)contrast=0;
  153.                                 OV7670_Contrast(contrast);
  154.                                 sprintf((char*)sbuf,"Contrast:%d",(char)contrast-2);
  155.                                 break;
  156.                 }
  157.                 if(count)
  158.                 {
  159.                         count--;
  160.                         LCD_ShowString((tftlcd_data.width-240)/2+30,(tftlcd_data.height-320)/2+60,200,16,16,sbuf);
  161.                 }
  162.                 camera_refresh();//更新顯示
  163.                 i++;
  164.                 if(i%20==0)
  165.                 {
  166.                         led1=!led1;
  167.                 }
  168.                 //delay_ms(10);       
  169.         }
  170. }
復(fù)制代碼

所有資料51hei提供下載:
攝像頭應(yīng)用程序--OV7670--DCMI.7z (756.84 KB, 下載次數(shù): 333)


回復(fù)

使用道具 舉報

ID:349783 發(fā)表于 2020-4-3 21:18 來自觸屏版 | 顯示全部樓層
請問樓主,單片機(jī)引腳怎么和ov7670引腳對應(yīng)
回復(fù)

使用道具 舉報

ID:799148 發(fā)表于 2020-7-7 15:44 | 顯示全部樓層
誰有下載好的可不可以給我一份
回復(fù)

使用道具 舉報

ID:601357 發(fā)表于 2020-7-21 11:41 | 顯示全部樓層
這個可以識別出字母嗎?
回復(fù)

使用道具 舉報

ID:805912 發(fā)表于 2020-7-22 10:32 | 顯示全部樓層
請問這個文件是寫在.c文件里還是頭文件里?
回復(fù)

使用道具 舉報

ID:851418 發(fā)表于 2021-1-13 05:34 | 顯示全部樓層
很好的一個攝像頭應(yīng)用程序
回復(fù)

使用道具 舉報

ID:116773 發(fā)表于 2021-1-13 09:37 | 顯示全部樓層
我買了一個7076攝像頭還在吃灰,正好可以借鑒樓主的經(jīng)驗使用起來。
回復(fù)

使用道具 舉報

ID:912948 發(fā)表于 2021-4-27 12:41 | 顯示全部樓層
F407和F429能一樣使用嗎
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表