⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coms_sencor.c

📁 blackfin开发板 BF533-CMOS:OV7648 开发代码 开发环境为visul dsp 3.5
💻 C
字号:
#include "I2C.h"
#include "stdio.h"
#include "sys\exception.h"
#include "cpld.h"

#define RAM_Length 720
#define RAM_Length_y 288



EX_INTERRUPT_HANDLER(DMA0_PPI_ISR);

void Init_EBIU(void);
void Init_CPLD(void);
void Init_PLL(void);
void Init_SDRAM(void);
void Init_PPI(void);
void Init_DMA(void);
void Close_ADV7181(void);


unsigned short PPI_DMA_DONE;
unsigned char dataIn[40];

main()
{
	int o = 0;
	bool ret = true;

    Init_PLL(); 
    Init_EBIU();
    Init_SDRAM();
   *pLED = 0x0;
   
    //Initial Interrupt 
    register_handler(ik_ivg8,DMA0_PPI_ISR);
    *pSIC_IMASK = 0x00000100;
	
    Close_ADV7181();
    Init_CPLD();

	
    I2C_Init(OV7648_IDENT_W);
 
  	
	I2C_Read(&dataIn[0],0x1c);//7f
	I2C_Read(&dataIn[1],0x1d);//a2
	I2C_Read(&dataIn[2],0x0a);//76
	//I2C_Write(0x11,0x05);
	I2C_Read(&dataIn[3],0x12);//14-->04
	I2C_Read(&dataIn[4],0x13);//a3-->b3
	I2C_Read(&dataIn[5],0x14);//04-->04
	I2C_Read(&dataIn[6],0x15);//00-->40
	I2C_Read(&dataIn[7],0x17);//1a
	I2C_Read(&dataIn[8],0x26);
	I2C_Read(&dataIn[9],0x27);
	
	
	I2C_Write(0x80,0x12);
	I2C_Write(0x40,0x12);
	I2C_Write(0x80,0x00);
	I2C_Write(0xa4,0x03);
	I2C_Write(0x30,0x04);
	I2C_Write(0x88,0x05);
	I2C_Write(0x60,0x06);
	I2C_Write(0x00,0x11);
	I2C_Write(0x05,0x12);
	I2C_Write(0xb3,0x13);
	I2C_Write(0x04,0x14);
	//I2C_Write(0x24,0x14);
	I2C_Write(0xc4,0x15);
	I2C_Write(0x41,0x1f);
	I2C_Write(0xd0,0x20);
	I2C_Write(0xde,0x23);
	I2C_Write(0xa0,0x24);
	I2C_Write(0x80,0x25);
	I2C_Write(0x32,0x26);
	I2C_Write(0xe2,0x27);
	I2C_Write(0x00,0x28);
	I2C_Write(0x11,0x2a);
	I2C_Write(0x00,0x2b);
	I2C_Write(0x05,0x2d);
	I2C_Write(0x9d,0x2f);
	I2C_Write(0x00,0x30);
	I2C_Write(0xc4,0x31);
	//I2C_Write(0xa6,0x60);
	I2C_Write(0x26,0x60);
	I2C_Write(0xe0,0x61);
	I2C_Write(0x88,0x62);
	I2C_Write(0x11,0x63);
	I2C_Write(0x89,0x64);
	I2C_Write(0x00,0x65);
	I2C_Write(0x94,0x67);
	I2C_Write(0x7a,0x68);
	I2C_Write(0x08,0x69);
	I2C_Write(0x11,0x6c);
	I2C_Write(0x33,0x6d);
	I2C_Write(0x22,0x6e);
	I2C_Write(0x00,0x6f);
	//I2C_Write(0x20,0x74);
	I2C_Write(0x00,0x74);
	I2C_Write(0x06,0x75);
	I2C_Write(0xb5,0x77);
//	I2C_Write(0x20,0x71);
	
	
	I2C_Read(&dataIn[10],0x12);
	I2C_Read(&dataIn[11],0x13);
	I2C_Read(&dataIn[12],0x14);
	I2C_Read(&dataIn[13],0x15);
	I2C_Read(&dataIn[14],0x71);
	I2C_Read(&dataIn[15],0x01);
	

	
	if((dataIn[0] != 0x7f) || (dataIn[1] != 0xa2))
	{
		while(1);
	}
	

		Init_DMA();
		Init_PPI();
	
		*pDMA0_CONFIG = *pDMA0_CONFIG | 0x0001;
		ssync();
		*pPPI_CONTROL = *pPPI_CONTROL | 0x0001;
		ssync();
	


	
		while(1);

}


