久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2799|回復: 1
打印 上一主題 下一主題
收起左側

STM32F407攝像頭實驗代碼

[復制鏈接]
跳轉到指定樓層
樓主
ID:234742 發表于 2017-9-21 21:10 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
下載:
實驗33 攝像頭實驗 最終確定.rar (404.07 KB, 下載次數: 15)

  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. #include "color.h"


  14. /************************************************
  15. ALIENTEK精英STM32開發板實驗33
  16. 攝像頭OV7670 實驗

  17. ************************************************/
  18. void RCC_Configuration(void);
  19. void GPIO_Configuration(void);
  20. void TIM_Configuration(u16 value);
  21. void TIM_Configuration1(u16 value);
  22. //int key_Read(void);
  23. int flag = 0;
  24. #define vole(tem)   (0.5+0.5/45*(tem+45))*1000/*換算公式*/

  25. const u8*LMODE_TBL[5]={"Auto","Sunny","Cloudy","Office","Home"};                                                        //5種光照模式            
  26. const u8*EFFECTS_TBL[7]={"Normal","Negative","B&W","Redish","Greenish","Bluish","Antique"};        //7種特效
  27. extern u8 ov_sta;        //在exit.c里 面定義
  28. extern u8 ov_frame;        //在timer.c里面定義                 
  29. //更新LCD顯示
  30. void camera_refresh(void)
  31. {
  32.         u32 j;
  33.          u16 color;
  34.      
  35.         if(ov_sta)//有幀中斷更新?
  36.         {
  37.                 LCD_Scan_Dir(U2D_L2R);                //從上到下,從左到右  
  38.                 if(lcddev.id==0X1963)LCD_Set_Window((lcddev.width-240)/2,(lcddev.height-320)/2,240,320);//將顯示區域設置到屏幕中央
  39.                 else if(lcddev.id==0X5510||lcddev.id==0X5310)LCD_Set_Window((lcddev.width-320)/2,(lcddev.height-240)/2,320,240);//將顯示區域設置到屏幕中央
  40.                 LCD_WriteRAM_Prepare();     //開始寫入GRAM        
  41.                 OV7670_RRST=0;                                //開始復位讀指針
  42.                 OV7670_RCK_L;
  43.                 OV7670_RCK_H;
  44.                 OV7670_RCK_L;
  45.                 OV7670_RRST=1;                                //復位讀指針結束
  46.                 OV7670_RCK_H;
  47.                 for(j=0;j<76800;j++)
  48.                 {
  49.                         OV7670_RCK_L;
  50.                         color=GPIOC->IDR&0XFF;        //讀數據
  51.                         OV7670_RCK_H;
  52.                         color<<=8;  
  53.                         OV7670_RCK_L;
  54.                         color|=GPIOC->IDR&0XFF;        //讀數據
  55.                         OV7670_RCK_H;  
  56. //            if(color>25500)
  57. //                color=0x0000;
  58. //            else
  59. //                color=0xffff;
  60.                         LCD->LCD_RAM=color;            
  61.                 }                                 
  62.             
  63.                  ov_sta=0;                                        //清零幀中斷標記
  64. //                ov_frame++;
  65.                 LCD_Scan_Dir(DFT_SCAN_DIR);        //恢復默認掃描方向
  66.         if(Trace(&condition, &result))
  67.                 {
  68.             LCD_DrawRectangle( result.x-result.w/2, result.y-result.h/2, result.x-result.w/2+result.w,  result.y-result.h/2+result.h);
  69.             LCD_DrawRectangle( result.x-2, result.y-2,result.x+2, result.y+2);
  70.            
  71.                 }
  72.         }
  73. }           


  74. int main(void)
  75. {         
  76.         u8 key;
  77.         u8 lightmode=0,saturation=2,contrast=2;
  78.         u8 effect=0;         
  79.          u8 i=0;            
  80.         u8 msgbuf[15];                                //消息緩存區
  81.         u8 tm=0;
  82.          int volume = vole(0);
  83. //     u16 t=0;
  84. //    u16 a,b,c;
  85.           RCC_Configuration();
  86.     GPIO_Configuration();
  87.     TIM_Configuration(volume);
  88.                 TIM_Configuration1(volume);   
  89.          
  90.         delay_init();                     //延時函數初始化         
  91.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//設置中斷優先級分組為組2:2位搶占優先級,2位響應優先級
  92.         uart_init(115200);                 //串口初始化為 115200
  93.          usmart_dev.init(72);                //初始化USMART               
  94.          LED_Init();                                          //初始化與LED連接的硬件接口
  95.         KEY_Init();                                        //初始化按鍵
  96.         LCD_Init();                                           //初始化LCD  
  97. //        TPAD_Init(6);                                //觸摸按鍵初始化
  98.          POINT_COLOR=RED;                        //設置字體為紅色
  99.         
  100.                         TIM_Configuration(1500);
  101.                         delay_ms(20);
  102.                         TIM_Configuration(1500);
  103.                         delay_ms(20);
  104.                         TIM_Configuration(1500);
  105.                         delay_ms(20);
  106.                         
  107.                         TIM_Configuration1(1500);
  108.                         delay_ms(20);
  109.                         TIM_Configuration1(1500);
  110.                         delay_ms(20);
  111.                         TIM_Configuration1(1500);
  112.                         delay_ms(20);
  113.         LCD_ShowString(30,50,200,16,16,"ELITE STM32F103 ^_^");        
  114.         LCD_ShowString(30,70,200,16,16,"OV7670 TEST");        
  115.         LCD_ShowString(30,90,200,16,16,"ATOM@ALIENTEK");
  116.         LCD_ShowString(30,110,200,16,16,"2015/1/18");
  117.         LCD_ShowString(30,130,200,16,16,"KEY0:Light Mode");
  118.         LCD_ShowString(30,150,200,16,16,"KEY1:Saturation");
  119.         LCD_ShowString(30,170,200,16,16,"KEY_UP:Contrast");
  120.         LCD_ShowString(30,190,200,16,16,"TPAD:Effects");         
  121.           LCD_ShowString(30,210,200,16,16,"OV7670 Init...");         
  122.         while(OV7670_Init())//初始化OV7670
  123.         {
  124.                 LCD_ShowString(30,210,200,16,16,"OV7670 Error!!");
  125.                 delay_ms(200);
  126.             LCD_Fill(30,210,239,246,WHITE);
  127.                 delay_ms(200);
  128.         }
  129.          LCD_ShowString(30,210,200,16,16,"OV7670 Init OK");
  130.         delay_ms(1500);                    
  131.         OV7670_Light_Mode(lightmode);
  132.         OV7670_Color_Saturation(saturation);
  133.         OV7670_Contrast(contrast);
  134.          OV7670_Special_Effects(effect);         
  135.         
  136.         TIM6_Int_Init(10000,7199);                        //10Khz計數頻率,1秒鐘中斷                                                                          
  137.         EXTI8_Init();                                                //使能定時器捕獲
  138.         OV7670_Window_Set(12,176,240,320);        //設置窗口         
  139.           OV7670_CS=0;                        
  140.         LCD_Clear(BLACK);               
  141. //                if(result.x!=0&&result.y!=0)        
  142. //                {
  143.                                 printf("ZB= %d,%d ",result.x,result.y);
  144. //                }
  145.          while(1)
  146.         {        
  147.                 POINT_COLOR=BLUE;        
  148.     key=KEY_Scan(0);//不支持連按
  149.                 camera_refresh();//更新顯示
  150.                
  151.                 if(KEY0==1)
  152.                 {
  153.                                 if((result.x<170|result.x>140)&&(result.y<210|result.x>190))
  154.                                 {
  155.                                                         if((160-result.x<200-result.y)||(160+result.x<200+result.y))
  156.                                                                         {
  157.                                                                                         TIM_Configuration(1500);
  158.                                                                                         delay_ms(30);
  159.                                                                                                                                                         
  160.                                                                                         TIM_Configuration(1725);
  161.                                                                                         delay_ms(20);
  162.                                                                                        
  163.                                                                                         TIM_Configuration(1500);
  164.                                                                                         delay_ms(30);
  165.                                                                                        
  166.                                                                                         TIM_Configuration(1550);
  167.                                                                                         delay_ms(20);
  168.                                                                                        
  169.                                                                                         TIM_Configuration(1500);
  170.                                                                                         delay_ms(20);
  171.                                                                                         camera_refresh();
  172.                                                                         }                                                                                
  173.                                                         else
  174.                                                                         {
  175.                                                                                         TIM_Configuration1(1500);
  176.                                                                                         delay_ms(30);
  177.                                                                                 
  178.                                                                                        
  179.                                                                                         TIM_Configuration1(1725);
  180.                                                                                         delay_ms(20);
  181.                                                                                        
  182.                                                                                         TIM_Configuration1(1500);
  183.                                                                                         delay_ms(20);
  184.                                                                                        
  185.                                                                                         TIM_Configuration1(1550);
  186.                                                                                         delay_ms(20);
  187.                                                                                        
  188.                                                                                         TIM_Configuration1(1500);
  189.                                                                                         delay_ms(20);
  190.                                                                                         camera_refresh();
  191.                                                                         }
  192.                                                         if(result.x<160&&result.x!=0)
  193.                                                                         {
  194.                                                                                 
  195.                                                                                 TIM_Configuration(1500);
  196.                                                                                 delay_ms(30);
  197.                                                                         
  198.                                                                                 
  199.                                                                                 TIM_Configuration(1725);
  200.                                                                                 delay_ms(20);
  201.                                                                                 
  202.                                                                                 TIM_Configuration(1800);
  203.                                                                                 delay_ms(30);

  204.                                                                                 TIM_Configuration(1400);
  205.                                                                                 delay_ms(20);
  206.                                                                
  207.                                                                                 TIM_Configuration(1525);
  208.                                                                                 delay_ms(20);
  209.                                                                                 
  210.                                                                                 TIM_Configuration(1500);
  211.                                                                                 delay_ms(20);
  212.                                                                                 camera_refresh();
  213.                                                                         }
  214.                                                                
  215.                                                         else
  216.                                                                         {
  217.                                                                                 TIM_Configuration1(1500);
  218.                                                                                 delay_ms(20);
  219.                                                                                                                                        
  220.                                                                                 TIM_Configuration1(1400);
  221.                                                                                 delay_ms(20);
  222.                                                                                 
  223.                                                                                 TIM_Configuration1(1350);
  224.                                                                                 delay_ms(20);

  225.                                                                                 TIM_Configuration1(1250);
  226.                                                                                 delay_ms(20);
  227.                                                                
  228.                                                                                 TIM_Configuration1(1100);
  229.                                                                                 delay_ms(20);
  230.                                                                                 
  231.                                                                                 TIM_Configuration1(1350);
  232.                                                                                 delay_ms(20);
  233.                                                                                 
  234.                                                                                 TIM_Configuration1(1500);
  235.                                                                                 delay_ms(20);
  236.                                                                                 
  237.                                                                                 TIM_Configuration1(1500);
  238.                                                                                 delay_ms(20);
  239.                                                                                 camera_refresh();
  240.                                                                         }
  241.                                                                


  242.                                                         if(result.y<200  &&  result.y!=0)
  243.                                                                         {
  244.                                                                                 TIM_Configuration1(1500);
  245.                                                                                 delay_ms(20);
  246.                                                                                                                                        
  247.                                                                                 TIM_Configuration1(1725);
  248.                                                                                 delay_ms(20);
  249.                                                                                 
  250.                                                                                 TIM_Configuration1(1800);
  251.                                                                                 delay_ms(20);

  252.                                                                                 TIM_Configuration1(1400);
  253.                                                                                 delay_ms(20);
  254.                                                                
  255.                                                                                 TIM_Configuration1(1500);
  256.                                                                                 delay_ms(20);
  257.                                                                                 
  258.                                                                                 TIM_Configuration1(1500);
  259.                                                                                 delay_ms(20);
  260.                                                                                 camera_refresh();
  261.                                                                         }                                                                                                               
  262.                                                         else
  263.                                                                         {
  264.                                                                                         TIM_Configuration1(1500);
  265.                                                                                         delay_ms(20);
  266.                                                                                                                                                         
  267.                                                                                         TIM_Configuration1(1400);
  268.                                                                                         delay_ms(20);
  269.                                                                                        
  270.                                                                                         TIM_Configuration1(1350);
  271.                                                                                         delay_ms(20);

  272.                                                                                         TIM_Configuration1(1200);
  273.                                                                                         delay_ms(20);
  274.                                                                         
  275.                                                                                         TIM_Configuration1(1100);
  276.                                                                                         delay_ms(20);
  277.                                                                                        
  278.                                                                                         TIM_Configuration1(1350);
  279.                                                                                         delay_ms(20);
  280.                                                                                        
  281.                                                                                         TIM_Configuration1(1500);
  282.                                                                                         delay_ms(20);
  283.                                                                                        
  284.                                                                                         TIM_Configuration1(1500);
  285.                                                                                         delay_ms(20);
  286.                                                                                         camera_refresh();
  287.                                                                         }
  288.                                         }
  289.                                 
  290.                         else
  291.                                 {
  292.                                                         TIM_Configuration1(1500);
  293.                                                                                         delay_ms(20);        
  294.                                                         TIM_Configuration1(1500);
  295.                                                                                         delay_ms(20);
  296.                                 }
  297.                 }
  298.                
  299.                 if(KEY1==1)
  300.                 {
  301.                         TIM_Configuration(1500);
  302.                         delay_ms(20);        
  303.                         TIM_Configuration1(1500);
  304.                         delay_ms(20);                        
  305.                                                 camera_refresh();
  306.                         TIM_Configuration1(1400);
  307.                         delay_ms(20);
  308.                         TIM_Configuration(1400);
  309.                         delay_ms(20);
  310.                                                                                 
  311.                         TIM_Configuration1(1350);
  312.                         delay_ms(20);
  313.                         TIM_Configuration(1350);
  314.                         delay_ms(20);
  315.                                                 camera_refresh();
  316.                         TIM_Configuration1(1250);
  317.                         delay_ms(20);
  318.                         TIM_Configuration(1250);
  319.                         delay_ms(20);
  320.                                                                
  321.                         TIM_Configuration1(1100);
  322.                         delay_ms(20);
  323.                         TIM_Configuration(1100);
  324.                         delay_ms(20);
  325.                                                 camera_refresh();                        
  326.                         TIM_Configuration1(1350);
  327.                         delay_ms(20);
  328.                         TIM_Configuration(1350);
  329.                         delay_ms(20);
  330.                                                                         
  331.                         TIM_Configuration1(1500);
  332.                         delay_ms(20);
  333.                                                                                 
  334.                         TIM_Configuration(1500);
  335.                         delay_ms(20);
  336.                                                                                 camera_refresh();
  337.                 }
  338.                 if(WK_UP==0)
  339.                 {
  340.                         TIM_Configuration(1500);
  341.                         delay_ms(20);        
  342.                         TIM_Configuration1(1500);
  343.                         delay_ms(20);                        
  344.                                                 camera_refresh();
  345.                         
  346.                 }
  347.                
  348.                                 if(tm)
  349.                                 {
  350.                                         LCD_ShowString((lcddev.width-240)/2+30,(lcddev.height-320)/2+60,200,16,16,msgbuf);
  351.                                         tm--;
  352.                                 }
  353.                                 i++;
  354.                         if(i==15)//DS0閃爍.
  355.                         {
  356.                                 i=0;
  357.                                 LED0=!LED0;
  358.                         }
  359.                 }           
  360. }




  361. void GPIO_Configuration(void)
  362. {
  363.     GPIO_InitTypeDef GPIO_InitStruct;
  364.     /*TIM1的通道1*/
  365.     GPIO_InitStruct.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3;
  366.     GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF_PP;
  367.     GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
  368.     GPIO_Init(GPIOA,&GPIO_InitStruct);

  369.     GPIO_InitStruct.GPIO_Pin=GPIO_Pin_1|GPIO_Pin_5;
  370.     GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPU;
  371.     GPIO_Init(GPIOC,&GPIO_InitStruct);

  372. }
