LPC2368 study notes (1) - light up the LED

LPC2368 study notes (1), lighting up the LED

foreword

LPC2368 is a very powerful microcontroller based on ARM7TDMI-S processor, which can run at up to 72MHz operating frequency, up to 512kB of on-chip Flash program memory, with in-system programming (ISP) and in-application programming (IAP) Function, there is up to 32kB SRAM on the ARM local bus, and has a wealth of peripherals, such as SD/MMC memory card interface, 10-bit A/D converter, 10-bit D/A converter, UART interface, CAN interface, SPI Interface, USB2.0 (with on-chip PHY and related DMA controller) interface, I2C interface, I2S frequency interface, SSP controller, Ethernet MAC, timer, RTC, etc.

1. Introduction to the development environment

LPC2368 supports a variety of development environments, including
1. LPCXpresso IDE
2. ADS
3. MDK
4. IAR Embedded Workbench for ARM
5. SEGGER Embedded Studio

Among them, SEGGER Embedded Studio is currently free for individual users, but in order to quickly become familiar with the development of LPC2368, I use MDK for program development.

2. New construction

  1. Open MDK, select the microcontroller model as LPC2368, and add the startup file LPC2300.s to the project . The interface is as shown in the figure:
  2. Write a program to light up an LED. The program is as shown in the figure:
  3. Configure the project.
    1. The output item configuration is shown in the figure:
    2. The debug item configuration is shown in the figure:
    3. The utilities item configuration is shown in the figure:
  4. Download the program. Click to start downloading the program, and the output window of successful program download is displayed as shown in the figure: If the download fails, there will be a prompt, please reconfigure according to the above content.
  5. Observe the experimental phenomenon.

Of course, you can also use the NXP startup file to create a new project. The steps are as follows:
1. Find the LPC2368 program on the NXP official website. You can find it at this website , and there are also chip information, software services and other information.
2. Download and open the routine of LPC2368
3. After opening, it is like this, common is the general configuration file, and the others are the driver routines of some peripherals. There are two folders in the common folder, the inc folder and the src folder, as shown in the following figure: The inc folder contains , the src folder contains
4. Copy the common folder to the project directory and add it to the project , The project configuration is as follows: The c/c++ item configuration is as shown in the figure below. The linker item configuration is as shown below . The configuration of other items is the same as the above configuration.
5. Compile and run, and observe the experimental phenomenon.

3. Program introduction

3.1 Program source code

#include <LPC23xx.H>

int main(void)
{
    //配置P0.29 P0.30 为输出模式
    IODIR0 |= 1 << 29;
    IODIR0 |= 1 << 30;

    while(1)
    {
        //配置P0.29 P0.30 输出低电平
        //由于硬件原因LED在低电平时点亮 在高电平熄灭
        IOCLR0 |= 1 << 29;
        IOCLR0 |= 1 << 30;
    }
}

3.2 GPIO register introduction

register name Register function size Configuration parameters reset value
IODIRx (GPIO port direction register) Configure GPIO as input/output mode 32 bit When the xth bit of the register is configured as 0, the corresponding port is configured as input mode; when the xth bit of the register is configured as 1, the corresponding port is configured as output mode 0
IOSETx (GPIO port set register) Configure GPIO output high level 32 bit When the xth bit of the register is configured as 0, the corresponding port state remains unchanged; when the xth bit of the register is configured as 1, the corresponding port outputs a high level 0
IOCLRx (GPIO Port Reset Register) Configure GPIO output low level 32 bit When the xth bit of the register is configured as 0, the corresponding port state remains unchanged; when the xth bit of the register is configured as 1, the corresponding port outputs a low level 0

For other registers, please refer to the LPC2386 data sheet.

4. Conclusion

Lighting up the LED is an entry point for learning single-chip microcomputers. After getting the peripheral configuration, the next step is to write the program framework. The actual configuration of LPC2368 is similar to that of STM32. There are some official peripheral-driven routines, but it is not as powerful as STM32 in terms of peripheral library functions. As far as the platform is concerned, it is worth exploring and trying to write a function library by yourself.

5. References

[1]. LPC2368 data sheet

Guess you like

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