#include "hw_ints.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "gpio.h"
#include "sysctl.h"
//#include "cpu.h"
//#include "interrupt.h"
//#include "hw_timer.h"
//#include "debug.h"
#include "timer.h"
#define uint unsigned int
#define uchar unsigned char
#define LED_PERIPBH SYSCTL_PERIPH_GPIOB //LED外围 B端口作为通用输入/输出 宏定义
#define LED_PERIPDH SYSCTL_PERIPH_GPIOD //LED外围 D端口作为通用输入/输出 宏定义
#define LED_PERIPEH SYSCTL_PERIPH_GPIOE //LED外围 E端口作为通用输入/输出 宏定义
#define BLUE1_L GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_1,0) //BLUE1管脚为低
#define GREEN1_L GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_0,0) //GREEN1管脚为低
#define RED1_L GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_1,0) //RED1管脚为低
#define BLUE2_L GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0,0) //BLUE2管脚为低
#define GREEN2_L GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_1,0) //GREEN2管脚为低
#define RED2_L GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_0,0) //RED2管脚为低
#define BLUE1_H GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_1,1) //BLUE1管脚为高
#define GREEN1_H GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_0,1) //GREEN1管脚为高
#define RED1_H GPIOPinWrite(GPIO_PORTE_BASE,GPIO_PIN_1,1) //RED1管脚为高
#define BLUE2_H GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_0,1) //BLUE2管脚为高
#define GREEN2_H GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_1,1) //GREEN2管脚为高
#define RED2_H GPIOPinWrite(GPIO_PORTB_BASE,GPIO_PIN_0,1) //RED2管脚为高
void delay(uint a)
{
uint i,j;
for(i=10000;i>0;i--)
for(j=a;j>0;j--)
{
}
}
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_6MHZ);
//SysCtlClockSet函数()系统时钟设置 采用主振荡器 外接6MHz晶振 不分频
SysCtlPeripheralEnable(LED_PERIPBH); //使能LED所在引脚
SysCtlPeripheralEnable(LED_PERIPDH);
SysCtlPeripheralEnable(LED_PERIPEH);
//GPIO输出型的
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0);
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1);
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0);
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_1);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0);
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_1);
while(1)
{
BLUE1_L;
BLUE2_L;
RED1_L;
RED2_L;
GREEN1_L;
GREEN2_L;
delay(100);
BLUE1_H;
BLUE2_H;
RED1_H;
RED2_H;
GREEN1_H;
GREEN2_H;
}
}
对其中一些,做了修改,运行通过了,但也遇到了一些问题:只看到了L4、L5、L7闪烁,其他三个,没看到明显效果,还有就是闪烁的效果没有那么炫,对板子初次上电时,感觉很炫!
自己用相机拍了些演示视频,有些模糊,不过还可以看得清:
自己刚传到优酷,还在审核中,稍后把链接发出来!
http://v.youku.com/v_show/id_XMjY2ODI2NTMy.htm[flash=media]http://v.youku.com/v_show/id_XMjY2ODI2NTMy.html[/flash]l
希望论坛的高手能多指教、指教!谢谢!
关于工程的完整文件,在论坛里上传:名字:LED&LM3S811
下面是6个LED闪烁对角点亮的程序,贴出来,和没有板子的朋友一起分享,程序运行后效果如视屏连接中所示,很炫,很夺目,呵呵。。。
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/adc.h"
#include "inc/lm3s811.h"
#include "driverlib/timer.h"
#include "driverlib/interrupt.h"
#include "inc/hw_ints.h"
unsigned char TIME=0;
#define New_Edition
#define Blink_First 0
#define Blink_Second 2
#define Blink_Third 4
#define Blue_Blink_Fast 6
#define Green_Blink_Fast 7
#define Red_Blink_Fast 8
#define Blue_Blink_Slow 15
#define Green_Blink_Slow 20
#define Red_Blink_Slow 25
#define All_LED_Close 80
#define LED_Close_Status_A 100
#define LED_Close_Status_B 200
void delay() //程序延时
{
int i=300000;
while(i>0)
{
i--;
}
}
void O_D2()
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,GPIO_PIN_5);
}
void C_D2()
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,0);
}
void O_L3()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,~0);
#else
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,0);
#endif
}
void C_L3()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,~GPIO_PIN_0);
#else
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_0,GPIO_PIN_0);
#endif
}
void O_L4()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1,~0);
#else
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1,0);
#endif
}
void C_L4()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1,~GPIO_PIN_1);
#else
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1,GPIO_PIN_1);
#endif
}
void O_L5()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,~0);
#else
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,0);
#endif
}
void C_L5()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,~GPIO_PIN_0);
#else
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0,GPIO_PIN_0);
#endif
}
void O_L6()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,~0);
#else
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,0);
#endif
}
void C_L6()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,~GPIO_PIN_1);
#else
GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1,GPIO_PIN_1);
#endif
}
void O_L7()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0,~0);
#else
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0,0);
#endif
}
void C_L7()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0,~GPIO_PIN_0);
#else
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_0,GPIO_PIN_0);
#endif
}
void O_L8()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1,~0);
#else
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1,0);
#endif
}
void C_L8()
{
#ifdef New_Edition
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1,~GPIO_PIN_1);
#else
GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1,GPIO_PIN_1);
#endif
}
void OA()
{
O_L3();O_L4();O_L5();O_D2();O_L6();O_L7();O_L8();
}
void CA()
{
C_L3();C_L4();C_L5();C_D2();C_L6();C_L7();C_L8();
}
void
Timer0IntHandler(void)
{
//
// 清除 Timer 中断
//
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TIME++;
if(TIME == LED_Close_Status_B) // 状态在 LED_Close_Status_A 与 LED_Close_Status_B 之间,LED 始终为灭的状态
TIME = LED_Close_Status_A;
}
void
SysTickIntHandler(void)
{
if(GPIOPinRead(GPIO_PORTC_BASE,GPIO_PIN_4)==0x00)//检测 USER 键是否被按下
TIME=0; //将控制 LED 状态的标志归零
}
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ);//配置系统时钟
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB | SYSCTL_PERIPH_GPIOC | SYSCTL_PERIPH_GPIOD | SYSCTL_PERIPH_GPIOE);//启用 GPIO B、C、D 和 E
SysTickPeriodSet(SysCtlClockGet() / 20);//配置系统最小时间中断
SysTickIntEnable();//启用最小时间中断
GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);//配置PB0、PB1为输出
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_5 );//配置PC5为输出
GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4 );//配置PC4为输入
GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_0 | GPIO_PIN_1);//配置PD0、PD1为输出
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_0 | GPIO_PIN_1);//配置PE0、PE1为输出
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);//启用 Timer0
TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);//配置 Timer0 为 32 位的定时器
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/2);//配置 Timer0 的时间为 0.5 秒
//
// 启用 Timer0/SysTick
//
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
SysTickEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
CA();//先关闭所有的 LED 灯
while(1)
{
//开机闪三下
if(TIME == Blink_First)
{
OA();
}
if(TIME == Blink_First+1)
{
CA();
}
if(TIME == Blink_Second)
{
OA();
}
if(TIME == Blink_Second+1)
{
CA();
}
if(TIME == Blink_Third)
{
OA();
}
if(TIME == Blink_Third+1)
{
CA();
}
//进入对角快闪状态
if((TIME == Blue_Blink_Fast)||(TIME == Blue_Blink_Fast+3)||(TIME == Blue_Blink_Fast+6))
{
O_L3();O_L6();C_L5();C_L8();
}
if((TIME == Green_Blink_Fast)||(TIME == Green_Blink_Fast+3)||(TIME == Green_Blink_Fast+6))
{
O_L4();O_L7();C_L3();C_L6();
}
if((TIME == Red_Blink_Fast)||(TIME == Red_Blink_Fast+3)||(TIME == Red_Blink_Fast+6))
{
O_L5();O_L8();C_L4();C_L7();
}
//进入对角慢闪状态
if((TIME == Blue_Blink_Slow)||(TIME == Blue_Blink_Slow+15)||(TIME == Blue_Blink_Slow+30)||(TIME == Blue_Blink_Slow+45))
{
O_L3();O_L6();delay();C_L5();C_L8();
}
if((TIME == Green_Blink_Slow)||(TIME == Green_Blink_Slow+15)||(TIME == Green_Blink_Slow+30)||(TIME == Green_Blink_Slow+45))
{
O_L4();O_L7();delay();C_L3();C_L6();
}
if((TIME == Red_Blink_Slow)||(TIME == Red_Blink_Slow+15)||(TIME == Red_Blink_Slow+30)||(TIME == Red_Blink_Slow+45))
{
O_L5();O_L8();delay();C_L4();C_L7();
}
//超时,未按下 USER 键,则关闭所有的 LED 灯
if(TIME > All_LED_Close)
{
CA();
}
};
}
优酷视频:http://v.youku.com/v_show/id_XMjY2ODI2NTMy.html
完整的工程文件会在论坛上传,请大家谅解!