LM3S8962 GPIO 연습 코드

Embeded : 2009. 1. 2. 22:30
반응형
  1. //*****************************************************************************  
  2. // watchdog.c - Watchdog timer example.  
  3. //  
  4. // Copyright (c) 2005-2008 Luminary Micro, Inc.  All rights reserved.  
  5. //   
  6. // Software License Agreement  
  7. //   
  8. // Luminary Micro, Inc. (LMI) is supplying this software for use solely and  
  9. // exclusively on LMI's microcontroller products.  
  10. //   
  11. // The software is owned by LMI and/or its suppliers, and is protected under  
  12. // applicable copyright laws.  All rights are reserved.  You may not combine  
  13. // this software with "viral" open-source software in order to form a larger  
  14. // program.  Any use in violation of the foregoing restrictions may subject  
  15. // the user to criminal sanctions under applicable laws, as well as to civil  
  16. // liability for the breach of the terms and conditions of this license.  
  17. //   
  18. // THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED  
  19. // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF  
  20. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.  
  21. // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR  
  22. // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.  
  23. //   
  24. // This is part of revision 3223 of the Stellaris Peripheral Driver Library.  
  25. //  
  26. //*****************************************************************************  
  27.   
  28. #include "../../../hw_ints.h"  
  29. #include "../../../hw_memmap.h"  
  30. #include "../../../hw_types.h"  
  31. #include "../../../src/debug.h"  
  32. #include "../../../src/gpio.h"  
  33. #include "../../../src/interrupt.h"  
  34. #include "../../../src/sysctl.h"  
  35. #include "../../../src/watchdog.h"  
  36. #include "../rit128x96x4.h"  
  37.   
  38. //*****************************************************************************  
  39. //  
  40. //! \addtogroup ek_lm3s8962_list  
  41. //! <h1>Watchdog (watchdog)</h1>  
  42. //!  
  43. //! This example application demonstrates the use of the watchdog as a simple  
  44. //! heartbeat for the system.  If the watchdog is not periodically fed, it will  
  45. //! reset the system.  Each time the watchdog is fed, the LED is inverted so  
  46. //! that it is easy to see that it is being fed, which occurs once every  
  47. //! second.  
  48. //  
  49. //*****************************************************************************  
  50.   
  51. //*****************************************************************************  
  52. //  
  53. // The error routine that is called if the driver library encounters an error.  
  54. //  
  55. //*****************************************************************************  
  56. #ifdef DEBUG  
  57. void  
  58. __error__(char *pcFilename, unsigned long ulLine)  
  59. {  
  60. }  
  61. #endif  
  62.   
  63. //*****************************************************************************  
  64. // The interrupt handler for the watchdog.  This feeds the dog (so that the  
  65. // processor does not get reset) and winks the LED.  
  66. //*****************************************************************************  
  67. void  
  68. WatchdogIntHandler(void)  
  69. {  
  70. /*    
  71.     //  
  72.     // Clear the watchdog interrupt.  
  73.     //  
  74.     WatchdogIntClear(WATCHDOG_BASE);  
  75.   
  76.     //  
  77.     // Invert the GPIO F0 value.  
  78.     //  
  79.     GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0,  
  80.                  GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) ^ GPIO_PIN_0);  
  81. */  
  82. }  
  83. // This example demonstrates the use of the watchdog timer.  
  84.   
  85. void SW_IntHandler(void);  
  86. int  
  87. main(void)  
  88. {  
  89.     volatile unsigned long ulLoop;  
  90.   
  91.     //장치의 클럭을 셋팅하는 부분 1초에 8메가번 클럭을 준다..  
  92.     SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);  
  93.   
  94.     //GPIO의 A,G port를 사용 가능하게 한다.  
  95.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);  
  96.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);  
  97.       
  98.     //GPI0 A1,G0 port를 output type으로 설정.  
  99.     GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_1);  
  100.     GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_0);  
  101.       
  102.     //GPI0 A5를 input type으로 설정.  
  103.     GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5);  
  104.       
  105.     GPIOPadConfigSet(GPIO_PORTA_BASE,GPIO_PIN_5, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_OD);  
  106.       
  107.     //A5에  falling edge때 인터럽트를 준다.  
  108.     GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_5,GPIO_FALLING_EDGE | GPIO_RISING_EDGE );  
  109.       
  110.     //interrupt event는 sw_intHandler로 준다.  
  111.     GPIOPortIntRegister(GPIO_PORTA_BASE, SW_IntHandler);  
  112.       
  113.     //A5에서 인터럽트 사용  
  114.     GPIOPinIntEnable(GPIO_PORTA_BASE,GPIO_PIN_5);  
  115.   
  116.     while(1)  
  117.     {  
  118.         // A1 On & Off  
  119.         GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_1, 0X02);  
  120.         for(ulLoop = 0; ulLoop < 600000; ulLoop++){}  
  121.         GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_1,0x00000000);  
  122.         for(ulLoop = 0; ulLoop < 600000; ulLoop++){}  
  123.     }  
  124. }  
  125.   
  126. void SW_IntHandler(void)  
  127. {  
  128.     GPIOPinIntClear(GPIO_PORTA_BASE, GPIO_PIN_5);//인터럽트  clear!!  
  129.     if(GPIOPinRead(GPIO_PORTG_BASE,GPIO_PIN_0) == 0)//LED가 켜져있을 때  
  130.         {  
  131.             GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0, GPIO_PIN_0);//LED끄고  
  132.         }  
  133.     else  
  134.         {  
  135.             GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0, 0);//꺼져있으면 다시 켠다.  
  136.         }  
  137. }  



대학 1학년때 전공 선택하면서 빵판 다시는 않만질줄 알았는데 ㅠ.ㅠ
오늘 빵판붙잡고 전원 연결하는것도 몰라서 전원도 안꼽꼬 왜 LED 안들어 오냐고 했다. ㅋㅋㅋ

그래도 하루만에 GPIO 인터럽트 사용법이랑 입,출력 예제를 완성했다.

설명도 못듣고 PPT만 보고 할라니깐 당최 PPT 내용도 모르겠고....
개발환경 구축도 PPT에는 윈도우에서 이클립스랑 Cygwin으로 크로스컴파일환경 세팅하게 나와있는데 이것저것 잘 안되서 삽질하다가
열받아서 리눅스 깔고 세팅해버렸다.

스위치로 인터럽트 걸어서 LED 깜빡이는건데 당최 하드웨어는 문외한이라서.... PPT를 봐도 모르겠고 그래서
코드만 쌩으로 팠다.
결국엔 코드 붙잡고 늘어지니 되긴 되는구나 ㅋㅋㅋㅋ

아~ 진짜 별거 없는데 되게 뿌듯하네....
반응형

'Embeded' 카테고리의 다른 글

Timer 사용하기  (0) 2009.01.05
2530 여러가지 테스트 예제들 ㅋㅋ  (0) 2008.12.26
2530 세팅 완료 ㅋㅋ  (0) 2008.12.26
Posted by Real_G