⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blinky.c

📁 Stellaris Luminary Micro 系列之 DK-LM3S102 多个学习范例全都是基于 Keil 工程版的范例, 而范例内容列举如下: 1.BitBand 2.Comparator
💻 C
字号:
/******************************************************************************/
/* BLINKY.C: LED Flasher                                                      */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools.                    */
/* Copyright (c) 2005-2006 Keil Software. All rights reserved.                */
/* This software may only be used under the terms of a valid, current,        */
/* end user licence from KEIL for a compatible version of KEIL software       */
/* development tools. Nothing else gives you the right to use this software.  */
/******************************************************************************/

#include <LM3Sxxx.H>


/* All pins used for LEDs (ULED0 .. ULED3)                                    */
#define LED_PINS  (GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3)
#define LED_NUM   4                     /* Number of used LEDs                */

/* LED pins for each LED                                                      */
static const char LED[] = { GPIO_PIN_0, GPIO_PIN_1, GPIO_PIN_2, GPIO_PIN_3 };

/* Send string to the UART0                                                   */
void UART_Send_String (const char *str) {
  while (*str != 0) UARTCharPut(UART0_BASE, *str++);
}

/* Main Program                                                               */
int main (void)
{
  int i, j;

  /* Set the clocking to run directly from the crystal                        */
  SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);

  /* Enable the peripherals: UART0, GPIOA, GPIOB                              */
  SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

  /* Set GPIOB LEDs pins as outputs                                           */
  GPIODirModeSet(GPIO_PORTB_BASE, LED_PINS, GPIO_DIR_MODE_OUT);

  /* Set GPIOA A0 and A1 pins as UART pins                                    */
  GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

  /* Configure the UART0 for 115200, 8-N-1 operation                          */
  UARTConfigSet(UART0_BASE, 115200, (UART_CONFIG_WLEN_8   | 
                                     UART_CONFIG_STOP_ONE | 
                                     UART_CONFIG_PAR_NONE));

  /* Loop forever cycling the outputs to the LEDs                             */
  while (1) {
    UART_Send_String("KEIL DEMO\r\n");
    for (i = 0; i < LED_NUM; i++) {
      GPIOPinWrite(GPIO_PORTB_BASE, LED_PINS, LED[i]);
      for (j = 0; j < 200000; j++);
    }
    for (i = (LED_NUM - 1); i >= 0; i--) {
      GPIOPinWrite(GPIO_PORTB_BASE, LED_PINS, LED[i]);
      for (j = 0; j < 200000; j++);
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -