找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1855|回复: 0
收起左侧

ov7670摄像头程序

[复制链接]
ID:224302 发表于 2017-8-3 10:35 | 显示全部楼层 |阅读模式
ov7670程序

单片机源程序如下:
  1. #include "led.h"
  2. #include "delay.h"
  3. #include "key.h"
  4. #include "sys.h"
  5. #include "lcd.h"
  6. #include "usart.h"         
  7. #include "string.h"
  8. #include "ov7670.h"
  9. #include "tpad.h"
  10. #include "timer.h"
  11. #include "exti.h"
  12. #include "usmart.h"


  13. /************************************************
  14. ALIENTEK战舰STM32开发板实验35
  15. 摄像头OV7670 实验
  16. ************************************************/


  17. const u8*LMODE_TBL[5]={"Auto","Sunny","Cloudy","Office","Home"};                                                        //5种光照模式            
  18. const u8*EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"};        //7种特效
  19. extern u8 ov_sta;        //在exit.c里 面定义
  20. extern u8 ov_frame;        //在timer.c里面定义                 
  21. //更新LCD显示
  22. void camera_refresh(void)
  23. {
  24.         u32 j;
  25.          u16 color;         
  26.         if(ov_sta)//有帧中断更新?
  27.         {
  28.                 LCD_Scan_Dir(U2D_L2R);                //从上到下,从左到右  
  29.                 if(lcddev.id==0X1963)LCD_Set_Window((lcddev.width-240)/2,(lcddev.height-320)/2,240,320);//将显示区域设置到屏幕中央
  30.                 else if(lcddev.id==0X5510||lcddev.id==0X5310)LCD_Set_Window((lcddev.width-320)/2,(lcddev.height-240)/2,320,240);//将显示区域设置到屏幕中央
  31.                 LCD_WriteRAM_Prepare();     //开始写入GRAM        
  32.                 OV7670_RRST=0;                                //开始复位读指针
  33.                 OV7670_RCK_L;
  34.                 OV7670_RCK_H;
  35.                 OV7670_RCK_L;
  36.                 OV7670_RRST=1;                                //复位读指针结束
  37.                 OV7670_RCK_H;
  38.                 for(j=0;j<76800;j++)
  39.                 {
  40.                         OV7670_RCK_L;
  41.                         color=GPIOC->IDR&0XFF;        //读数据
  42.                         OV7670_RCK_H;
  43.                         color<<=8;  
  44.                         OV7670_RCK_L;
  45.                         color|=GPIOC->IDR&0XFF;        //读数据
  46.                         OV7670_RCK_H;
  47.                         LCD->LCD_RAM=color;   
  48.                 }                                                            
  49.                  ov_sta=0;                                        //清零帧中断标记
  50.                 ov_frame++;
  51.                 LCD_Scan_Dir(DFT_SCAN_DIR);        //恢复默认扫描方向
  52.         }
  53. }           


  54. int main(void)
  55. {         
  56.         u8 key;
  57.         u8 lightmode=0,saturation=2,brightness=2,contrast=2;
  58.         u8 effect=0;         
  59.          u8 i=0;            
  60.         u8 msgbuf[15];                                //消息缓存区
  61.         u8 tm=0;

  62.         delay_init();                     //延时函数初始化         
  63.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
  64.         uart_init(115200);                 //串口初始化为 115200
  65.          usmart_dev.init(72);                //初始化USMART               
  66.          LED_Init();                                          //初始化与LED连接的硬件接口
  67.         KEY_Init();                                        //初始化按键
  68.         LCD_Init();                                           //初始化LCD  
  69.         TPAD_Init(6);                                //触摸按键初始化
  70.          POINT_COLOR=RED;                        //设置字体为红色
  71.         LCD_ShowString(30,50,200,16,16,"WarShip STM32");        
  72.         LCD_ShowString(30,70,200,16,16,"OV7670 TEST");        
  73.         LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
  74.         LCD_ShowString(30,110,200,16,16,"2015/1/18");
  75.         LCD_ShowString(30,130,200,16,16,"KEY0:Light Mode");
  76.         LCD_ShowString(30,150,200,16,16,"KEY1:Saturation");
  77.         LCD_ShowString(30,170,200,16,16,"KEY2:Brightness");
  78.         LCD_ShowString(30,190,200,16,16,"KEY_UP:Contrast");
  79.         LCD_ShowString(30,210,200,16,16,"TPAD:Effects");         
  80.           LCD_ShowString(30,230,200,16,16,"OV7670 Init...");         
  81.         while(OV7670_Init())//初始化OV7670
  82.         {
  83.                 LCD_ShowString(30,230,200,16,16,"OV7670 Error!!");
  84.                 delay_ms(200);
  85.             LCD_Fill(30,230,239,246,WHITE);
  86.                 delay_ms(200);
  87.         }
  88.          LCD_ShowString(30,230,200,16,16,"OV7670 Init OK");
  89.         delay_ms(1500);                    
  90.         OV7670_Light_Mode(lightmode);
  91.         OV7670_Color_Saturation(saturation);
  92.         OV7670_Brightness(brightness);
  93.         OV7670_Contrast(contrast);
  94.          OV7670_Special_Effects(effect);         
  95.         TIM6_Int_Init(10000,7199);                        //10Khz计数频率,1秒钟中断                                                                          
  96.         EXTI8_Init();                                                //使能定时器捕获
  97.         OV7670_Window_Set(12,176,240,320);        //设置窗口         
  98.           OV7670_CS=0;                                       
  99.         LCD_Clear(BLACK);
  100.          while(1)
  101.         {        
  102.                 key=KEY_Scan(0);//不支持连按
  103.                 if(key)
  104.                 {
  105.                         tm=20;
  106.                         switch(key)
  107.                         {                                    
  108.                                 case KEY0_PRES:        //灯光模式Light Mode
  109.                                         lightmode++;
  110.                                         if(lightmode>4)lightmode=0;
  111.                                         OV7670_Light_Mode(lightmode);
  112.                                         sprintf((char*)msgbuf,"%s",LMODE_TBL[lightmode]);
  113.                                         break;
  114.                                 case KEY1_PRES:        //饱和度Saturation
  115.                                         saturation++;
  116.                                         if(saturation>4)saturation=0;
  117.                                         OV7670_Color_Saturation(saturation);
  118.                                         sprintf((char*)msgbuf,"Saturation:%d",(signed char)saturation-2);
  119.                                         break;
  120.                                 case KEY2_PRES:        //亮度Brightness                                 
  121.                                         brightness++;
  122.                                         if(brightness>4)brightness=0;
  123.                                         OV7670_Brightness(brightness);
  124.                                         sprintf((char*)msgbuf,"Brightness:%d",(signed char)brightness-2);
  125.                                         break;
  126.                                 case WKUP_PRES:        //对比度Contrast                           
  127.                                         contrast++;
  128.                                         if(contrast>4)contrast=0;
  129.                                         OV7670_Contrast(contrast);
  130.                                         sprintf((char*)msgbuf,"Contrast:%d",(signed char)contrast-2);
  131.                                         break;
  132.                         }
  133.                 }         
  134.                 if(TPAD_Scan(0))//检测到触摸按键
  135.                 {
  136.                         effect++;
  137.                         if(effect>6)effect=0;
  138.                         OV7670_Special_Effects(effect);//设置特效
  139.                          sprintf((char*)msgbuf,"%s",EFFECTS_TBL[effect]);
  140.                         tm=20;
  141.                 }
  142.                 camera_refresh();//更新显示
  143.                  if(tm)
  144.                 {
  145.                         //LCD_ShowString((lcddev.width-240)/2+30,(lcddev.height-320)/2+60,200,16,16,msgbuf);
  146.                         tm--;
  147.                 }
  148.                 i++;
  149.                 if(i==15)//DS0闪烁.
  150.                 {
  151.                         i=0;
  152.                         LED0=!LED0;
  153.                  }
  154.         }           
  155. }
复制代码

所有资料51hei提供下载:
实验35 摄像头实验.rar (387.25 KB, 下载次数: 9)
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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