標題: 使用野火STM32單片機配合OV7725與上位機山外調試助手拍照源碼 [打印本頁]

作者: dempsey233    時間: 2020-11-20 16:59
標題: 使用野火STM32單片機配合OV7725與上位機山外調試助手拍照源碼
使用的原工程是野火資料提供的,在此基礎上 我將FIFO中發(fā)往LCD的RGB565數(shù)據(jù)通過usart串口輸送到上位機,再利用山外調試助手顯示出來。


單片機源程序如下:
  1. #include "stm32f10x.h"
  2. #include "./ov7725/bsp_ov7725.h"
  3. #include "./lcd/bsp_ili9341_lcd.h"
  4. #include "./led/bsp_led.h"   
  5. #include "./usart/bsp_usart.h"
  6. #include "./key/bsp_key.h"  
  7. #include "./systick/bsp_SysTick.h"

  8. extern uint8_t Ov7725_vsync;

  9. unsigned int Task_Delay[NumOfTask];


  10. extern OV7725_MODE_PARAM cam_mode;


  11. /**
  12.   * @brief  主函數(shù)
  13.   * @param  無  
  14.   * @retval 無
  15.   */
  16. int main(void)         
  17. {               

  18.         float frame_count = 0;
  19.         uint8_t retry = 0;

  20.         /* 液晶初始化 */
  21.         ILI9341_Init();
  22.         ILI9341_GramScan ( 3 );
  23.         
  24.         LCD_SetFont(&Font8x16);
  25.         LCD_SetColors(RED,BLACK);

  26.   ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH);        /* 清屏,顯示全黑 */
  27.         
  28.         /********顯示字符串示例*******/
  29.   ILI9341_DispStringLine_EN(LINE(0),"BH OV7725 Test Demo");

  30.         USART_Config();
  31.         LED_GPIO_Config();
  32.         Key_GPIO_Config();
  33.         SysTick_Init();
  34. //        printf("\r\n ** OV7725攝像頭實時液晶顯示例程** \r\n");
  35.         
  36.         /* ov7725 gpio 初始化 */
  37.         OV7725_GPIO_Config();
  38.         
  39.         LED_BLUE;
  40.         /* ov7725 寄存器默認配置初始化 */
  41.         while(OV7725_Init() != SUCCESS)
  42.         {
  43.                 retry++;
  44.                 if(retry>5)
  45.                 {
  46.                         printf("\r\n沒有檢測到OV7725攝像頭\r\n");
  47.                         ILI9341_DispStringLine_EN(LINE(2),"No OV7725 module detected!");
  48.                         while(1);
  49.                 }
  50.         }


  51.         /*根據(jù)攝像頭參數(shù)組配置模式*/
  52.         OV7725_Special_Effect(cam_mode.effect);
  53.         /*光照模式*/
  54.         OV7725_Light_Mode(cam_mode.light_mode);
  55.         /*飽和度*/
  56.         OV7725_Color_Saturation(cam_mode.saturation);
  57.         /*光照度*/
  58.         OV7725_Brightness(cam_mode.brightness);
  59.         /*對比度*/
  60.         OV7725_Contrast(cam_mode.contrast);
  61.         /*特殊效果*/
  62.         OV7725_Special_Effect(cam_mode.effect);
  63.         
  64.         /*設置圖像采樣及模式大小*/
  65.         OV7725_Window_Set(cam_mode.cam_sx,
  66.                                                                                                                 cam_mode.cam_sy,
  67.                                                                                                                 cam_mode.cam_width,
  68.                                                                                                                 cam_mode.cam_height,
  69.                                                                                                                 cam_mode.QVGA_VGA);

  70.         /* 設置液晶掃描模式 */
  71. //        ILI9341_GramScan( cam_mode.lcd_scan );
  72.         
  73.         
  74.         
  75. //        ILI9341_DispStringLine_EN(LINE(2),"OV7725 initialize success!");
  76. //        printf("\r\nOV7725攝像頭初始化完成\r\n");
  77.         
  78.         Ov7725_vsync = 0;
  79.         
  80.         
  81.         while(1){
  82.                 /*接收到新圖像進行顯示*/
  83.                 if( Ov7725_vsync == 2 )
  84.                 {
  85.                         USART_SendBits(DEBUG_USARTx,0x01);
  86.                         USART_SendBits(DEBUG_USARTx,0xFE);
  87.                         frame_count++;
  88.                         FIFO_PREPARE;                          /*FIFO準備*/                                       
  89.                         ImagDisp(cam_mode.lcd_sx,
  90.                                                                 cam_mode.lcd_sy,
  91.                                                                 cam_mode.cam_width,
  92.                                                                 cam_mode.cam_height);                        /*采集并顯示*/
  93.                         USART_SendBits(DEBUG_USARTx,0xFE);
  94.                         USART_SendBits(DEBUG_USARTx,0x01);
  95.         
  96.                         Ov7725_vsync = 0;                        
  97.                         LED1_TOGGLE;

  98.                 }
  99.                
  100.                 /*檢測按鍵*/
  101.                 if( Key_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN) == KEY_ON  )
  102.                 {
  103.                         /*LED反轉*/
  104.                         LED2_TOGGLE;

  105.                 }
  106.                 /*檢測按鍵*/
  107.                 if( Key_Scan(KEY2_GPIO_PORT,KEY2_GPIO_PIN) == KEY_ON  )
  108.                 {
  109.                         /*LED反轉*/
  110.                         LED3_TOGGLE;                        
  111.                         
  112.                                 /*動態(tài)配置攝像頭的模式,
  113.                             有需要可以添加使用串口、用戶界面下拉選擇框等方式修改這些變量,
  114.                             達到程序運行時更改攝像頭模式的目的*/
  115.                         
  116.                                 cam_mode.QVGA_VGA = 0,        //QVGA模式
  117.                                 cam_mode.cam_sx = 0,
  118.                                 cam_mode.cam_sy = 0,        

  119.                                 cam_mode.cam_width = 320,
  120.                                 cam_mode.cam_height = 240,

  121.                                 cam_mode.lcd_sx = 0,
  122.                                 cam_mode.lcd_sy = 0,
  123.                                 cam_mode.lcd_scan = 3, //LCD掃描模式,本橫屏配置可用1、3、5、7模式

  124.                                 //以下可根據(jù)自己的需要調整,參數(shù)范圍見結構體類型定義        
  125.                                 cam_mode.light_mode = 0,//自動光照模式
  126.                                 cam_mode.saturation = 0,        
  127.                                 cam_mode.brightness = 0,
  128.                                 cam_mode.contrast = 0,
  129.                                 cam_mode.effect = 1,                //黑白模式
  130.                         
  131.                         /*根據(jù)攝像頭參數(shù)寫入配置*/
  132.                         OV7725_Special_Effect(cam_mode.effect);
  133.                         /*光照模式*/
  134.                         OV7725_Light_Mode(cam_mode.light_mode);
  135.                         /*飽和度*/
  136.                         OV7725_Color_Saturation(cam_mode.saturation);
  137.                         /*光照度*/
  138.                         OV7725_Brightness(cam_mode.brightness);
  139.                         /*對比度*/
  140.                         OV7725_Contrast(cam_mode.contrast);
  141.                         /*特殊效果*/
  142.                         OV7725_Special_Effect(cam_mode.effect);
  143.                         
  144.                         /*設置圖像采樣及模式大小*/
  145.                         OV7725_Window_Set(cam_mode.cam_sx,
  146.                                                                                                                                 cam_mode.cam_sy,
  147.                                                                                                                                 cam_mode.cam_width,
  148.                                                                                                                                 cam_mode.cam_height,
  149.                                                                                                                                 cam_mode.QVGA_VGA);

  150.                         /* 設置液晶掃描模式 */
  151.                         ILI9341_GramScan( cam_mode.lcd_scan );
  152.         }
  153.                
  154.                 /*每隔一段時間計算一次幀率*/
  155.                 if(Task_Delay[0] == 0)  
  156.                 {                        
  157. //                        printf("\r\nframe_ate = %.2f fps\r\n",frame_count/10);
  158.                         frame_count = 0;
  159.                         Task_Delay[0] = 10000;
  160.                 }
  161.         }
  162.         
  163. }




  164. /*********************************************END OF FILE**********************/
復制代碼

提供源碼參考:
液晶實時顯示.7z (762.76 KB, 下載次數(shù): 90)


作者: 話之王    時間: 2022-3-23 15:34
能用嗎?




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1