void Init_CPLD(void)
{ 
	int i;
	
	*pCtrlReg1 = 0x31;
	for(i = 0;i < 10000;i++);
	*pCtrlReg2 = 0x01;

	
}

void Close_ADV7181(void)
{
	int i;
	*pCtrlReg1 = 0x01;
	for(i = 0;i < 1000;i++)
	{;}
	if(!I2C_Init(ADV7181_IDENT_W))
	{
		while(1);
	}
	I2C_Write(0x40,0x03);
	I2C_Read(&dataIn[0],0x03);
}

void Init_EBIU(void)
{
	
	*pEBIU_AMBCTL0	= 0x7bb07bb0;	// <--|Write access time = 7 cycles, read access time = 11 cycles, no ARDY
	*pEBIU_AMBCTL1	= 0x7bb07bb0;	//    |Hold time = 2 cycles, setup time = 3 cycles, transition time = 4 cycles
	*pEBIU_AMGCTL	= 0x000F;		//	  |Enable all memory banks

}//end Init_EBIU

void Init_PLL(void)
{
    int iIMASK_Value;
	sysreg_write(reg_SYSCFG, 0x32);		//Initialize System Configuration Register

	// set VCO/CCLK = 1, and VCO/SCLK = 5 (take effect immediately)
	*pPLL_DIV = 0x0005;

	// prepare PLL changes (set CLKIN/VCO = 22; takes effect after PLL programming sequence)
	*pPLL_LOCKCNT	= 0x0200;					// time for PLL to stabilize
	*pPLL_CTL		= 0x2c00;					// set VCO/CLKIN = 22

	// execute PLL programming sequence
	*pSIC_IWR		= 0x00000001;				// enable only PLL wakeup interrupt
	iIMASK_Value	= cli();					// disable interrupts
	idle();										// wait for PLL wakeup interrupt
	sti(iIMASK_Value);	


}//end Init_PLL 



void Init_SDRAM(void)
{

	//SDRAM Refresh Rate Control Register
	*pEBIU_SDRRC = 0x00000817;	

	//SDRAM Memory Bank Control Register
	*pEBIU_SDBCTL = 0x00000013;

	//SDRAM Memory Global Control Register	
	*pEBIU_SDGCTL = 0x0091998d;	
														
		

}//end Init_SDRAM

void Init_PPI(void)
{
		*pPPI_CONTROL = 0x40c0;
		*pPPI_FRAME =   240;
		*pPPI_COUNT = 640;	
}

	


void Init_DMA(void)
{

	//Target address of the DMA
	*pDMA0_START_ADDR = 0x0;	

	//RAM_Length 32bit transfers will be executed
	*pDMA0_X_COUNT = 640;

	//The modifier is set to 4 because of the 32bit transfers
	*pDMA0_X_MODIFY = 0x2;
	*pDMA0_Y_COUNT	= 3840;
	*pDMA0_Y_MODIFY = 0x2;													

	//PPI Peripheral is used
	*pDMA0_PERIPHERAL_MAP = 0x0;	
	
	//DMA Config: Enable DMA | Memory write DMA | Discard DMA FIFO before start | enable assertation of interrupt | NDSIZE for stop mode | Enable STOP DMA
	//Enable 2D-DMA
	*pDMA0_CONFIG = 0x00b6;	
	//*pDMA0_CONFIG = DMAEN | DI_EN | WNR | WDSIZE_32 | RESTART | DMA2D ;//| DI_SEL;	
	

}//end Init_DMA



EX_INTERRUPT_HANDLER(DMA0_PPI_ISR)	// <--|declaration in  exception.h -->
{
//disable the interrupt request
        	*pDMA0_IRQ_STATUS = 0x1;   // to clear interrupt bit	
	        //temp2 = *pPPI_CONTROL;
	        *pPPI_CONTROL &= 0xfffe;
	       printf( "\nThe DMA0 PPI Interrupt has been entered!\n" );
	      // PPI_DMA_DONE = 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -