I undertake a project about Electronic Control Unit for an electric vehicle with S912XEQ512F1MAA MCU. How to create subroutines in C language?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I undertake a project about Electronic Control Unit for an electric vehicle with S912XEQ512F1MAA MCU. How to create subroutines in C language?

Jump to solution
583 Views
afardilao
Contributor I

Hello everybody

 

Currently, I am undertaking a project about Electronic Control Unit for an electric vehicle and I want to programme the microcontroller unit in C language. I have more experience with assembler language and I would like to solve some doubts about C language in Freescale microcontrollers. For instance, if I have the following assembler code, how can I implement the subroutines in C language:

 

MOVB      #$FF,PORTB

JSR          Delay

MOVB       #$00, PORTB

JSR          Delay   

 

 

Delay

                 LDAA #$FF

Delay_Loop                

                 DECA         

                 BEQ    End_Delay

                 BRA    Delay_Loop   

End_Delay

                 RTS

 

I await your prompt response.

 

Good day

Labels (1)
Tags (2)
1 Solution
404 Views
iggi
NXP Employee
NXP Employee

Hi,

Here are some various example codes for S12XE line of MCUs.

S12X Examples Pack

When you open a project in CodeWarrior IDE and in the project open a source code file such as main.c, then mouse right click will show you a menu and there is option disassemble. This will allow you to see all C code in assembler language, so you can see how some functions are in C and assembler.

The particular assembler code you post is in C:

//*********************************

void Delay (void)

{

unsigned int i;

 

for(i=0; i<10000; i++)

  {

      asm nop;

      asm nop;

      asm nop;

  }

}

//*********************************

void main (void)

{

PORTB = 0xFF;

Delay();

PORTB = 0x00;

Delay();

}

//********************************

On the web you can find many C language tutorials and documents for learning programming language. But, still if you know assembler well, you can use it.

Regards,

iggi

View solution in original post

2 Replies
405 Views
iggi
NXP Employee
NXP Employee

Hi,

Here are some various example codes for S12XE line of MCUs.

S12X Examples Pack

When you open a project in CodeWarrior IDE and in the project open a source code file such as main.c, then mouse right click will show you a menu and there is option disassemble. This will allow you to see all C code in assembler language, so you can see how some functions are in C and assembler.

The particular assembler code you post is in C:

//*********************************

void Delay (void)

{

unsigned int i;

 

for(i=0; i<10000; i++)

  {

      asm nop;

      asm nop;

      asm nop;

  }

}

//*********************************

void main (void)

{

PORTB = 0xFF;

Delay();

PORTB = 0x00;

Delay();

}

//********************************

On the web you can find many C language tutorials and documents for learning programming language. But, still if you know assembler well, you can use it.

Regards,

iggi

404 Views
afardilao
Contributor I

Hello Iggi

Thanks for your response. Your information has been useful in my project, although I had to make the adjustment of time in the for structure. In several examples, I has seen each library has two indepent files, one with as *,c directory and the another as *.h directory. In this case, how can I create the delay library in my project.

On the other hand, I need to display information with a graphic LCD 128x64 Built-in controller ( S6B0108 ), do you know where can I find any library in order to manage this display?. 

I await your prompt response.

Best regars,

Anderson

0 Kudos