Code Change ASM to C Code

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Code Change ASM to C Code

1,369 次查看
michaellee
Contributor I

Dear All

 

Below I want to change the ASM to C code.

 

Core is S12P.

 

 

Asm ANDCC # 0x7Fu;  // Logical AND with CCR

Asm JSR Send_Command;  Jump to Subroutine Send_Command Function

Asm SEI;  Set interrupt bit

Asm CLI  Clear Interrupt bit

Asm STOP  STOP

 

Thank BR

标签 (1)
0 项奖励
回复
1 回复

960 次查看
RadekS
NXP Employee
NXP Employee

Hi Michael,

The asm CLI; and asm SEI; commands are defined in hidef.h file as EnableInterrupts; and DisableInterrupts; commands.

The same format might be used for other commands. For example:

#define ClearSbit {__asm ANDCC # 0x7Fu;}

or

#define StopMode {__asm STOP;}

The code for flash command with wait loop in RAM might be defined as an array of opcodes. For example:

static byte Send_Command[]=

{

  0x14, 0x10, 0x1C, 0x01, 0x06, 0x80, 0x1F, 0x01, 0x06, 0x80, 0xFB, 0x10, 0xEF, 0x3D

};

And the command for execution will be

asm JSR Send_Command;

or you may directly write C code and let linker to place it into RAM. For example:

#pragma CODE_SEG __NEAR_SEG MY_RAM

void Send_Command2(void)

{

DisableInterrupts;      //start critical section

  FSTAT_CCIF = 1;        //launch command

  while(FSTAT_CCIF == 0); //wait for done

EnableInterrupts;      //end critical section

}

#pragma CODE_SEG DEFAULT

And the command for execution will be

Send_Command2();

Note: In CW5.1, the MY_RAM must be a user segment defined in prm file. Placing this code into DEFAULT_RAM doesn’t work. For example:

SEGMENTS

//..

    RAM_ROUTINE  = READ_WRITE    0x3FF0 TO 0x3FFF;        //space for flash routine

//..

END

PLACEMENT

//..

MY_RAM INTO  RAM_ROUTINE;

//..

END

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 项奖励
回复