SCCB.docx
《SCCB.docx》由会员分享,可在线阅读,更多相关《SCCB.docx(12页珍藏版)》请在冰豆网上搜索。
SCCB
以上来自西安交大技术报告
以上来自WJ续
#include/*commondefinesandmacros*/
#include"derivative.h"/*derivative-specificdefinitions*/
#defineSCLPORTB_PB0
#defineSDAPORTB_PB1
#defineSDA_DRDDRB_DDRB1
#defineSCL_DRDDRB_DDRB0
#defineOUT1
#defineIN0
/*************************************************
Function:
SCCB_Wait
Description:
delay
Input:
no
Output:
no
More:
no
*************************************************/
voidSCCB_Wait(void)
{
unsignedchari;
for(i=0;i<10;i++)
{
_asmnop;
}
}
/*************************************************
Function:
SCCB_Start
Description:
signalofstart
Input:
no
Output:
no
More:
no
*************************************************/
voidSCCB_Start(void)
{
SDA_DR=OUT;
SDA=1;
SCL=1;
SCCB_Wait();
SDA=0;
SCCB_Wait();
SCL=0;
}
/*************************************************
Function:
SCCB_Stop
Description:
signalofstop
Input:
no
Output:
no
More:
no
*************************************************/
voidSCCB_Stop(void)
{
SDA_DR=OUT;
SDA=0;
SCCB_Wait();
SCL=1;
SCCB_Wait();
SDA=1;
SCCB_Wait();
}
/*************************************************
Function:
SCCB_SendAck
Description:
sendacktoslave
Input:
signalofack
Output:
no
More:
no
*************************************************/
voidSCCB_SendAck(byteack)
SDA_DR=OUT;
SDA=ack;
SCL=1;
SCCB_Wait();
SCL=0;
}
/*************************************************
Function:
SCCB_SendByte
Description:
senddatatoSCCBregister
Input:
byteofdata
Output:
returnack1:
receiveack0:
noack
More:
no
*************************************************/
byteSCCB_SendByte(unsignedcharbytedata)
unsignedchari;
byteack;
SDA_DR=OUT;
for(i=0;i<8;i++)
{
if(bytedata&0x80)
SDA=1;
else
SDA=0;
bytedata<<=1;
SCCB_Wait();
SCL=1;
SCCB_Wait();
SCL=0;
SCCB_Wait();
}
SDA=1;
SDA_DR=IN;
SCCB_Wait();
SCL=1;
SCCB_Wait();
ack=SDA;
SCL=0;
SCCB_Wait();
returnack;
}
/******************************************************
Function:
SCCB_ReceiveByte
Description:
receivedatafromSCCBregister
Input:
no
Output:
data
More:
no
********************************************************/
unsignedcharSCCB_ReceiveByte(void)
{
unsignedchari;
unsignedcharbytedata=0;
SDA_DR=IN;
for(i=0;i<8;i++)
{
SCL=1;
SCCB_Wait();
bytedata<<=1;
if(SDA)
{
bytedata|=0x01;
}
SCL=0;
SCCB_Wait();
}
returnbytedata;
}
/******************************************************
Function:
SCCB_ByteWrite
Description:
writethedatatotheaddress
Input:
device0xC0writetoOV6620
0XC1readfromOV6620
0x42writetoOV7620
0x43readfromOV7620
Output:
no
More:
no
********************************************************/
voidSCCB_ByteWrite(unsignedchardevice,unsignedcharaddress,unsignedcharbytedata)
{
unsignedchari;
byteack;
for(i=0;i<20;i++)
{
SCCB_Start();
ack=SCCB_SendByte(device);
if(ack==1)
{
SCCB_Stop();
continue;
}
ack=SCCB_SendByte(address);
if(ack==1)
{
SCCB_Stop();
continue;
}
ack=SCCB_SendByte(bytedata);
if(ack==1)
{
SCCB_Stop();
continue;
}
SCCB_Stop();
if(ack==0)break;//file:
//正/常,跳出循环
}
}
/******************************************************
Function:
main
Description:
no
Input:
no
Output:
no
More:
no
********************************************************/
voidmain(void){
EnableInterrupts;
SDA_DR=1;
SCL_DR=1;
//SCCB_ByteWrite(0xC0,0x06,0xC0);//ov6620设置函数
//SCCB_ByteWrite(0xC0,0x03,0x80);
//SCCB_ByteWrite(0xC0,0x0C,0x20);
SCCB_ByteWrite(0x42,0x12,0x64);//7620镜像设置缺省值0x24
SCCB_ByteWrite(0x42,0x06,0xA0);//7620亮度调节0xff最大0x00最小
SCCB_ByteWrite(0x42,0x03,0x80);//7620对比度调节
SCCB_Wait();
for(;;){}/*waitforever*/
}