21,597
社区成员
发帖
与我相关
我的任务
分享
#include "lpc21xx.h"
long led_flag; //在这里初始化没用,编译后发现值改变了
const int led_taber[16]={ 0x3F, 0x06 ,0x5B, 0x4F, //加上const才解决问题
0x66, 0x6D ,0x7D, 0x07,
0x7F, 0x67,0x77, 0x7C,
0x39, 0x5E,0x79, 0x71,
} ;
void Led_Add()
{
Ext->INT=0x04;
led_flag++;
led_flag%=16;
Gpio->PIN= led_taber[led_flag];
}
void Led_Sub()
{
Ext->INT=0x08;
led_flag--;
led_flag=(led_flag+16)%16;
Gpio->PIN= led_taber[led_flag];
}
void Init()
{
Pin->SEL0=0x000cc000;//P0.7 P0.9设为EINT2,3
Gpio->DIR=0x7F;//P0.0-P0.6设置为输出
Ext->MODE=ExtMode2|ExtMode3;
Ext->POLAR=ExtPolar2|ExtPolar3;
Vic->IntEnable=(1<<VicEint2)|(1<<VicEint3);
Vic->VectCntl[0]=0x20|VicEint2;
Vic->VectAddr[0]=(u32)Led_Add; //递增
Vic->VectCntl[1]=0x20|VicEint3;
Vic->VectAddr[1]=(u32)Led_Sub; //递减
}
int main()
{
Init();
led_flag=0; //在这里重新赋值,修正一下
Gpio->PIN= led_taber[led_flag];
while(1);
return 1;
}
typedef unsigned long u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef struct
{
u32 SEL0;
u32 SEL1;
u32 SEL2;
}PIN;
#define Pin ((PIN*)0xe002c000) //管脚选择寄存器
typedef struct
{
u32 PIN;
u32 SET;
u32 DIR;
u32 CLR;
}GPIO;
#define Gpio ((GPIO*)0xe0028000)
typedef struct
{
u32 INT;
u32 WAKE;
u32 MODE;
u32 POLAR;
}EXT;
#define Ext ((EXT*)0xe01fc140)
#define ExtInt0 0x1
#define ExtInt1 0x2
#define ExtInt2 0x4
#define ExtInt3 0x8
#define ExtWake0 0x1
#define ExtWake1 0x2
#define ExtWake2 0x4
#define ExtWake3 0x8
#define BodWake (0x1<<14)
#define RtcWake (0x1<<15)
#define ExtMode0 0x1
#define ExtMode1 0x2
#define ExtMode2 0x4
#define ExtMode3 0x8
#define ExtPolar0 0x1
#define ExtPolar1 0x2
#define ExtPolar2 0x4
#define ExtPolar3 0x8
typedef struct
{
u32 IrqStatus;
u32 FiqStatus;
u32 RawIntr;
u32 IntSelect;
u32 IntEnable;
u32 IntEnClr;
u32 SoftInt;
u32 SoftIntClear;
u32 Protection;
u32 rsv1[3];
u32 CurVectAddr;
u32 DefVectAddr;
u32 rsv2[50];
u32 VectAddr[16];
u32 rsv3[48];
u32 VectCntl[16];
}VIC;
#define Vic ((VIC*)0xfffff000)
#define VicWdt 0
#define VicSwi 1
#define VicDbgCommRx 2
#define VicDbgCommTx 3
#define VicTmr0 4
#define VicTmr1 5
#define VicUart0 6
#define VicUart1 7
#define VicPwm0 8
#define VicI2c0 9
#define VicSpi0 10
#define VicSpi1 11
#define VicPll 12
#define VicRtc 13
#define VicEint0 14
#define VicEint1 15
#define VicEint2 16
#define VicEint3 17
#define VicAd0 18
#define VicI2c1 19
#define VicBod 20
#define VicAd1 21