[Bluetooth development] CC2540 novice learning to light up LED

  Today, continue the content of the blog in the previous chapter. In the previous section, we talked about how to install the IAR compilation software. Let's start writing the first simple program today, work hard and make progress together. Before learning, not all the novice understand, the basics still need a little bit of C language, and a few simple sentences can also complete the task of lighting up the LEDs that we are going to do in this section.

First, install IAR and open our IAR


Then


The created image is as follows


Click OK

Here comes our first project


After that, you need to create a .C suffix file, which is the main.c file that is essential for future projects.




Click Save to create a complete blank project.


Add our main.c file to the project

So we can start adding the code in, because we are the version of CC2540, different versions correspond to different models


This is the code I wrote, the text version is attached below for easy copy and paste

/**************************************/
/* CNPF Technology */
/* Bluetooth 4.0 development CC2540 */
/* Routine name: light up the LED */
/* Build time: 2018/04/17 */
/*Description: Light up LED1 */
/***************************************/
#include<ioCC2540.h>

#define LED P1_0 //Define P10 port as LED control terminal

void IO_Init(void) //Here is the function initialization package
{
  P1DIR |= 0x01; //P1_0 is defined as output   
}

void main(void) //Main function (the first step of the program starts)
{   
  IO_Init(); //call initializer
  LED=1; //Light LED1
  while(1); // infinite loop
}

Experimental phenomenon: You can see that the LED light connected to the P1_0 interface is always on on the development board.

The development board has not been made for the time being. Later, I made my own development board and attached pictures of the corresponding experimental phenomena. If you are interested, you can contact me privately.

Well, that's it for today, tomorrow will update the flexible use and fun brought about by the lighting of LEDs.

I hope that those who read my blog, find the problem and give me opinions, make progress together and learn together.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325939295&siteId=291194637