ç§ã¯ãšã¬ã¯ãããã¯ã¹ã«å°ãèŠåŽããŠãããšããã«èšããªããã°ãªããªãã®ã§ããã®èšäºã¯ãããã©ã®ããã«æ©èœãããã«ã€ããŠã®ç§ã®æèŠãè¡šæããŸãã å°éçšèªãéåžžã«æªãã®ã§ãæ£ããçšèªãç¥ã£ãŠããå Žåã¯ä¿®æ£ããŠãã ããã
æºåãã
ãŸããéçºã«å¿ èŠãªãœãããŠã§ã¢ãã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã- ã³ã³ãã€ã©ãŒãšéçºç°å¢
- SDKïŒStellarisWareïŒ
- ãããã°ã¢ãžã¥ãŒã«ãã©ã€ããŒ
- ãã¡ãŒã ãŠã§ã¢ããã°ã©ã
- ããã¥ã¡ã³ã
ã³ã³ãã€ã©ãšIDEã䜿çšããŠãTexas Instrumentsã¯ç¬èªã®EclipseããŒã¹ã®Code Composer StudioïŒåå¥ã«ããŸãã¯æ¢ã«ã€ã³ã¹ããŒã«ãããŠããEclipseã®ãã©ã°ã€ã³ãšããŠã€ã³ã¹ããŒã«å¯èœïŒãIAR Embedded WorkbenchãKeilããã³Mentor Graphics Sourcery CodeBenchã®éžæè¢ãæäŸããŸãã
CCSã®ç¡æããŒãžã§ã³ã¯å®å šã«æ©èœããããã䜿çšããŸãã äžèšã®ãªã³ã¯ã䜿çšãããšãEK-LM4F120XL-CCSã®éšåçªå·ã®åŸãã«é ããŠãããCDããããŠã³ããŒãã§ããŸãããã®éšåçªå·ã«ã¯ãéçºã«å¿ èŠãªãã¹ãŠã®ãã®ããããŸãããã¢ãŒã«ã€ãã®å 容ã¯ããå€ããæŽæ°ãããŠããªãããã§ãã ãã ãããã¹ãŠãåå¥ã«ããŠã³ããŒãã§ããŸãã
Code Composer Studio ãStellarisWareã¯ãã SW-EK-LM4F120XLã®éšåçªå·ã Stellaris ICDIãã©ã€ã㌠ã LMFlashããã°ã©ã㌠ã è©äŸ¡ããŒããŠãŒã¶ãŒããã¥ã¢ã« ã ããŒã¿ã·ãŒãã«é ããŠããŸã ã StellarisWareãã€ã³ã¹ããŒã«ãããã£ã¬ã¯ããªã«ã€ã³ã¹ããŒã«ãããšãããã¥ã¡ã³ãã®ããdocsãµããã£ã¬ã¯ããªãèŠã€ããããšãã§ããŸãã ããã§ãäž»ãªé¢å¿ã¯SW-DRL-UG-9453.pdfãã¡ã€ã«ã§ãïŒæ°å€ã¯SWããŒãžã§ã³ã«ãã£ãŠç°ãªãå ŽåããããŸãïŒ-SDKã«ãã£ãŠæäŸãããæ©èœã«é¢ããããã¥ã¡ã³ãïŒãŸããSW-EK-LM4F120XL-UG-9453.pdfãèŠããšã LEDããã¿ã³ãããã«äœ¿çšã§ããé«ã¬ãã«ã®æ©èœãèŠã€ããŸãããããã¯å®éã®ãžã§ãã€ã®ããæ¹ã§ã¯ãããŸããã
TIã¯ååãå€æŽããããŒãã§äœ¿çšãããŠããLM4F120H5QRãã€ã¯ãã³ã³ãããŒã©ãŒã¯ããããTM4C1233H6PMãšåŒã°ããŠãããšèšããªããã°ãªããŸããã
ãããµã¹ã»ã€ã³ã¹ãã«ã¡ã³ãã®Webãµã€ãã§ãããŒãããã³å°å·ç©ã«é¢ãããããªè¬çŸ©ãèŠã€ããããšãã§ããŸãã
ããŒããã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ããŸãã
USBã±ãŒãã«ããããã¬ããŒãã«æ¥ç¶ããé»æºã¹ã€ããïŒUSBããŒãã®æšªïŒãããããã°ãäœçœ®ã«ããããšã確èªããŸãã ç·è²ã®é»æºLEDãé€ããã¹ãŠãæ£ããè¡ãããå Žåãããªã»ããããã¿ã³ã®é£ã®LEDãç¹ç¯ãã5ç§åŸã«ç°ãªãè²ã§ç¹æ» ãå§ããŸãïŒãã¡ãããå·¥å Žåºè·æã®ãã¡ãŒã ãŠã§ã¢ãšã¯ç°ãªããã®ãç¹æ» ãããæéããªãéãïŒã
Windows 8.1ã«é¢ãã泚æã ãã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ã¯ãããã©ã«ãã§æªçœ²åã®ãã©ã€ããŒãããŠã³ããŒãã§ããªããããICDIãã©ã€ããŒãã€ã³ã¹ããŒã«ã§ããŸããã ããã¯æ¬¡ã®ããã«æ±ãããŸãïŒWin + Iâé»æºãæŒããShiftããŒãæŒããªããåèµ·åãã¯ãªãã¯ããŠãåŸ æ©ããŸãã修埩ãªãã·ã§ã³ã®ã¡ãã¥ãŒã衚瀺ãããŸãããã©ãã«ã·ã¥ãŒãã£ã³ã°â詳现ãªãã·ã§ã³âèµ·åèšå®âåèµ·åãéžæããŸãã åèµ·ååŸãããã©ã€ããŒçœ²åã®åŒ·å¶ãç¡å¹ã«ããããéžæããå¿ èŠãããã¡ãã¥ãŒã衚瀺ãããŸãã
æåã®ããã°ã©ã
ãã®ãããå¿ èŠãªãã®ã¯ãã¹ãŠã€ã³ã¹ããŒã«ããŸããã æžãæéã§ãã CCSã§ãããžã§ã¯ããäœæããŸãïŒãã¡ã€ã«âæ°èŠâCCSãããžã§ã¯ãã å³ãšåæ§ã«æ§æããŸãã
空ã®
main.c
ãš
lm4f120h5qr_startup_ccs.c
ãœãŒã¹ã³ãŒããå«ã2ã€ã®ãã¡ã€ã«ãåæã«ååšãããããžã§ã¯ããåãåããŸãã 2çªç®ã®ãã¡ã€ã«ã«ã¯ãå²ã蟌ã¿ããŒãã«ãåæåããããã®å®åã³ãŒããšãå²ã蟌ã¿ãåŠçããããã®ã¹ã¿ãé¢æ°ãå«ãŸããŠããŸãã
ããããŒãã¡ã€ã«ãšã©ã€ãã©ãªãæ€çŽ¢ããããã®ãã¹ãããã«æ§æãã[ãããžã§ã¯ã]ã¡ãã¥ãŒã®[ããããã£]ã«ç§»åããŠã次ã®æäœãè¡ããŸãã
ãã¡ããããã¹ãç¬èªã®ãã®ã«çœ®ãæããŠãã ããã
#include
ã
main.c
è¿œå ãããã¹ãŠãã³ã³ãã€ã«ãããããšã確èªããŸãã
#include <inc/hw_types.h> #include <inc/hw_gpio.h> #include <inc/hw_memmap.h> #include <driverlib/sysctl.h> #include <driverlib/gpio.h> int main(void) { return 0; }
åäœããªãå Žåã¯ä¿®åŸ©ããåäœããå Žåã¯äœãæçšãªããšãéå§ã§ããŸãã
åãé »åºŠ
ãŸãããã€ã¯ãã³ã³ãããŒã©ãŒãåäœããåšæ³¢æ°ãèšå®ããå¿ èŠããããŸãã åäœå¯èœãªæ倧åšæ³¢æ°ã¯80 MHzã§ãããããããäœãåšæ³¢æ°ãå¯èœã§ãã ããŒã¿ã·ãŒãã®ã»ã¯ã·ã§ã³5.2.5ã«ãåšæ³¢æ°ã®èª¿æŽæ¹æ³ãèšèŒãããŠãããå³5-5ã§ã¯æãã§ãã
çŸæç¹ã§ã¯ããã·ã¹ãã ã¯ããã¯ãåºåã«é¢å¿ããããŸãã ããŒã¿ã·ãŒãã«ãããšã次ã®ãã®ãã¯ããã¯ãœãŒã¹ãšããŠäœ¿çšã§ããŸãã
- é«ç²ŸåºŠå éšOSC 16 MHz
- ã¡ã€ã³OSCïŒãã®ããŒãã§ã¯Y1ãšã©ãã«ä»ããããåšæ³¢ââæ°ã¯16 MHzïŒ
- å éšOSC 30 kHz
- ãã€ãããŒã·ã§ã³OSCïŒ32.768 kHzïŒ-ããŒãäžã®Y2
- Pll
- 4ååšåšã«ããé«ç²ŸåºŠå éšOSC
ãããã®ãœãŒã¹ã®ãã¡ã2ã€ã¯å€éšã§ããããã€ã¯ãã³ã³ãããŒã©ãŒïŒã¡ã€ã³OSCãšãã€ãããŒã·ã§ã³OSCïŒã«é¢ããŠãæ®ãã¯å éšã«ãããŸãã
å³ã§SYSDIVãšããŠæå®ãããŠããååšåšã¯ã1ã64åã®åšæ³¢æ°äœäžã«èª¿æŽã§ããŸãã PLLããœãŒã¹ãšããŠäœ¿çšããå ŽåãDIV400ãããã§å¶åŸ¡ãããè¿œå ã®2ãããååšåšã䜿çšã§ããŸãïŒããã©ã«ãã§æå¹ïŒã PLLãæ©èœããã«ã¯ããã¹ã¿ãŒãã«ã¹ãžã§ãã¬ãŒã¿ãŒãå¿ èŠã§ãã ãã®é »åºŠã¯å€§ããç°ãªããŸãããåæåæã«æå®ããå¿ èŠããããŸãã PLLã䜿çšããããšã¯ãæ倧åšæ³¢æ°ã§ãã€ã¯ãã³ã³ãããŒã©ãŒãèµ·åããå¯äžã®æ¹æ³ãªã®ã§ãããã䜿çšããŸãïŒãã ãããã®ç®çã®ããã«ã¯ããã®ãããªã¯ã¬ã€ãžãŒãªåšæ³¢æ°ã¯å¿ èŠãããŸããïŒã PLLã¯ãããã³ã°ã§ã¯ãå€éšæ°Žæ¶ãšå éšæ°Žæ¶ã®äž¡æ¹ã䜿çšã§ããŸãã
StellarisWareã¯
SysCtlClockSet
é¢æ°ãæäŸããŠãã·ã¹ãã ã¯ããã¯ã«é¢é£ãããã¹ãŠã
SysCtlClockSet
èšå®ããŸãã ãããè¡ãããã«ã圌女ã¯å ¥ãå£ã§ããããã®æãåãåããŸãïŒ
ãŸããPLLïŒ
SYSCTL_USE_PLL
ïŒã䜿çšããããä»ã®äœãïŒ
SYSCTL_USE_PLL
ïŒã䜿çšãããã決å®ããŸã-ãã€ã¢ã°ã©ã äžã®BYPASSãã©ã°ã
PLLã䜿çšããå Žåã誰ããã¹ã¿ãŒãªã·ã¬ãŒã¿ãŒã«ãªãããéžæããå¿ èŠããããŸããã¡ã€ã³OSCïŒ
SYSCTL_OSC_MAIN
ïŒãŸãã¯é«ç²ŸåºŠå éšOSCïŒ
SYSCTL_OSC_INT
ïŒã ã¡ã€ã³OSCã䜿çšããå Žåããã®é »åºŠïŒãã®å Žåã¯
SYSCTL_XTAL_16MHZ
ïŒãæå®ããå¿ èŠããããŸãã
PLLã䜿çšããªãå ŽåããœãŒã¹ãæå®ããå¿ èŠããããŸãã
- é«ç²ŸåºŠå
éšOSC-
SYSCTL_OSC_INT
- 4ã®é€æ°ã«ããé«ç²ŸåºŠå
éšOSC-
SYSCTL_OSC_INT4
- ã¡ã€ã³OSC-
SYSCTL_OSC_MAIN
- å
éšOSC-
SYSCTL_OSC_INT30
- ãã€ãããŒã·ã§ã³OSC-
SYSCTL_OSC_EXT32
ãããŠæåŸã«ãä»åããèšå®ããå¿ èŠããããŸãã
SYSCTL_SYSDIV_1
ãã
SYSCTL_SYSDIV_1
ãŸã§ã®ãã®ããã®ãã¯ãããããŸãã PLLã䜿çšããå Žåããªãã·ã§ã³ã§ãã¯ã
SYSCTL_SYSDIV_2_5
ïŒ/2.5ïŒ
SYSCTL_SYSDIV_2_5
ïŒ/63.5ïŒã䜿çšã§ããŸãã ç§ã«ã¯äžæãªçç±
SysCtlClockSet
ãåŒã³åºããã
SysCtlClockSet
PLLåšæ³¢æ°ã¯200 MHzã«çãããšèŠãªãããŸãã 80 MHzã®åšæ³¢æ°ã§åäœããã«ã¯ã2.5ã®ååšåšãæå®ããå¿ èŠããããŸãã
å šäœãšããŠã
SysCtlClockSet
åŒã³åºãã¯æ¬¡ã®ããã«ãªããŸãã
// PLL, - Main OSC 16 , 2.5, 80 SysCtlClockSet(SYSCTL_USE_PLL | SYSCTL_SYSDIV_2_5 | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
ãŸãã¯ïŒ
// PLL, - Precision Internal OSC, 2.5, 80 , Main OSC SysCtlClockSet(SYSCTL_USE_PLL | SYSCTL_SYSDIV_2_5 | SYSCTL_OSC_INT | SYSCTL_MAIN_OSC_DIS);
ãŸãã¯ããªãã奜ããªãã®ã
LEDã®ç¹æ»
çµæãèŠãããšãã§ããããã°ã©ã ãäœæããæãæ¥ãŸããã ããŒãã®ããã¥ã¡ã³ãã«ã¯ãLEDããªã³ã«ããåè·¯ããããŸãã
ã€ãŸã LEDã¯1-3 GPIOããŒãFã®èã«æ¥ç¶ãããŠããŸãïŒæµæããã©ã³ãžã¹ã¿ã®ããŒã¹ãšãšããã¿ã®éã«ããçç±ãç¥ã£ãŠãã人ã¯ãåçºããŠãã ããããããŠãªãããã瀺ãããŠããªãã®ã§ããïŒïŒã GPIOããŒãã«ã¯8ã€ã®ã¬ãã°ããããããããã¬ãã°ãå ¥åãŸãã¯åºåãšããŠåå¥ã«æ§æã§ããŸãã æžã蟌ã¿ãšèªã¿åãã¯ãã¡ã¢ãªã«ãããã³ã°ããã
GPIODATA
ã¬ãžã¹ã¿ãæžã蟌ã¿ãŸãã¯èªã¿åãããããšã«ããããã¹ãŠã®ã¬ãã°ããäžåºŠã«
GPIODATA
ãããŸãïŒããããã1ãã€ãã®èªã¿åã/æžã蟌ã¿-ãã¹ãŠã®ã¬ãã°ã®ç¶æ ïŒã ããŒãã«ã¢ã¯ã»ã¹ããã«ã¯ãAdvanced Peripheral BusïŒAPBïŒãŸãã¯Advanced High-performance BusïŒAHBïŒã®2ã€ã®æ¹æ³ããããŸãã æåã®æ¹æ³ã¯ãå€ããé ãã2çªç®ã®æ¹æ³ã¯çŸä»£çã§é«éã§ãã æ£çŽãªãšãããããã°ã©ãã³ã°ã®èŠ³ç¹ãããããã®éãã¯ããããŸããïŒå°ãªããšãããŒãã®ããŒã¹ã¢ãã¬ã¹ã¯ç°ãªããŸãïŒãAPBã䜿çšããŸãããããŒãFã®ããŒã¹ã¢ãã¬ã¹ã¯0x40025000ã§ãã
ãã®ãããLEDãç¹ç¯ããã«ã¯ã察å¿ããèã«é«é»å§ã¬ãã«ãèšå®ããå¿ èŠããããŸãã ã€ãŸã 察å¿ãããããã«1ãæžã蟌ã¿ãŸãã éåžžããããã®ç¶æ ãå€æŽããã«ã¯ãã¬ãžã¹ã¿ã®ã¹ããŒã¿ã¹ãèªã¿åããç®çã®ãããã®å€ãèšå®ããåä¿¡ããå€ãæžãæ»ãå¿ èŠããããŸãã ã¡ã¢ãªæäœã¯é ãããããã€ã¯ãã³ã³ãããŒã©ãŒã®éçºè ã¯1ã€ã®ã¬ã³ãŒãïŒäºåèªã¿åããªãïŒãå®è¡ããæ©äŒãæäŸããŸããã¬ãžã¹ã¿ã¯1ã€ã®ã¢ãã¬ã¹ã§ã¯ãªããããŒã¹ã¢ãã¬ã¹ããå§ãŸã1024ãã€ãã®ç¯å²ã§ã¢ã¯ã»ã¹ãããŸãã ã¢ãã¬ã¹ã®ããã2ã9ã«ã¯ãå€ãæŽæ°ããå¿ èŠããããããã®ãã¹ã¯ãå«ãŸããŠããŸãã ã€ãŸã ããã1ã«1ãæžã蟌ãå Žåã¯ãé©åãªãã¹ã¯ãååŸããå¿ èŠããããŸãïŒ0x02ãå·Šã«2ãããã·ããããçµæã®å€ãããŒã¹ã¢ãã¬ã¹ã«è¿œå ããŸã-ç®çã®ããŒãã¹ããŒã¿ã¹ãæžã蟌ãå¿ èŠãããã¢ãã¬ã¹ãååŸããŸãïŒ0x02ãŸãã¯0xFF-ååŸãããŸãïŒæåã®ãããã®ã¿ïŒã
ç®çã®ããããèšå®ããé¢æ°ã¯æ¬¡ã®ããã«ãªããŸãã
void pinWrite(unsigned int base, unsigned char pins, unsigned char value) { *((unsigned char *)base + ((unsigned int)pins << 2)) = value; }
StellarisWareã¯ã
GPIOPinWrite
ããšãè¡ãåã眲åãæã€
GPIOPinWrite
é¢æ°ãæäŸããŸãã
äžè¶³ããŠããããšã1ã€ã ããããŸããããŒãããªã³ã«ããLEDãåºåãšããŠæ¥ç¶ãããã¬ãã°ãèšå®ããå¿ èŠããããŸãã SDKãªãã§å®è¡ããã人ã®ããã«ãããã»ã¹ã¯ãã€ã¯ãã³ã³ãããŒã©ã®ããŒã¿ã·ãŒãã®ã»ã¯ã·ã§ã³10.3ã§èª¬æãããŠããŸãã StellarisWareã§ã¯ãããã¯
SysCtlPeripheralEnable
ããã³
GPIOPinTypeGPIOInput
/
GPIOPinTypeGPIOOutput
åŒã³åºãããšã§è¡ãããŸãã
#include <inc/hw_types.h> #include <inc/hw_gpio.h> #include <inc/hw_memmap.h> #include <driverlib/sysctl.h> #include <driverlib/gpio.h> const unsigned int LED_RED = 0x02; const unsigned int LED_GREEN = 0x08; const unsigned int LED_BLUE = 0x04; const unsigned int LEDS_ALL = 0x02 | 0x08 | 0x04; int main(void) { SysCtlClockSet(SYSCTL_USE_PLL | SYSCTL_SYSDIV_2_5 | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH2_GPIOF); SysCtlDelay(2); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LEDS_ALL); const unsigned long int delay = 80000000 / 3 / 2; // 80 , 3 , 1/2 while (1) { GPIOPinWrite(GPIO_PORTF_BASE, LEDS_ALL, LEDS_ALL); SysCtlDelay(delay); GPIOPinWrite(GPIO_PORTF_BASE, LEDS_ALL, 0); SysCtlDelay(delay); } return 0; }
SysCtlDelay
é¢æ°ã¯ã空ã®ã«ãŒãã
n
åç¹°ãè¿ããŠãç®çã®é·ãã®é 延ãäœæã§ããããã«ããŸãã åå埩ã¯ãããã»ããµã®3ã¯ããã¯ãµã€ã¯ã«ç¶ããŸãã ã³ã³ãã€ã«ããŠå®è¡ããŸãïŒCCSã§F11ãæŒããšãããã©ã«ãã§ããã°ã©ã ã®å é ã«æé»çãªãã¬ãŒã¯ãã€ã³ãããããããF8ãæŒãå¿ èŠããããŸãïŒã ããŒãã®LEDã1ç§ééã§çœãç¹æ» ãå§ããŸãã
LEDS_ALL
代ããã«ã
LEDS_ALL
ãžã®æåã®åŒã³åºãã®3çªç®ã®åŒæ°ãããšãã°
GPIOPinWrite
æž¡ããããšãç·è²ã«ç¹æ» ããŸãã
ãã¿ã³ïŒ
ãã®ã¹ããŒã ã«åŸã£ãŠã2ã€ã®ãã¿ã³ãGPIOããŒãFã®ã¬ãã°0ããã³4ã«æ¥ç¶ãããŸãã
å³ããããã¿ã³ãæŒããšè¶³ãå°é¢ã«æ¥ç¶ãããé©çšç¶æ ã§ãªãå Žåã足ã¯ã©ãã«ãæ¥ç¶ãããŠããªãããšãããããŸãã ããã¯æªãããšã§ã;æ¥ç¶ãããŠããªãèããèªã¿èŸŒãããšãããšãäœã§ãèªãããšãã§ããŸãã ãã¿ã³ãæŒãããŠããªããšãã«é»æºãæ¥ç¶ãããŠããããšã確èªããå¿ èŠããããŸãã ããã¯ãã«ã¢ããïŒãã«ã¢ããïŒã«åœ¹ç«ã¡ãŸããå®éã«ã¯ãæµæãä»ããŠè¶³ãé»æºã«æ¥ç¶ããŸãããã®ããããã¿ã³ãæŒãããŠããªãå Žåããã«ã¢ãããä»ããŠé»åãäŸçµŠãããæŒãããå Žåãããããã®é»æµãå°é¢ã«æµããŸãã€ãŸã 解æŸããããã¿ã³ã¯ãããŒãå ã®ãŠããããšããŠèªã¿åãããæŒãããŸã-ãŒããšããŠã
ãããã£ãŠãã¬ãã°0ããã³4ãå ¥åã«èšå®ãããã«ã¢ãããæå¹ã«ããŸãã
GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
GPIOPadConfigSet
é¢æ°ã䜿çš
GPIOPadConfigSet
ãšã足ïŒ2ã4ããŸãã¯8 mAïŒãšãã®ã¢ãŒããåºåã§ããé»æµãèšå®ã§ã
GPIOPadConfigSet
ã ãã€ã¯ãã³ã³ãããŒã©ã¯ãããã€ãã®GPIOããŒãïŒJTAG / SWDããŒãïŒããŒãCã®ããã0ã3ïŒã«äœ¿çšã§ãããã®ïŒãŸãã¯ãã¹ã¯ãããŠããªãå²ã蟌ã¿ã®å ¥å-NMIïŒããŒãDã®7ããããš0ãããïŒã®èšå®ã®å€æŽã«å¯Ÿããä¿è·ãæã£ãŠããããšã«æ³šæãã䟡å€ããããŸãããŒãFïŒïŒïŒãããã®ã¬ãã°ã®ãã«ã¢ãã/ãã«ããŠã³èšå®ã®å€æŽã¯ã
GPIOCR
ã¬ãžã¹ã¿ã«1.ãæžã蟌ãŸããŠããå Žåã®ã¿å¯èœã§ã
GPIOCR
ã¬ãžã¹ã¿
GPIOCR
ã¯ãç¹å¥ãªãããžãã¯ãã³ããŒãã
GPIOLOCK
ã¬ãžã¹ã¿ã«æžã蟌ãŸããŠããå Žåã«ã®ã¿æžã蟌ãããšãã§ããŸãã
ãã¹ãŠããŸãšããïŒ
#include <inc/hw_types.h> #include <inc/hw_gpio.h> #include <inc/hw_memmap.h> #include <driverlib/sysctl.h> #include <driverlib/gpio.h> const unsigned int LEDS_ALL = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3; const unsigned int SW1 = GPIO_PIN_0; const unsigned int SW2 = GPIO_PIN_4; void crSet(unsigned int base, unsigned char value); int main(void) { int led = 2; SysCtlClockSet(SYSCTL_USE_PLL | SYSCTL_SYSDIV_2_5 | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); SysCtlPeripheralEnable(SYSCTL_PERIPH2_GPIOF); SysCtlDelay(2); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LEDS_ALL); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, SW1 | SW2); HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD; crSet(GPIO_PORTF_BASE, 1); GPIOPadConfigSet(GPIO_PORTF_BASE, SW1 | SW2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); crSet(GPIO_PORTF_BASE, 0); HWREG(GPIO_PORTF_BASE + GPIO_O_LOCK) = 0; while (1) { unsigned int state = ~GPIOPinRead(GPIO_PORTF_BASE, SW1 | SW2); led = ((state & SW1) << 1) | ((state & SW2) >> 1); GPIOPinWrite(GPIO_PORTF_BASE, LEDS_ALL, led); } return 0; } void crSet(unsigned int base, unsigned char value) { unsigned long v = (HWREG(GPIO_PORTF_BASE + GPIO_O_CR) & 0xFFFFFF00) | value; HWREG(base + GPIO_O_CR) = v; }
æåŸã«ããã®çŽ ââæŽãããããã°ã©ã ãš12ãã«ã®æéã«ããã10ã«ãŒãã«ã«çžåœãã12ããŒãæªæºã®åçŽãªåè·¯å³ãšåãããšãã§ããŸãïŒ