找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

帖子
查看: 5462|回復(fù): 0
收起左側(cè)

LPC1768 GPIO中斷實(shí)驗(yàn) 八個(gè)LED輪流點(diǎn)亮100毫秒

[復(fù)制鏈接]
ID:210585 發(fā)表于 2017-6-12 20:20 | 顯示全部樓層 |閱讀模式
路虎LPC1768開發(fā)板 GPIO實(shí)驗(yàn)

這個(gè)例程是將路虎開發(fā)板上的八個(gè)LED輪流點(diǎn)亮100毫秒,
采用SYStick 定時(shí)器中斷方式做延時(shí)  系統(tǒng)時(shí)鐘設(shè)置在100MHZ
使用時(shí),短路JP8跳線使能LED。

單片機(jī)源程序如下:
  1. /**************************************************************************//**
  2. * @file     main.c
  3. * @brief    CMSIS Cortex-M3 GPIO example
  4. *           a LED using CM3 SysTick
  5. * @version  V1.30
  6. * @date     24. Jan 2010
  7. *
  8. * @note
  9. * Copyright (C) 2009 ARM Limited. All rights reserved.
  10. *
  11. * @par
  12. * ARM Limited (ARM) is supplying this software for use with Cortex-M
  13. * processor based microcontrollers.  This file can be freely distributed
  14. * within development tools that are supporting such ARM based processors.
  15. *
  16. * @par
  17. * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  18. * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  20. * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  21. * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  22. *
  23. ******************************************************************************/

  24. #include "LPC17xx.h"


  25. volatile uint32_t msTicks;                            /* counts 1ms timeTicks */
  26. /*----------------------------------------------------------------------------
  27.   SysTick_Handler
  28. *----------------------------------------------------------------------------*/
  29. void SysTick_Handler(void) {
  30.   msTicks++;                        /* increment counter necessary in Delay() */
  31. }

  32. /*------------------------------------------------------------------------------
  33.   delays number of tick Systicks (happens every 1 ms)
  34. *------------------------------------------------------------------------------*/
  35. __INLINE static void Delay (uint32_t dlyTicks) {
  36.   uint32_t curTicks;

  37.   curTicks = msTicks;
  38.   while ((msTicks - curTicks) < dlyTicks);
  39. }

  40. /*------------------------------------------------------------------------------
  41.   configer LED pins
  42. *------------------------------------------------------------------------------*/
  43. __INLINE static void LED_Config(void) {

  44.   LPC_GPIO2->FIODIR = 0x000000ff;               /* LEDs PORT2 are Output */
  45.   LPC_GPIO0->FIODIR = 0x00200000;
  46.   LPC_GPIO0->FIOPIN |=  0x00200000;
  47. }

  48. /*------------------------------------------------------------------------------
  49.   Switch on LEDs
  50. *------------------------------------------------------------------------------*/
  51. __INLINE static void LED_On (uint32_t led) {

  52.   LPC_GPIO2->FIOPIN |=  (led);                  /* Turn On  LED */
  53. }

  54. /*------------------------------------------------------------------------------
  55.   Switch off LEDs
  56. *------------------------------------------------------------------------------*/
  57. __INLINE static void LED_Off (uint32_t led) {

  58.   LPC_GPIO2->FIOPIN &= ~(led);                  /* Turn Off LED */
  59. }

  60. /*----------------------------------------------------------------------------
  61.   MAIN function
  62. *----------------------------------------------------------------------------*/
  63. int main (void) {
  64.   uint8_t  location;
  65.        
  66.   if (SysTick_Config(SystemCoreClock / 1000)) { /* Setup SysTick Timer for 1 msec interrupts  */
  67.     while (1);                                  /* Capture error */
  68.   }
  69.   
  70.   LED_Config();                             

  71.   while(1)
  72.   {
  73.           LED_On (0xff);
  74.         Delay (500);
  75. ……………………

  76. …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
0.png
所有資料51hei提供下載:
GPIO.rar (163.57 KB, 下載次數(shù): 18)


回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表