仿真进入不了中断,函数 EEPROM_ByteWrite 没执行,求大神解答!
#include "c8051F392.h"
#include "iic.h"
void delay(int);
sbit EN_1151P = P0^5;
main(void)
{
unsigned char temp_char[1];
EN_1151P = 0;
PCA0MD &= ~0x40; //WDT
Port_IO_Init();
Oscillator_Init();
I2C_Init();
Timer3_Init();
EA = 1 ; //开中断
while(1)
{
EEPROM_ByteWrite(0X00, 0x08);
EEPROM_ByteWrite(0X01, 0x01);
EEPROM_ByteWrite(0X02, 0x05);
EEPROM_ByteWrite(0X03, 0x07);
EEPROM_ByteWrite(0X07, 0x01);
EEPROM_ByteWrite(0X0B, 0x80);
EEPROM_ByteWrite(0X0C, 0x80);
EEPROM_ByteWrite(0X0D, 0x80);
temp_char[0] = EEPROM_ByteRead(0x0F);
delay(1000);
SMBus_ISR ();
}
}
void delay (int i)
{
int m;
for(m=0;m<i;m++);
}
//以下中断函数:
char Tran_Flag;
char xdata sRecComBuf[8];
char *pointer;
void Timer3_ISR (void) interrupt 14 //Timer3_ISR
{
SMB0CF &= ~0x80; // 禁止
SMB0CF |= 0x80; // 打开
TMR3CN &= ~0x80; // 清除
SMB_BUSY=0; //MARK
}
void SMBus_ISR (void) interrupt 7 //SMBus_ISR
{
bit FAIL = 0; // 标志位---ISR
static char i; // 发或收的计数
static bit SEND_START = 0;
switch (SMB0CN & 0xF0) //状态
{
case SMB_MTSTA:
SMB0DAT = TARGET; // 连接目标从机地址
SMB0DAT |= SMB_RW; // 连接R/W
STA = 0; // 清除开始位
i = 0; // 重置数据字节计数
break;
case SMB_MTDB:
if (ACK) // 应答
{
if (SEND_START)
{
STA = 1;
SEND_START = 0;
break;
}
if(SMB_SENDWORDADDR) // 是否发送?
{
SMB_SENDWORDADDR = 0; // 清标志位
SMB0DAT = WORD_ADDR; // 发高8位地址
/* if (SMB_RANDOMREAD)
{
SEND_START = 1;
SMB_RW = READ;
}*/
break;
}
else if(SMB_SENDWORDADDR1)
{
SMB_SENDWORDADDR1 = 0;
SMB0DAT = WORD_ADDR1; // 发低8位地址
if (SMB_RANDOMREAD)
{
SEND_START = 1; // 在下一个ACK后发STA
SMB_RW = READ;
}
break;
}
if (SMB_RW==WRITE) // 写?
{
if (i < SMB_DATA_LEN)
{
SMB0DAT = *pSMB_DATA_OUT;
pSMB_DATA_OUT++;
i++;
}
else
{
STO = 1; // 停止传输
SMB_BUSY = 0; // 清除
}
}
else {}
}
else // NACK,
{
if(SMB_ACKPOLL)
{
STA = 1; // 重发
}
else
{
FAIL = 1; // 发送失败
}
}
break;
case SMB_MRDB: //接收
if ( i < SMB_DATA_LEN )
{
*pSMB_DATA_IN = SMB0DAT;
pSMB_DATA_IN++;
i++;
ACK = 1; //设定ACK
}
if (i == SMB_DATA_LEN)
{
SMB_BUSY = 0; // 释放SMB
ACK = 0;
STO = 1;
}
break;
default:
FAIL = 1;
break;
}
if (FAIL)
{
SMB0CN &= ~0x40; // 复位
SMB0CN |= 0x40;
SMB_BUSY = 0;
}
SI=0; // 清除终端标志位
}
void EEPROM_ByteWrite( unsigned int addr, unsigned char dat ) //EEPROM_ByteWrite
{
while (SMB_BUSY); // 等待SMB空闲
SMB_BUSY = 0;
// ISR参数设置
TARGET = EEPROM_ADDR; // 设置目标从机地址
SMB_RW = WRITE; // 写标记
SMB_SENDWORDADDR = 1; // 高8位
SMB_SENDWORDADDR1 = 1; // 低8位
SMB_RANDOMREAD = 0; // 不发STA
SMB_ACKPOLL = 1; //如从机无应答将自动重发
WORD_ADDR = addr/256;
WORD_ADDR1 = addr%256;
SMB_SINGLEBYTE_OUT = dat;
pSMB_DATA_OUT = &SMB_SINGLEBYTE_OUT;
SMB_DATA_LEN = 1;
STA = 1;
}
unsigned char EEPROM_ByteRead( unsigned int addr)
{
unsigned char retval;
while (SMB_BUSY);
SMB_BUSY = 0;
TARGET = EEPROM_ADDR;
SMB_RW = WRITE;
SMB_SENDWORDADDR = 1;
SMB_SENDWORDADDR1 = 1;
SMB_RANDOMREAD = 1;
SMB_ACKPOLL = 1;
WORD_ADDR = addr/256;
WORD_ADDR1 = addr%256;
pSMB_DATA_IN = &retval;
SMB_DATA_LEN = 1;
STA = 1;
while(SMB_BUSY);
return retval;
}
|