标题:
AW60 I2C_RTC 8025驱动问题
[打印本页]
作者:
tianlan_316
时间:
2007-1-12 12:50
标题:
AW60 I2C_RTC 8025驱动问题
哪位朋友帮我分析下,问题在哪里呀?
RTC8025的时间就是读不上来,有做过个朋友给我发一个?多谢!!!
#define ERR_OK 0
unsigned char readtime_buffer[7];
unsigned char writetime_buffer[7]={0x00,0x30,0x08,0x01,0x12,0x01,0x07};
void IIC2_Init(void);
byte WriteBytesI2C(unsigned char SlaveAddress,unsigned char DateAddress,
unsigned char DateNumber,unsigned char *p_date);
byte ReadBytesI2C(unsigned char SlaveAddress,unsigned char DateAddress,
unsigned int DateNumber,unsigned char *p_date);
void Main(void)
{
IIC2_Init();
while(!WriteBytesI2C(0x64,0x00,0x07,writetime_buffer)==ERR_OK) _asm nop;
for(;;)
{
while(!ReadBytesI2C(0x64,0x00,0x07,readtime_buffer)==ERR_OK) _asm nop;
}
}
void IIC2_Init(void)
{
/* IIC1A: ADDR7=1,ADDR6=0,ADDR5=1,ADDR4=0,ADDR3=0,ADDR2=1,ADDR1=0,??=0 */
setReg8(IIC1A, 0xA4);
/* IIC1F: MULT1=0,MULT0=1,ICR5=0,ICR4=0,ICR3=0,ICR2=0,ICR1=0,ICR0=0 */
setReg8(IIC1F, 0x40);
/* IIC1S: TCF=0,IAAS=0,BUSY=0,ARBL=1,??=0,SRW=0,IICIF=1,RXAK=0 */
setReg8(IIC1S, 0x12); /* Clear the interrupt flags */
/* IIC1C: IICEN=1 */
setReg8Bits(IIC1C, 0x80);
/* IIC1C: IICEN=1,IICIE=0,MST=0,TX=1,TXAK=1,RSTA=0,??=0,??=0 */
setReg8(IIC1C, 0x98);
}
byte WriteBytesI2C(unsigned char SlaveAddress,unsigned char DateAddress,
unsigned char DateNumber,unsigned char *p_date)
{
byte Result = ERR_OK;
unsigned char temp;
IIC1C_IICEN = 1;
temp = IIC1S; /* Clear any pending interrupt */
IIC1S_IICIF=1;
IIC1C_MST = 0;
IIC1C_TX = 1; /* Select Transmit Mode */
while(IIC1S_BUSY==1) _asm nop; /* 等待总线空闲 */
IIC1C_MST =1; /* Select Master Mode (Send Start Bit) */
for(temp=0;temp<5;temp++); /* Small delay */
IIC1D = SlaveAddress;
while(IIC1S_RXAK==1) _asm nop; /* 等待从机应答 */
IIC1D = DateAddress;
while(IIC1S_RXAK==1) _asm nop; /* 等待从机应答 */
for(temp=0;temp
{
IIC1D = *p_date++;
while(IIC1S_RXAK==1) _asm nop; /* 等待从机应答 */
}
IIC1C_MST = 0; /* Send Stop Bit */
return Result;
}
byte ReadBytesI2C(unsigned char SlaveAddress,unsigned char DateAddress,
unsigned int DateNumber,unsigned char *p_date)
{
byte Result = ERR_OK;
unsigned char temp;
IIC1C_IICEN = 1;
temp = IIC1S; /* Clear any pending interrupt */
IIC1S_IICIF=1;
IIC1C_MST = 0;
IIC1C_TX = 1; /* Select Transmit Mode */
while(IIC1S_BUSY==1) _asm nop; /* 等待总线空闲 */
IIC1C_MST = 1;
for(temp=0;temp<5;temp++); /* Small delay */
IIC1D = SlaveAddress; /* Send SlaveAddress*/
while(IIC1S_RXAK==1) _asm nop; /* 等待从机应答 */
IIC1D = DateAddress;
while(IIC1S_RXAK==1) _asm nop; /* 等待从机应答 */
IIC1C_RSTA = 1; /* Send Restart bit */
for(temp=0;temp<5;temp++); /* Small delay */
IIC1D = SlaveAddress|0x01;
while(IIC1S_RXAK==1) _asm nop; /* 等待从机应答 */
IIC1C_TX = 0; /* 接收状态 */
temp = IIC1D; /* 清接收状态 */
IIC1C_TXAK = 0; /* 设置接收发送应答位 */
DateNumber--;
for(temp=0;temp
{
while(IIC1S_TCF==0) _asm nop; /* 等待接收到数据 */
*p_date++ = IIC1D;
}
IIC1C_TXAK = 1; /* 接收最后一个数据时主机不应答 */
while(IIC1S_TCF==0) _asm nop; /* 等待接收到数据 */
*p_date = IIC1D;
IIC1C_MST = 0; /* Send Stop Bit */
return Result;
}
[此贴子已经被作者于2007-1-12 12:08:40编辑过]
[此贴子已经被作者于2007-1-12 12:50:55编辑过]
作者:
strongchen
时间:
2007-1-12 14:15
你有没有调试过程序停在哪里,有没有用示波器看过通讯波形?
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/)
Powered by Discuz! 7.0.0