I remember that the STC microcontroller has a chip that can be used for single-step simulation. I didn't expect Qinheng to be able to do it, so I tried it today and it works well.
It’s actually very simple:
1. Add ISD51.A51 and ISD51.H to the project;
2. Initialize the serial port, configure the appropriate baud rate, and finally enable the global interrupt;
3. Select the appropriate ISD51 initialization function;
ISDinit(): Initialize and run the user program. If KEIL successfully communicates with the microcontroller, the program will terminate immediately.
ISDwait(): Initialize ISD51 and wait for KEIL to connect
ISDcheck(): Periodically check the ISD51 connection
4. Compile the user program and burn it into the microcontroller;
5. Select ISD51 In-system Debugger in KEIL -> option for target -> DEBUG setting, and set the serial port baud rate corresponding to the ISD51 serial port initialization in setup.
6. Click the DEBUG button to enter hardware debugging mode.
ISD51 interface functions can be found in the KEIL help document.
Is that really the case?
I modified the ID reading program in the simulation routine:
#include "CH554.H"
#include "debug.h"
#include "STDIO.H"
//#include <absacc.h> /* Direct access to memory areas. */
#include "ISD51.H" /* Find it at the location like 'C:\Keil\C51\ISD51' */
UINT8 str[] = "hello CH55X!\n";
UINT8 t = 0;
sbit LED = P1^0;
#define ROM_CHIP_ID_ADDR 0x20
/*******************************************************************************
* Function Name : GetChipID(void)
* Description : 获取ID号和ID号和校验
* Input : None
* Output : None
* Return : None
*******************************************************************************/
UINT32 GetChipID( void )
{
UINT8 d0, d1;
UINT16 xl, xh;
E_DIS = 1; //避免进入中断
d0 = *(PUINT8C)( ROM_CHIP_ID_ADDR + 0 );
d1 = *(PUINT8C)( ROM_CHIP_ID_ADDR + 1 ); //ID号低字
xl = ( d1 << 8 ) | d0;
d0 = *(PUINT8C)( ROM_CHIP_ID_ADDR + 2 );
d1 = *(PUINT8C)( ROM_CHIP_ID_ADDR + 3 ); //ID号高字
xh = ( d1 << 8 ) | d0;
d0 = *(PUINT8C)( ROM_CHIP_ID_ADDR + 6 );
d1 = *(PUINT8C)( ROM_CHIP_ID_ADDR + 7 ); //ID校验和
E_DIS = 0;
if ( (UINT16)( xl + xh ) != (UINT16)( ( d1 << 8 ) | d0 ) ) return( 0xFFFFFFFF );//校验ID号
return( ( (UINT32)xh << 16 ) | xl );
}
/*******************************************************************************
* Function Name : CopyChipID(void)
* Description : 获取ID号,因为Flash双字节访问,低字节在前,使用时要注意
* Input : PUINT32X buf
* Output : None
* Return : None
*******************************************************************************/
void CopyChipID( PUINT32X buf )
{
E_DIS = 1;
*( (PUINT16X)buf + 0 ) = *(const unsigned short code *)( ROM_CHIP_ID_ADDR + 0 );
*( (PUINT16X)buf + 1 ) = *(const unsigned short code *)( ROM_CHIP_ID_ADDR + 2 );
E_DIS = 0;
}
void main( void )
{
UINT32 x;
CfgFsys();
mDelaymS(10);
mInitSTDIO(); /* Baudrate = 57600, 8, 1, N */
EA = 1;
printf("INIT OK!\n");
printf("%s",str);
ISDwait(); /* Wait until Debugger sends 0xA5, comment it if not nessery. */
while(1)
{
t++; /* Add t to watch windos, this can be changged by manual. */
ISDcheck(); /* Wait util Debugger send 0xA5, if ISD51 UART already initialized. */
LED ^= 1; /* Toggle P1^0 bit. */
mDelaymS(10);
CopyChipID(&x);
printf("ID:%lx\n",x);
}
}
The simulation results are as follows:
I think the simulation of Biheng is better. It doesn't cost anything. Just test two programs and arrange the functions.
Attached simulation routine:
1507967901967569.rar
(159.06 KB, downloads: 8)
This content is originally created by EEWORLD forum user ddllxxrr . If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source
|