|
Keil3 的 debug下编写ini文件 仿真?
[复制链接]
最近发现 keil Debug下可以通过编写ini文件仿真,比如我的项目里就有一个I2C通信的ini文件
代码如下:
DEFINE int SADR // SADR is I2C EEP Slave Address
DEFINE int I2C_Base // Map Base Address
MAP 0x50000000, 0x5000FFFF READ WRITE // Map User Memory region
I2C_Base = 0x50000000;
SADR = 0x24; // Default I2C EEP Slave Address
signal void I2C_Memory(void)
{
unsigned long adr;
adr = I2C_Base;
while (1)
{
wwatch (I2C_OUT); // Wait for data from Microcontroller
if(I2C_OUT == 0x0100)
printf ("START condition\n");
else if(I2C_OUT == 0xFFFF)
printf ("STOP condition\n");
else
printf ("<>\n", I2C_OUT);
while (I2C_OUT == 0x0100) // START detected
{
wwatch (I2C_OUT); // Wait for data from Microcontroller
printf ("DevAddr: 0x%2.2X\n", I2C_OUT>>1);
if (I2C_OUT > 0xFF) continue;
if ((I2C_OUT >> 1) != SADR) continue; // test if Slave is addressed
I2C_IN = 0xFF00; // ACK to Microcontroller
if (I2C_OUT & 1) // Slave Read
{
while (1)
{
I2C_IN = _RBYTE(adr); // Read Byte from Memory
printf ("ReadData: 0x%2.2X\n", I2C_IN);
adr++; // Increment Address
wwatch (I2C_OUT); // Wait for ACK from Microcontroller
if (I2C_OUT != 0xFF00) break;
}
}
else // Slave Write
{
wwatch (I2C_OUT); // Wait for data from Microcontroller
printf ("MemAddr: 0x%2.2X\n", I2C_OUT);
if (I2C_OUT > 0xFF) continue;
adr = I2C_Base + I2C_OUT; // Set Memory Address
I2C_IN = 0xFF00; // ACK to Microcontroller
/////////////////////////////////////--------Added by XJ.Liu
if(I2C_OUT & 0x80) // LSByte of memory address >= 0x80 : device has 2-byte memory address
{
wwatch (I2C_OUT);
printf ("MemAddr(MSB): 0x%2.2X\n", I2C_OUT);
if (I2C_OUT > 0xFF) continue;
adr = adr + (I2C_OUT << 8);
I2C_IN = 0xFF00;
}
/////////////////////////////////////
while (1)
{
wwatch (I2C_OUT); // Wait for data from Microcontroller
if (I2C_OUT > 0xFF)
{
if(I2C_OUT == 0x0100)
printf ("START condition\n");
else if(I2C_OUT == 0xFFFF)
printf ("STOP condition\n");
else
printf ("<>\n", I2C_OUT);
break;
}
else
printf ("WriteData: 0x%2.2X\n", I2C_OUT);
_WBYTE (adr, I2C_OUT); // Store Byte in Memory
adr++; // Increment Address
I2C_IN = 0xFF00; // ACK to Microcontroller
}
}
}
}
}
I2C_Memory()
这样在Debug调试时就可以仿真I2C通信 很好奇!
这是怎么实现的呢 大家有没有这方面的资料啊!
必重谢!
|
|