復制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:620272 發表于 2019-11-16 08:40 | 只看該作者
這是用到的哪個攝像頭模塊啊?ov7725可以用么?
回復

使用道具 舉報

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

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 黄色骚片 | 久久久精品久 | 欧美日韩手机在线观看 | 亚洲精品视频在线看 | 成人超碰| 天天干,夜夜操 | 中文字幕第90页 | 国产精品久久久久久久久 | 国产精品呻吟久久av凹凸 | 久草视频网站 | 9久久| 日本电影韩国电影免费观看 | 亚洲综合中文字幕在线观看 | 亚洲精品在线播放 | 欧美久久久久久久 | 欧美日韩福利视频 | 成人久久18免费网站图片 | 欧美一区二区三区四区五区无卡码 | 欧美久久一级 | 成人av鲁丝片一区二区小说 | 一级全黄视频 | 91精品国产综合久久久动漫日韩 | 中文字幕免费视频 | 青青操av | www.4虎影院 国产999精品久久久影片官网 | 三级高清| 欧美一区2区三区3区公司 | 在线精品国产 | www.一级片 | 浮生影院免费观看中文版 | 韩日在线 | 久久久国产精品网站 | 黄色国产视频 | 欧美一区二区三区,视频 | 激情一区二区三区 | 欧美日韩三区 | 亚洲精品1区 | 国产伦一区二区三区四区 | 一本岛道一二三不卡区 | 日日干夜夜操天天操 | 欧美成人精品一区二区三区 |