OV7670 IO 直接驅動 Keil C 代碼
單片機源程序如下:
- /*******************************************************************************
- * Copyright (C) 2012 All Rights Reserved
- *
- * 軟件作者: 騎飛家族
- * 版權所有: 騎飛電子
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x_lib.h"
- #include "ili9320.h"
- #include "OV7670.h"
- #include "delay.h"
- #include <stdio.h>
- ErrorStatus HSEStartUpStatus;
- #define PIX_LONG ((u32)0x12c00)
- #define GUI_CONST_STORAGE const
- /* Private function prototypes -----------------------------------------------*/
- void Demo_Init(void);
- /* Private functions ---------------------------------------------------------*/
- /*******************************************************************************
- * Function Name : main
- * Description : Main program
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- int main(void)
- {
- static unsigned long TimerCnt = 0;
- static unsigned int temp7670 = 0;
- u16 value,val,val1,val2;
-
- Demo_Init();
- ili9320_Initializtion();
- ili9320_Clear(0xffff);
- delay_ms(100);
- ili9320_SetCursor(0,0);
- LCD_WriteReg(0x0050, 0);
- LCD_WriteReg(0x0052, 0);
- LCD_WriteReg(0x0051, 239);
- LCD_WriteReg(0x0053, 319);
- LCD_WriteRAM_Prepare(); // 開顯存
- //delay_ms(10);
-
- while(1!=OV7670_init());
- while(1)
- {
- TimerCnt = 0;
- temp7670 = 0;
- CLK_init_ON(); // OV7670 XCLK 開
- while(value & 0x0800) value = GPIOC->IDR; // Vsync=H
- while((~value) & 0x0800) value = GPIOC->IDR; // Vhync=L
-
- CLK_init_OFF(); //OV7670 XCLK 關
- while(TimerCnt < 76800)
- {
- XCLK_L; // GPIOA->BRR = GPIO_Pin_8; 為0或1
- XCLK_H; // GPIOA->BSRR = GPIO_Pin_8; 端口復位寄存器 為0
- value = GPIOC->IDR;
- temp7670 ++;
-
- if(value & 0x0100) // HREF = H ||(LCD_PCLK_STATE)
- {
- //value = GPIOC->IDR;
- //display[TimerCnt]=value;
-
- if((temp7670 == 1))// 高字節||(value & 0x0200) ||(LCD_PCLK_STATE)
- {
- val1=value& 0x00ff;
- }
- else // 低字節 if((temp7670 != 1)||(LCD_PCLK_STATE))
- {
- val2= value<<8 ; //
- val =ili9320_BGR2RGB(val1 |val2);
- temp7670 = 0;
- LCD_WriteRAM(val); //TFT GRAM 數據
- TimerCnt ++;
- }
- }
-
-
- }
- }
- }
- /*******************************************************************************
- * Function Name : Demo_Init
- * Description : Initializes the demonstration application.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void Demo_Init(void)
- {
- /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
- /* RCC system reset(for debug purpose) */
- RCC_DeInit();
- /* Enable HSE */
- RCC_HSEConfig(RCC_HSE_ON);
- /* Wait till HSE is ready */
- HSEStartUpStatus = RCC_WaitForHSEStartUp();
- if(HSEStartUpStatus == SUCCESS)
- {
- /* Enable Prefetch Buffer */
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
- /* Flash 2 wait state */
- FLASH_SetLatency(FLASH_Latency_2);
-
- /* HCLK = SYSCLK */
- RCC_HCLKConfig(RCC_SYSCLK_Div1);
-
- /* PCLK2 = HCLK */
- RCC_PCLK2Config(RCC_HCLK_Div1);
-
- /* PCLK1 = HCLK/2 */
- RCC_PCLK1Config(RCC_HCLK_Div2);
-
- /* PLLCLK = 8MHz * 9 = 72 MHz */
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_16);
-
- /* Enable PLL */
- RCC_PLLCmd(ENABLE);
-
- /* Wait till PLL is ready */
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
- {
- }
-
- /* Select PLL as system clock source */
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
-
- /* Wait till PLL is used as system clock source */
- while(RCC_GetSYSCLKSource() != 0x08)
- {
- }
- /* Enable USART1 and GPIOA clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
- }
- /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
- | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG
- | RCC_APB2Periph_AFIO, ENABLE);
-
- /*------------------- Resources Initialization -----------------------------*/
- /* ADCCLK = PCLK2/8 */
- RCC_ADCCLKConfig(RCC_PCLK2_Div8);
-
- /* Enable DMA clock */
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
- /* Enable ADC1 and GPIOC clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, ENABLE);
- /* If HSE is not detected at program startup */
- if(HSEStartUpStatus == ERROR)
- {
- /* Generate NMI exception */
- NVIC_SetSystemHandlerPendingBit(SystemHandler_NMI);
- }
-
- }
- #ifdef DEBUG
- /*******************************************************************************
- * Function Name : assert_failed
- * Description : Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * Input : - file: pointer to the source file name
- * - line: assert_param error line source number
- * Output : None
- * Return : None
- *******************************************************************************/
- void assert_failed(u8* file, u32 line)
- {
- /* User can add his own implementation to report the file name and line number */
- }
- #endif
復制代碼
所有資料51hei提供下載:
Stm32 IO口直接驅動OV7670 V1.0(keil).rar
(269.92 KB, 下載次數: 32)
2018-7-30 00:51 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|