本帖最后由 jlgcumt 于 2011-11-24 20:04 编辑
void SMBUS_ISR (void) interrupt 7
{
switch (SMB0STA)
{
case 0x08:
//起始条件 重复起始条件
SMB0DAT = SMBUSAddr;
STA = 0;
break;
case 0x10:
SMB0DAT = SMBUSAddr | 0x01;
STA = 0;
break;
case 0x18:
//从地址+w已发
收到ACK
SMB0DAT = *SMBUSBuf++ ;
SMBUSNbyte = SMBUSNbyte-1;
break;
case 0x20:
//从地址+w已发
收到NACK
{
WRFinishStatus = 0x21 ;
STO = 1;
break;
}
case 0x28:
//数字字节已发出,收到ACK
{
if(SMBUSNbyte > 0)
{
SMB0DAT = *SMBUSBuf++;
SMBUSNbyte = SMBUSNbyte-1;
break ;
}
else if((WRFlag == 1) && (SMBUSNbyte==0))
//当前操作为读
{
STA = 1; //重启总线
break ;
}
else
{
WRFinishStatus = 0x11 ; // 操作成功置1
STO = 1;
// 中止 I2C
break ;
// 禁止使能I2C
}
break ;
}
case 0x30: //数字字节已发出,收到NACK
{
WRFinishStatus = 0x21;
//操作失败
STO = 1;
break;
}
case 0x38:
//竞争失败
WRFinishStatus = 0x21;
//操作失败
STO = 1;
break;
case 0x40: //从地址+R已发出 收到ACK
{
AA = 0;
break ;
//
if(SMBUSNbyte<=1)
//
AA = 0;
//
else
//
AA = 1;
}
case 0x48: //从地址+R已发出,收到NACK
{
WRFinishStatus = 0x21;
//操作失败
STO = 1;
break ;
}
case 0x50: //数字字节收到,ACK已发出
{
//
aa = SMB0DAT;
//
WRFinishStatus = 0x11;
//操作成功
//
STO = 1;
break ;
/*
*SMBUSBuf++ = SMB0DAT;
SMBUSNbyte--;
if(SMBUSNbyte<=1)
AA = 0;
else
AA = 1;
break ; */
}
case 0x58: //数字字节收到,NACK已发出
{
aa = SMB0DAT;
//
*SMBUSBuf++ = SMB0DAT;
//
SMBUSNbyte--;
STO = 1;
WRFinishStatus = 0x11;
//操作成功
break;
}
default:
{
SI = 0;
break;
}
}
SI = 0;
} |