第一种方法就是开发板自己带的那个固件库里的例程
一般都直接装在C盘,
我的安装路径是:C:\StellarisWare\boards\ek-lm3s8962\blinky
为了方便我把它打个包,这个是不用库的
#include "inc/lm3s8962.h"
//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Blinky (blinky)</h1>
//!
//! A very simple example that blinks the on-board LED.
//
//*****************************************************************************
//*****************************************************************************
//
// Blink the on-board LED.
//
//*****************************************************************************
int
main(void)
{
volatile unsigned long ulLoop;
//
// Enable the GPIO port that is used for the on-board LED.
//
SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;
//
// Do a dummy read to insert a few cycles after enabling the peripheral.
//
ulLoop = SYSCTL_RCGC2_R;
//
// Enable the GPIO pin for the LED (PF0). Set the direction as output, and
// enable the GPIO pin for digital function.
//
GPIO_PORTF_DIR_R = 0x01;
GPIO_PORTF_DEN_R = 0x01;
//
// Loop forever.
//
while(1)
{
//
// Turn on the LED.
//
GPIO_PORTF_DATA_R |= 0x01;
//
// Delay for a bit.
//
for(ulLoop = 0; ulLoop < 200000; ulLoop++)
{
}
//
// Turn off the LED.
//
GPIO_PORTF_DATA_R &= ~(0x01);
//
// Delay for a bit.
//
for(ulLoop = 0; ulLoop < 200000; ulLoop++)
{
}
}
}
程序打包:
blinky.zip
(162.32 KB, 下载次数: 29)
看来超简单,下面这个我自己调通的用库的哈:
注意下:
用库时一定要加上如下:
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
涉及到系统时钟还应加上:
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
我发现它们都在 driverlib 里,这个是MDK包含的目录,
再有就是用什么加什么的头文件,
程序列出哈:
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "gpio.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "drivers/rit128x96x4.h"
//*****************************************************************************
//
//! \addtogroup example_list
//! <h1>Hello World (hello)</h1>
//!
//! A very simple ``hello world'' example. It simply displays ``hello world''
//! on the OLED and is a starting point for more complicated applications.
//
//*****************************************************************************
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif
delay(int d)
{
for(;d;--d)
;
}
//*****************************************************************************
//
// Print "Hello world!" to the OLED on the Stellaris evaluation board.
//
//*****************************************************************************
int
main(void)
{
//
// Set the clocking to run directly from the crystal.
//
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);//这里是给F口时钟
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, 0x01 );//设F0为输出
//
// Initialize the OLED display.
//
RIT128x96x4Init(1000000);
//
// Hello!
//
RIT128x96x4StringDraw("Hello World!", 30, 24, 15);
//
// Finished.
//
while(1)
{
GPIOPinWrite(GPIO_PORTF_BASE,(GPIO_PIN_0 ),0x01); //F0高电平
RIT128x96x4StringDraw("TEH LED IS HIGH", 30, 24, 15);//在OLED显示一下
delay(60000);
delay(60000);
delay(60000);
delay(60000);
delay(60000);
GPIOPinWrite(GPIO_PORTF_BASE,(GPIO_PIN_0 ),0x00);
RIT128x96x4StringDraw("TEH LED IS LOW", 30, 24, 15);
delay(60000);
delay(60000);
delay(60000);
delay(60000);
delay(60000);
}
}
程序打包哈:
blinkcool.zip
(279.25 KB, 下载次数: 28)