LM3S8962 GPIO 연습 코드
Embeded :
2009. 1. 2. 22:30
반응형
- //*****************************************************************************
- // watchdog.c - Watchdog timer example.
- //
- // Copyright (c) 2005-2008 Luminary Micro, Inc. All rights reserved.
- //
- // Software License Agreement
- //
- // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
- // exclusively on LMI's microcontroller products.
- //
- // The software is owned by LMI and/or its suppliers, and is protected under
- // applicable copyright laws. All rights are reserved. You may not combine
- // this software with "viral" open-source software in order to form a larger
- // program. Any use in violation of the foregoing restrictions may subject
- // the user to criminal sanctions under applicable laws, as well as to civil
- // liability for the breach of the terms and conditions of this license.
- //
- // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
- // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
- // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
- // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
- // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
- //
- // This is part of revision 3223 of the Stellaris Peripheral Driver Library.
- //
- //*****************************************************************************
- #include "../../../hw_ints.h"
- #include "../../../hw_memmap.h"
- #include "../../../hw_types.h"
- #include "../../../src/debug.h"
- #include "../../../src/gpio.h"
- #include "../../../src/interrupt.h"
- #include "../../../src/sysctl.h"
- #include "../../../src/watchdog.h"
- #include "../rit128x96x4.h"
- //*****************************************************************************
- //
- //! \addtogroup ek_lm3s8962_list
- //! <h1>Watchdog (watchdog)</h1>
- //!
- //! This example application demonstrates the use of the watchdog as a simple
- //! heartbeat for the system. If the watchdog is not periodically fed, it will
- //! reset the system. Each time the watchdog is fed, the LED is inverted so
- //! that it is easy to see that it is being fed, which occurs once every
- //! second.
- //
- //*****************************************************************************
- //*****************************************************************************
- //
- // The error routine that is called if the driver library encounters an error.
- //
- //*****************************************************************************
- #ifdef DEBUG
- void
- __error__(char *pcFilename, unsigned long ulLine)
- {
- }
- #endif
- //*****************************************************************************
- // The interrupt handler for the watchdog. This feeds the dog (so that the
- // processor does not get reset) and winks the LED.
- //*****************************************************************************
- void
- WatchdogIntHandler(void)
- {
- /*
- //
- // Clear the watchdog interrupt.
- //
- WatchdogIntClear(WATCHDOG_BASE);
- //
- // Invert the GPIO F0 value.
- //
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0,
- GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_0) ^ GPIO_PIN_0);
- */
- }
- // This example demonstrates the use of the watchdog timer.
- void SW_IntHandler(void);
- int
- main(void)
- {
- volatile unsigned long ulLoop;
- //장치의 클럭을 셋팅하는 부분 1초에 8메가번 클럭을 준다..
- SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ);
- //GPIO의 A,G port를 사용 가능하게 한다.
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
- //GPI0 A1,G0 port를 output type으로 설정.
- GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_1);
- GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_0);
- //GPI0 A5를 input type으로 설정.
- GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_5);
- GPIOPadConfigSet(GPIO_PORTA_BASE,GPIO_PIN_5, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_OD);
- //A5에 falling edge때 인터럽트를 준다.
- GPIOIntTypeSet(GPIO_PORTA_BASE,GPIO_PIN_5,GPIO_FALLING_EDGE | GPIO_RISING_EDGE );
- //interrupt event는 sw_intHandler로 준다.
- GPIOPortIntRegister(GPIO_PORTA_BASE, SW_IntHandler);
- //A5에서 인터럽트 사용
- GPIOPinIntEnable(GPIO_PORTA_BASE,GPIO_PIN_5);
- while(1)
- {
- // A1 On & Off
- GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_1, 0X02);
- for(ulLoop = 0; ulLoop < 600000; ulLoop++){}
- GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_1,0x00000000);
- for(ulLoop = 0; ulLoop < 600000; ulLoop++){}
- }
- }
- void SW_IntHandler(void)
- {
- GPIOPinIntClear(GPIO_PORTA_BASE, GPIO_PIN_5);//인터럽트 clear!!
- if(GPIOPinRead(GPIO_PORTG_BASE,GPIO_PIN_0) == 0)//LED가 켜져있을 때
- {
- GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0, GPIO_PIN_0);//LED끄고
- }
- else
- {
- GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_0, 0);//꺼져있으면 다시 켠다.
- }
- }
대학 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 |