从头开始用 C 语言编程 ARM

发布于 2024-11-18 02:25:02 字数 410 浏览 4 评论 0原文

我有一个来自嵌入式艺术家的 LPC3141 开发人员套件,并且我已经成功创建了基于 eclipse 的免费 IDE,可以成功为 ARM 进行编译。我使用附带的信号灯示例测试了我的 IDE。我有一个启动代码和一个可以工作的链接器脚本,从现在开始我将使用它们。

现在我想学习如何从无到有开始我自己的眨眼程序。我首先要编程什么?是 GPIO 寄存器、定时器寄存器、uart 寄存器……???第一件事是什么?我需要写的东西实际上是 HAL 吗?我已经订购了这本书,什么你认为吗?

谢谢。

问候 齐加

I have a LPC3141 developers kit from Embeded artists and i have sucessfully created free IDE based on eclipse that can sucesfully compile for ARM. I tested my IDE using included blinker example. I have a startup code and a linker script which work and i will use them from now on.

Now i would like to learn how to start my own blinker program from nothing. What do i have to program first? Is it GPIO registers, timer registers, uart registers,... ??? What is the very first thing? Is the thing i need to write in fact a HAL? I allready ordered this book, what do you think?

Thank you.

Regards Ziga

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬心 2024-11-25 02:25:02

这些页面可能有用,同一系列,不同的芯片。

http://lpcstuff.blogspot.com/2008/09/lpc -2148-blinker-1.html

http://lpcstuff.blogspot.com/2010 /08/nxp-mbed-aint-so-bad-after-all.html

您不需要计时器或中断或类似的东西来开始。有一个(长)while 的 C 循环计数,然后更改 GPIO 的状态。您需要将 GPIO 配置为输出。并小心不要让 C 编译器优化您的延迟循环。稍后您可以开始轮询计时器,然后如果您认为确实需要,则可以中断。

These pages might be useful, same family, different chips.

http://lpcstuff.blogspot.com/2008/09/lpc-2148-blinker-1.html

http://lpcstuff.blogspot.com/2010/08/nxp-mbed-aint-so-bad-after-all.html

You wont need timers or interrupts or anything like that to get started. have a C loop count for a (long) while then change the state of the gpio. You will need to configure the gpio as an output. And careful not to have the C compiler optimize out your delay loop. Later you can get into polling the timer, then after that interrupts if you feel you really need to.

↙温凉少女 2024-11-25 02:25:02

开始使用 Arm 微控制器非常容易。您所需要做的就是阅读微控制器的数据表和用户手册。您可以在用户手册中找到有关外设和寄存器的所有文档

https:/ /www.nxp.com/docs/en/user-guide/UM10362.pdf ,此代码适用于lpc2148():

例如

#include <lpc214x.h> // this header file is provided by nxp and contains all register addresses

/* delay function is using only for loop to generate delay. 
For accurate timing, use a hardware timer/counter (systick timer is recommended (because it is so easy and configurable via cmsis functions that are provided by ARM)) */
void delay_ms(unsigned int count)
{
  unsigned int j=0,i=0;
  for(j=0;j<count;j++)
  {
    for(i=0;i<3000;i++)
        asm("nop");
  }
}

/* main function */
int main() 
{
    PINSEL2 = 0x000000;  //Configure the P1 Pins for GPIO;
    IODIR1 = 0xffffffff; //Configure the P1 pins as OUTPUT;

    while(1)
    {
       IOSET1 = 0xffffffff;     // Make all the Port pins as high  
       delay_ms(1000);

       IOCLR1 = 0xffffffff;     // Make all the Port pins as low  
       delay_ms(1000);
    }
    return 0;
}

it is really easy to get started with arm microcontrollers. all you need to do is reading the datasheet and user manual of your microcontroller. you can find all documentation about peripherals and registers in the user manual

https://www.nxp.com/docs/en/user-guide/UM10362.pdf

for example, this code is for lpc2148 ():

#include <lpc214x.h> // this header file is provided by nxp and contains all register addresses

/* delay function is using only for loop to generate delay. 
For accurate timing, use a hardware timer/counter (systick timer is recommended (because it is so easy and configurable via cmsis functions that are provided by ARM)) */
void delay_ms(unsigned int count)
{
  unsigned int j=0,i=0;
  for(j=0;j<count;j++)
  {
    for(i=0;i<3000;i++)
        asm("nop");
  }
}

/* main function */
int main() 
{
    PINSEL2 = 0x000000;  //Configure the P1 Pins for GPIO;
    IODIR1 = 0xffffffff; //Configure the P1 pins as OUTPUT;

    while(1)
    {
       IOSET1 = 0xffffffff;     // Make all the Port pins as high  
       delay_ms(1000);

       IOCLR1 = 0xffffffff;     // Make all the Port pins as low  
       delay_ms(1000);
    }
    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文