Exemple #1
0
////////////////////////////
//¹¦ÄÜ£º¶ÁOV7660¼Ä´æÆ÷
//·µ»Ø£º1-³É¹¦	0-ʧ°Ü
uchar rdOV7670Reg(uchar regID, uchar *regDat)
{
	//ͨ¹ýд²Ù×÷ÉèÖüĴæÆ÷µØÖ·
	startSCCB();
	if(0==SCCBwriteByte(0x60))
	{
		stopSCCB();
		return(0);
	}
	//Delay_nUS(100);
  	if(0==SCCBwriteByte(regID))
	{
		stopSCCB();
		return(0);
	}
	stopSCCB();
	
	//Delay_nUS(100);
	
	//ÉèÖüĴæÆ÷µØÖ·ºó£¬²ÅÊǶÁ
	startSCCB();
	if(0==SCCBwriteByte(0x61))
	{
		stopSCCB();
		return(0);
	}
	//Delay_nUS(100);
  	*regDat=SCCBreadByte();
  	noAck();
  	stopSCCB();
  	return(1);
}
Exemple #2
0
////////////////////////////
//╣д─▄Б║Х┴OV7660╝─┤Ткэ
//их╗пБ║1-│╔╣д	0-╩Д░▄
//guanfu_wang
unsigned char rd_Sensor_Reg(unsigned char regID, unsigned char *regDat)
{
	//═е╣§л┤▓┘Оэ╔Уо├╝─┤Ткэхпои
	startSCCB();
	if(0==SCCBwriteByte(0x42))//л┤хпои
	{
		stopSCCB();//иб╦═SCCB О▄¤▀═Бо╣┤Ф╩С├Ч┴Ь
		return(0);//┤ь╬зих╗п
	}
	delay_us(100);
  	if(0==SCCBwriteByte(regID))//╗§┤ТкэID
	{
		stopSCCB();//иб╦═SCCB О▄¤▀═Бо╣┤Ф╩С├Ч┴Ь
		return(0);//┤ь╬зих╗п
	}
	stopSCCB();//иб╦═SCCB О▄¤▀═Бо╣┤Ф╩С├Ч┴Ь
	
	delay_us(100);
	
	//╔Уо├╝─┤Ткэхпои║зБг▓┼╩КХ┴
	startSCCB();
	if(0==SCCBwriteByte(0x43))//Х┴хпои
	{
		stopSCCB();//иб╦═SCCB О▄¤▀═Бо╣┤Ф╩С├Ч┴Ь
		return(0);//┤ь╬зих╗п
	}
	delay_us(100);
  	*regDat=SCCBreadByte();//их╗пХ┴хйх─ох
  	noAck();//иб╦═NACK├Ч┴Ь
  	stopSCCB();//иб╦═SCCB О▄¤▀═Бо╣┤Ф╩С├Ч┴Ь
  	return(1);//│╔╣дих╗п
}
Exemple #3
0
//读OV7660寄存器
u8 OV_ReadReg(u8 regID, u8 *regDat)
{
	//通过写操作设置寄存器地址
	SCCB_Start();
	if(SCCB_Write(0x42))//写地址
	{
		SCCB_Stop();//发送SCCB 总线停止传输命令
		return 1;//错误返回
	}
	delay_us(10);
  	if(SCCB_Write(regID))//积存器ID
	{
		SCCB_Stop();//发送SCCB 总线停止传输命令
		return 2;//错误返回
	}
	SCCB_Stop();//发送SCCB 总线停止传输命令	
	delay_us(10);	
	//设置寄存器地址后,才是读
	SCCB_Start();
	if(SCCB_Write(0x43))//读地址
	{
		SCCB_Stop();//发送SCCB 总线停止传输命令
		return 3;//错误返回
	}
	delay_us(10);
  	*regDat=SCCB_Read();//返回读到的值
  	noAck();//发送NACK命令
  	SCCB_Stop();//发送SCCB 总线停止传输命令
  	return 0;//成功返回
}
Exemple #4
0
uchar read(uchar ch )
{
 uchar temp=0;

start();
 send(AddWr);//确认芯片
 ack();
 send(adCon|ch);//确认通道
 ack();
 //读出数据,放进temp
 start();
 send(AddRd);
 ack();
 temp=recive();
 noAck();
 stop();
 return temp;
}
Exemple #5
0
Fichier : MT9M031.c Projet : wzw/D3
////////////////////////////
//Function:read MTpM031 reg
//return: 0=success; 1=fail
uchar rdMT9M031Reg(uchar regID_h, uchar regID_l, uchar length, uchar *regDat_h, uchar *regDat_l)
{
	//ͨ¹ýд²Ù×÷ÉèÖüĴæÆ÷µØÖ·
	startSCCB();
	if(SCCBwriteByte(0x20))
	{
		stopSCCB();
		return(1);
	}
	usleep(DELAY_TIME);
  	if(SCCBwriteByte(regID_h))
	{
		stopSCCB();
		return(1);
	}
  	usleep(DELAY_TIME);
  	if(SCCBwriteByte(regID_l))
	{
		stopSCCB();
		return(1);
	}
	stopSCCB();

	usleep(DELAY_TIME);
	
	//ÉèÖüĴæÆ÷µØÖ·ºó£¬²ÅÊǶÁ
	startSCCB();
	if(SCCBwriteByte(0x21))
	{
		stopSCCB();
		return(1);
	}
	usleep(DELAY_TIME);
  	*regDat_h=SCCBreadByte();
    if(length == 2){
    	usleep(DELAY_TIME);
    	SCCB_Ack();
      	*regDat_l=SCCBreadByte();
    }
  	noAck();
  	stopSCCB();
  	return(0);
}
Exemple #6
0
void i2cCheckPort(i2cPortData *pPort)
{
    switch(pPort->i2cState)
    {
        case I2C_STATE_START:
            if(!pPort->pConBits->SEN)
            {   // start done - send a read or write address
                sendAddress(pPort);
            }
            break;

        case I2C_STATE_ADDR:
            if(!pPort->pStatBits->TRSTAT)
            {   // address send done - did the device ack?
                if(!pPort->pStatBits->ACKSTAT)
                {   // device ack'd
                    if(pPort->writeSize)
                    {   // start writing
                        writeNextByte(pPort);
                    }
                    else
                    {   // start reading
                        readNextByte(pPort);
                    }
                }
                else
                {   // no ack - do a stop and give up
                    noAck(pPort);
                }
            }
            break;

        case I2C_STATE_WRITE:
            if(!pPort->pStatBits->TRSTAT)
            {   // write done - did the device ack?
                if(!pPort->pStatBits->ACKSTAT)
                { 
                    if(pPort->i2cIndex < pPort->writeSize)
                    {
                        writeNextByte(pPort);
                    }
                    else
                    {   // done writing - might need to read
                        if(pPort->readSize)
                        {   // repeat start
                            pPort->pConBits->RSEN = 1;
                            pPort->i2cState = I2C_STATE_R_START;
                        }
                        else
                        {
                            i2cStop(pPort);
                        }
                    }
                }
                else
                {
                    noAck(pPort);
                }
            }
            break;

        case I2C_STATE_R_START:
            if(!pPort->pConBits->RSEN)
            {   // Repeat start done - back to the address
                pPort->writeSize = 0;  // force a read
                sendAddress(pPort);
            }
            break;

        case I2C_STATE_READ:
            if(!pPort->pConBits->RCEN)
            {   // done reading, now do ack
                pPort->readBuffer[pPort->i2cIndex] = *pPort->pRxReg;
                pPort->i2cIndex++;
                pPort->pConBits->ACKDT = (pPort->i2cIndex == pPort->readSize);    // NACK on last byte
                pPort->pConBits->ACKEN = 1;
                pPort->i2cState = I2C_STATE_READ_ACK;
            }
            break;

        case I2C_STATE_READ_ACK:
            if(!pPort->pConBits->ACKEN)
            {   // done read ack
                if(pPort->i2cIndex >= pPort->readSize)
                {   // done receiving
                    i2cStop(pPort);
                }
                else
                {
                    readNextByte(pPort);
                }
            }
            break;

        case I2C_STATE_STOP:
            if(!pPort->pConBits->PEN)
            {   // stop condition done
                pPort->i2cState = I2C_STATE_IDLE;
                *pPort->pConReg  = I2CCON_OFF;       // Turn off the I2C
            }
            break;

        default:
            pPort->i2cState = I2C_STATE_IDLE;
            break;
    }
}