This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Make and call a C function

Using Keil MDK Lite v 5.22, writing code in C for nRF52, with SDK 12.

Example code works.

How does one declare a function, define it, and call it?

I've created a new module: myFunction.c and a header file: myFunction.h.

I added a folder under the project folder named: myFunction. I added the C file under that folder. I couldn't figure out how to add a header file, so I added the function prototype to the header file stdio.h.

Here's the declaration in stdio.h: void myFunction(void);

In the C file, the definition looks like this: void myFunction(void) { int myVar = 0; myVar++;

if(myVar ==1) {
myVar = 0; } }

Then, I called the function from main(), like this: myFunction();

The code compiles without issue, uploads to the dev board, and runs. When I debug and break on the function, the code breaks as expected, but it skips over the steps in the function.

I'm new to this system, and this is the first time I'm adding a function. I'm sure there's a simple, fundamental step missing, but I need some help.

Any ideas? Can anyone point me to a tutorial that describes adding a function?

Thanks,

Related