查看: 1439|回复: 0

[原创] 重玩LPC1768——GPIO实现

[复制链接]
  • TA的每日心情
    开心
    2024-4-10 22:38
  • 签到天数: 1335 天

    [LV.10]以坛为家III

    88

    主题

    4292

    帖子

    12

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    9049
    最后登录
    2024-4-13
    发表于 2020-8-30 09:00:01 | 显示全部楼层 |阅读模式
    重玩LPC1768——GPIO实现

    LPC1768芯片同其它Cortex-M3芯片类似,引脚也提供较为灵活的多路复用功能,粗略的看了一下,基本上每个引脚都有4个复用功能(含本身GPIO),默认为GPIO功能,且带有上拉电阻。
    我们拿来做GPIO实验的引脚是P0.7,根据原理图,我们需要将P0.7配置为推挽输出。
    本实验仍然使用LPCopen库,应用库中的gpio_17xx_40xx.c/.h与iocon_17xx_40xx.c/.h两组文件。在库的包装下,配置流程也相对简单,直接上代码:


    1. void heartbeat_init(void)
    2. {
    3.   Chip_GPIO_Init(LPC_GPIO);
    4.   Chip_IOCON_PinMux(LPC_IOCON, 0, 7, IOCON_MODE_PULLUP, IOCON_FUNC0);
    5.   Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 7, true);
    6.   Chip_GPIO_SetPortOutLow(LPC_GPIO, 0, 7);
    7. }
    复制代码

    在配合systick的实验,我们实现1Hz下的LED灯闪烁实验。
    附bspgpio.c源代码

    1. /**
    2. ******************************************************************************
    3. * @file    bspgpio.c
    4. * @author  jobs
    5. * @version v0.00
    6. * @date    2020-08-29
    7. * @brief   
    8. * @note   
    9. *
    10. ******************************************************************************
    11. */

    12. #include "bspgpio.h"
    13. #include "chip.h"

    14. void heartbeat_init(void)
    15. {
    16.   Chip_GPIO_Init(LPC_GPIO);
    17.   Chip_IOCON_PinMux(LPC_IOCON, 0, 7, IOCON_MODE_PULLUP, IOCON_FUNC0);
    18.   Chip_GPIO_WriteDirBit(LPC_GPIO, 0, 7, true);
    19.   Chip_GPIO_SetPortOutLow(LPC_GPIO, 0, 7);
    20. }

    21. void heartbeat_blink(void)
    22. {
    23.   Chip_GPIO_SetPinToggle(LPC_GPIO, 0, 7);
    24. }

    25. /******************************** END OF FILE *********************************/
    复制代码
    附main.c源代码
    1. /**
    2. ******************************************************************************
    3. * @file    main.c
    4. * @author  jobs
    5. * @version v0.00
    6. * @date    2020-08-23
    7. * @brief   
    8. * @note   
    9. *
    10. ******************************************************************************
    11. */

    12. #include <stdio.h>
    13. #include <stdint.h>
    14. #include "main.h"
    15. #include "chip.h"
    16. #include "bspgpio.h"

    17. const uint32_t OscRateIn = 12000000;
    18. const uint32_t RTCOscRateIn = 32768;

    19. volatile uint32_t time_line_ms = 0;
    20. int32_t heartbeat_cycle = 0;

    21. void main(void)
    22. {
    23.   Chip_SetupXtalClocking();
    24.   SystemCoreClockUpdate();
    25.   SysTick_Config(SystemCoreClock / 1000);
    26.   heartbeat_init();
    27.   heartbeat_cycle = 500;
    28.   while(1)
    29.   {
    30.     if(heartbeat_cycle == 0)
    31.     {
    32.       heartbeat_cycle = 500;
    33.       heartbeat_blink();
    34.     }
    35.   }
    36. }


    37. void SysTick_Handler(void)
    38. {
    39.   time_line_ms++;
    40.   if(heartbeat_cycle > 0)
    41.   {
    42.     heartbeat_cycle--;
    43.   }
    44. }

    45. /******************************** END OF FILE *********************************/
    复制代码





    该会员没有填写今日想说内容.
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-4-25 00:48 , Processed in 0.117914 second(s), 20 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表