找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 10751|回复: 7
打印 上一主题 下一主题
收起左侧

stm32F407+ov7670的摄像头识别(代码+连接)

  [复制链接]
跳转到指定楼层
楼主
stm32F407单片机+ov7670摄像头识别

单片机源程序如下:
  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);//将显示区域设置到屏幕中央
  31.           LCD_Set_Window(0,(tftlcd_data.height-240)/2,320-1,240-1);//将显示区域设置到屏幕中央
  32.                
  33.                 OV7670_RRST=0;                                //开始复位读指针
  34.                 OV7670_RCK_L;
  35.                 OV7670_RCK_H;
  36.                 OV7670_RCK_L;
  37.                 OV7670_RRST=1;                                //复位读指针结束
  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;        //读数据
  45.                                 OV7670_RCK_H;
  46.                                 color>>=8;  
  47.                                 OV7670_RCK_L;
  48.                                 color|=OV7670_DATA;        //读数据
  49.                                 OV7670_RCK_H;
  50.                                 LCD_WriteData_Color(color);
  51.                         }
  52.                 }*/
  53.                 for(j=0;j<76800;j++)   //此种方式需清楚TFT内部显示方向控制寄存器值
  54.                 {
  55.                         OV7670_RCK_L;
  56.                         color=OV7670_DATA;        //读数据
  57.                         OV7670_RCK_H;
  58.                         color<<=8;  
  59.                         OV7670_RCK_L;
  60.                         color|=OV7670_DATA;        //读数据
  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;                                        //清零帧中断标记
  68.                 ov_frame++;       //统计帧数
  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);  //中断优先级分组 分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);                //初始化内部内存池
  92.        
  93.         FRONT_COLOR=RED;//设置字体为红色
  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相关变量申请内存                                 
  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, "摄像头应用--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);         //默认设置自动白平衡
  116.         OV7670_Color_Saturation(2);   // 色度调节
  117.         OV7670_Brightness(2);         //亮度调节
  118.         OV7670_Contrast(2);           //对比度
  119.         OV7670_Special_Effects(0);    //特效
  120.                
  121.         TIM4_Init(10000,8399);                        //10Khz计数频率,1秒钟中断                                                                          
  122.         EXTI7_Init();                       
  123.         OV7670_Window_Set(12,176,240,320);        //设置窗口       
  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:           //灯光模式设置
  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. }
复制代码

所有资料51hei提供下载:
摄像头应用程序--OV7670--DCMI.7z (756.84 KB, 下载次数: 324)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏12 分享淘帖 顶1 踩
回复

使用道具 举报

沙发
ID:349783 发表于 2020-4-3 21:18 来自手机 | 只看该作者
请问楼主,单片机引脚怎么和ov7670引脚对应
回复

使用道具 举报

板凳
ID:799148 发表于 2020-7-7 15:44 | 只看该作者
谁有下载好的可不可以给我一份
回复

使用道具 举报

地板
ID:601357 发表于 2020-7-21 11:41 | 只看该作者
这个可以识别出字母吗?
回复

使用道具 举报

5#
ID:805912 发表于 2020-7-22 10:32 | 只看该作者
请问这个文件是写在.c文件里还是头文件里?
回复

使用道具 举报

6#
ID:851418 发表于 2021-1-13 05:34 | 只看该作者
很好的一个摄像头应用程序
回复

使用道具 举报

7#
ID:116773 发表于 2021-1-13 09:37 | 只看该作者
我买了一个7076摄像头还在吃灰,正好可以借鉴楼主的经验使用起来。
回复

使用道具 举报

8#
ID:912948 发表于 2021-4-27 12:41 | 只看该作者
F407和F429能一样使用吗
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表