金牌会员
- 积分
- 1455
- 威望
- 748
- 贡献
- 425
- 兑换币
- 234
- 注册时间
- 2012-4-11
- 在线时间
- 141 小时
- 毕业学校
- 华侨大学
|
欲对ov7620的pclk更改分频,但对SCCB协议不熟悉,在网上找了个例程,但只有对寄存器进行写入的,没有读取函数,希望有做过的人帮忙看下,给加个读取函数。(用意:想先将现在有的设置读取出来,再进行修改,免得悲剧了……)
谢谢啦!
下面是基于xs128的源程序:
- #include <hidef.h> /* common defines and macros */
- #include "derivative.h" /* derivative-specific definitions */
- #define SCL PORTB_PB0
- #define SDA PORTB_PB1
- #define SDA_DR DDRB_DDRB1
- #define SCL_DR DDRB_DDRB0
- #define OUT 1
- #define IN 0
- /*************************************************
- Function: SCCB_Wait
- Description: delay
- Input: no
- Output: no
- More:no
- *************************************************/
- void SCCB_Wait(void)
- {
- unsigned char i;
- for(i=0;i<10;i++)
- {
- _asm nop;
- }
- }
- /*************************************************
- Function: SCCB_Start
- Description: signal of start
- Input: no
- Output: no
- More:no
- *************************************************/
- void SCCB_Start(void)
- {
- SDA_DR=OUT;
- SDA = 1;
- SCL = 1;
- SCCB_Wait();
- SDA = 0;
- SCCB_Wait();
- SCL = 0;
- }
- /*************************************************
- Function: SCCB_Stop
- Description: signal of stop
- Input: no
- Output: no
- More:no
- *************************************************/
- void SCCB_Stop(void)
- {
- SDA_DR=OUT;
- SDA = 0;
- SCCB_Wait();
- SCL = 1;
- SCCB_Wait();
- SDA = 1;
- SCCB_Wait();
- }
- /*************************************************
- Function: SCCB_SendAck
- Description: send ack to slave
- Input: signal of ack
- Output: no
- More:no
- *************************************************/
- void SCCB_SendAck(byte ack)
- {
-
- SDA_DR=OUT;
- SDA = ack;
- SCL = 1;
- SCCB_Wait();
- SCL = 0;
- }
- /*************************************************
- Function: SCCB_SendByte
- Description: send data to SCCB register
- Input: byte of data
- Output: return ack 1:receive ack 0:no ack
- More:no
- *************************************************/
- byte SCCB_SendByte(unsigned char bytedata)
- {
-
- unsigned char i;
- byte ack;
- 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();
- return ack;
- }
- /******************************************************
- Function: SCCB_ReceiveByte
- Description: receive data from SCCB register
- Input: no
- Output: data
- More:no
- ********************************************************/
- unsigned char SCCB_ReceiveByte(void)
- {
- unsigned char i;
- unsigned char bytedata = 0;
- SDA_DR=IN;
- for(i=0;i<8;i++)
- {
- SCL = 1;
- SCCB_Wait();
- bytedata <<= 1;
- if(SDA)
- {
- bytedata |= 0x01;
- }
- SCL = 0;
- SCCB_Wait();
- }
- return bytedata;
- }
- /******************************************************
- Function: SCCB_ByteWrite
- Description: write the data to the address
- Input: device 0xC0 write to OV6620
- 0XC1 read from OV6620
- 0x42 write to OV7620
- 0x43 read from OV7620
- Output: no
- More:no
- ********************************************************/
- void SCCB_ByteWrite(unsigned char device,unsigned char address,unsigned char bytedata)
- {
- unsigned char i;
- byte ack;
- 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
- ********************************************************/
- void main(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(;;) {} /* wait forever */
- }
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|