标题:
Stm32 IO口直接驱动OV7670的源程序
[打印本页]
作者:
期末已过
时间:
2018-7-29 18:14
标题:
Stm32 IO口直接驱动OV7670的源程序
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
作者:
gjgygwc
时间:
2018-12-21 19:48
为什么下载了文件打不开啊
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1