📄 12c508.c
字号:
/////////////////////////////////////////////////////////////////////////
//// pic12c508.c program for ov7950 ////
//// OmniVision Serial Camera Control Bus (SCCB) ////
//// Configure the CCS prototype card as follows: ////
//// 12C508 Protoboard ////
//// 1 VDD +3.3V ////
//// 2 GP5/OSC1/CLKIN NC ////
//// 3 MIRROR/OSC2 MIRROR 0 ENABLE ////
//// 4 GP3/MCLR/VPP +3.3V ////
//// 5 RST/T0CKI RST ////
//// 6 SIO_C SIOC ////
//// 7 SIO_D SIOD ////
//// 8 VSS GND ////
//// This example will work with the PCB and PCM compilers. The ////
//// following conditional compilation lines are used to include a ////
//// valid device for each compiler. Change the device and clock ////
//// for your hardware if needed. ////
/////////////////////////////////////////////////////////////////////////
//// This source code may only be used by licensed users of the CCS ////
//// C compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, ////
//// reproduction or distribution is permitted without written ////
//// permission. Derivative programs created using this software ////
//// in object code form are not restricted in any way. ////
/////////////////////////////////////////////////////////////////////////
#if defined(__PCB__)
#include <12C508.h>
#include <Intrins.h>
#fuses INTRC,NOWDT,NOPROTECT, NOMCLR
#use delay(clock=4000000)
#define SIO_D PIN_B0
#define SIO_C PIN_B1
#define RST PIN_B2
#define GP3 PIN_B3
#define MIRROR PIN_B4 //0 ENABLE
#define GP5 PIN_B5 // NC
#elif defined(__PCM__)
#endif
void main() {
#if defined(__PCB__)
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
// See .h file for other special
// options for setup_counters
#else
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
#endif
while (TRUE) {
if (!input (GP3))
RST=0 ;
else
RST=1 ;
}
}
void nops(void)
{
Nop;
nop;
nop;
nop;
nop;
}
void hnops(void)
{
nop;
nop;
}
unsigned char Read_CMOS(unsigned char DeviceAddress,unsigned char RegisterAddress)
{
unsigned char bdata Buffer_Data;
bit Buffer_Data0=Buffer_Data^0;
bit Buffer_Data1=Buffer_Data^1;
bit Buffer_Data2=Buffer_Data^2;
bit Buffer_Data3=Buffer_Data^3;
bit Buffer_Data4=Buffer_Data^4;
bit Buffer_Data5=Buffer_Data^5;
bit Buffer_Data6=Buffer_Data^6;
bit Buffer_Data7=Buffer_Data^7;
Buffer_Data=DeviceAddress;
F0=0;
//SIO_E=0;
//nops();
SIO_C=1;
SIO_D=1;
nops();
SIO_D=0;
nops();
SIO_C=0;
nops(); //Start
SIO_D=Buffer_Data7;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit7
SIO_D=Buffer_Data6;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit6
SIO_D=Buffer_Data5;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit5
SIO_D=Buffer_Data4;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit4
SIO_D=Buffer_Data3;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit3
SIO_D=Buffer_Data2;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit2
SIO_D=Buffer_Data1;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit1
SIO_D=Buffer_Data0;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit0
SIO_C=1;
if(SIO_D)
{
if(SIO_D)
F0=1;
}
else
nops();
SIO_C=0;
nops(); //check Ack
Buffer_Data=RegisterAddress;
SIO_D=Buffer_Data7;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit7
SIO_D=Buffer_Data6;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit6
SIO_D=Buffer_Data5;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit5
SIO_D=Buffer_Data4;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit4
SIO_D=Buffer_Data3;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit3
SIO_D=Buffer_Data2;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit2
SIO_D=Buffer_Data1;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit1
SIO_D=Buffer_Data0;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit0
SIO_C=1;
if(SIO_D)
{
if(SIO_D)
F0=1;
}
else
nops();
SIO_C=0;
nops(); //check Ack
//read data
Buffer_Data=0xff;
SIO_C=1;
hnops();
Buffer_Data7=SIO_D;
hnops();
SIO_C=0;
nops(); //bit7
SIO_C=1;
hnops();
Buffer_Data6=SIO_D;
hnops();
SIO_C=0;
nops(); //bit6
SIO_C=1;
hnops();
Buffer_Data5=SIO_D;
hnops();
SIO_C=0;
nops(); //bit5
SIO_C=1;
hnops();
Buffer_Data4=SIO_D;
hnops();
SIO_C=0;
nops(); //bit4
SIO_C=1;
hnops();
Buffer_Data3=SIO_D;
hnops();
SIO_C=0;
nops(); //bit3
SIO_C=1;
hnops();
Buffer_Data2=SIO_D;
hnops();
SIO_C=0;
nops(); //bit2
SIO_C=1;
hnops();
Buffer_Data1=SIO_D;
hnops();
SIO_C=0;
nops(); //bit1
SIO_C=1;
hnops();
Buffer_Data0=SIO_D;
hnops();
SIO_C=0;
nops(); //bit0
SIO_C=1;
if(SIO_D)
{
if(SIO_D)
F0=1;
}
else
nops();
SIO_C=0;
nops(); //check Ack
SIO_C=1;
SIO_D=0;
nops();
SIO_D=1;
nops();
SIO_C=1;
SIO_D=1; //stop
return Buffer_Data;
}
bit Write_COMS(unsigned char DeviceAddress,unsigned char RegisterAddress,char Write_Data)
{
ACC=DeviceAddress;
F0=0;
//SIO_E=0;
//nops();
SIO_C=1;
SIO_D=1;
nops();
SIO_D=0;
nops();
SIO_C=0;
nops(); //Start
SIO_D=ACC^7;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit7
SIO_D=ACC^6;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit6
SIO_D=ACC^5;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit5
SIO_D=ACC^4;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit4
SIO_D=ACC^3;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit3
SIO_D=ACC^2;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit2
SIO_D=ACC^1;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit1
SIO_D=ACC^0;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit0
SIO_C=1;
if(SIO_D)
{
if(SIO_D)
F0=1;
}
else
nops();
SIO_C=0;
nops(); //check Ack
ACC=RegisterAddress;
SIO_D=ACC^7;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit7
SIO_D=ACC^6;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit6
SIO_D=ACC^5;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit5
SIO_D=ACC^4;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit4
SIO_D=ACC^3;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit3
SIO_D=ACC^2;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit2
SIO_D=ACC^1;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit1
SIO_D=ACC^0;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit0
SIO_C=1;
if(SIO_D)
{
if(SIO_D)
F0=1;
}
else
nops();
SIO_C=0;
nops(); //check Ack
ACC=Write_Data;
SIO_D=ACC^7;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit7
SIO_D=ACC^6;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit6
SIO_D=ACC^5;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit5
SIO_D=ACC^4;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit4
SIO_D=ACC^3;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit3
SIO_D=ACC^2;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit2
SIO_D=ACC^1;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit1
SIO_D=ACC^0;
SIO_C=1;
nops();
SIO_C=0;
nops(); //bit0
SIO_C=1;
if(SIO_D)
{
if(SIO_D)
F0=1;
}
else
nops();
SIO_C=0;
nops(); //check Ack
SIO_C=1;
SIO_D=0;
nops();
SIO_D=1;
nops();
SIO_C=1;
SIO_D=1; //stop
return F0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -