原创 LPC11xxcfg.h(V1.06)

2010-8-18 01:52 1487 7 7 分类: MCU/ 嵌入式

点击拷贝全文:   http://bbs.21ic.com/icview-190541-1-1.html


//KEY1宏定义三板斧
#define PioKey1   PIO2_6 //P2.6
#define PortKey1  P2     //P2
#define PinKey1   Pin6   //Px.6
//KEY2宏定义三板斧
#define PioKey2   PIO2_0 //P2.0
#define PortKey2  P2     //P2
#define PinKey2   Pin0   //Px.0


//LED1宏定义三板斧
#define PioLed1   PIO1_8 //P1.8
#define PortLed1  P1     //P1
#define PinLed1   Pin8   //Px.8
//LED2宏定义三板斧
#define PioLed2   PIO0_2 //P0.2
#define PortLed2  P0     //P0
#define PinLed2   Pin2   //Px.2
//LED3宏定义三板斧
#define PioLed3   PIO2_7 //P2.7
#define PortLed3  P2     //P2
#define PinLed3   Pin7   //Px.7
//LED4宏定义三板斧
#define PioLed4   PIO2_8 //P2.8
#define PortLed4  P2     //P2
#define PinLed4   Pin8   //Px.8
//LED5宏定义三板斧
#define PioLed5   PIO2_1 //P2.1
#define PortLed5  P2     //P2
#define PinLed5   Pin1   //Px.1
//LED6宏定义三板斧
#define PioLed6   PIO1_9 //P1.9
#define PortLed6  P1     //P1
#define PinLed6   Pin9   //Px.9
//LED7宏定义三板斧
#define PioLed7   PIO3_4 //P3.4
#define PortLed7  P3     //P3
#define PinLed7   Pin4   //Px.4
//LED8宏定义三板斧
#define PioLed8   PIO3_5 //P3.5
#define PortLed8  P3     //P3
#define PinLed8   Pin5   //Px.5
//BEEP宏定义三板斧
#define PioBeep   PIO0_8 //P0.8
#define PortBeep  P0     //P0
#define PinBeep   Pin8   //Px.8


#include "main.h"
volatile unsigned int SystemRamTest = 0x55aa55aa;//RAM不初始化


/*-------------------------------------------
注意:
1.全局类对象实例的构造函数运行级别高于main()
2.类的构造函数的运行次序与申请次序一样
--------------------------------------------*/
SystemObj System;//自动调用构造函数
SysTickObj SystemTick;//自动调用构造函数
TimerObj  Timer;//自动调用构造函数
UartObj   Uart;//自动调用构造函数
TargetObj Target;//自动调用构造函数
/*-------------------------------------------
main()将在以上构造函数后才能运行
--------------------------------------------*/
int main()
{
/*
//位域写法
 IOCON.TXD.Bits.FUNC = IOCON_TXD;
 IOCON.TXD.Bits.MODE = IOCON_UP;
//寄存器写法
 IOCON.TXD.Regs = (IOCON_TXD << IOCON_FUNC)
                | (IOCON_UP << IOCON_MODE);
//位域写法
 IOCON.RXD.Bits.FUNC = IOCON_RXD;
 IOCON.RXD.Bits.MODE = IOCON_UP;
//寄存器写法
 IOCON.RXD.Regs = (IOCON_RXD << IOCON_FUNC)
                | (IOCON_UP << IOCON_MODE);
//位域写法
 IOCON.PIO0_4.Bits.FUNC    = IOCON_SCL;//选择PIO0.4为I2C_SCL
 IOCON.PIO0_4.Bits.I2CMODE = IOCON_SCL_I2CMODE;//选择PIO0.4为I2C_SCL
 IOCON.PIO0_5.Bits.FUNC    = IOCON_SDA;//选择PIO0.5为I2C_SCL
 IOCON.PIO0_5.Bits.I2CMODE = IOCON_SDA_I2CMODE;//选择PIO0.5为I2C_SDA
//寄存器写法
 IOCON.PIO0_4.Regs = (IOCON_SCL << IOCON_FUNC)
                   | (IOCON_SCL_I2CMODE << IOCON_I2CMODE);
 IOCON.PIO0_5.Regs = (IOCON_SDA << IOCON_FUNC)
                   | (IOCON_SDA_I2CMODE << IOCON_I2CMODE);
//位域写法
 IOCON.PIO2_6.Bits.FUNC = IOCON_PIO2_6;//选择PIO2.6为IO
 IOCON.PIO2_6.Bits.FUNC = IOCON_PIO;//选择PIO2.6为IO
 IOCON.PIO2_6.Bits.MODE = IOCON_UP;//选择PIO2.6上拉电阻
 IOCON.PIO2_0.Bits.FUNC = IOCON_PIO2_0_SSEL1;//选择PIO2.0为SSEL1
 IOCON.PIO2_0.Bits.FUNC = IOCON_SSEL1;//选择PIO2.0为SSEL1
  P0.DIR.Bits.Pin2 = 1;
  PX(0).DIR.Bits.Pin2 = 1;
 PX(1).DIR.Bits.Pin8 = 1;
//
*/
 SYSCON.SYSAHBCLKCTRL.Bits.GPIOCLK = 1;//使能GPIO的时钟
//BeepInit
 IOCON.PioBeep.Bits.FUNC = IOCON_PIO;//选择PIO0.8为BEEP
 IOCON.PioBeep.Bits.MODE = IOCON_DOWN;//下拉电阻
 PortBeep.DIR.Bits.PinBeep = 1;//设置输出方式
 PortBeep.DATA.Bits.PinBeep = 0;//蜂鸣器不响
//Key1Init
 IOCON.PioKey1.Bits.FUNC = IOCON_PIO;//选择P2.6为KEY1
 IOCON.PioKey1.Bits.MODE = IOCON_UP;//上拉电阻
 PortKey1.DIR.Bits.PinKey1 = 0;//设置输输入方式
 PortKey1.DATA.Bits.PinKey1 = 1;//释放键盘
//Key2Init
 IOCON.PioKey2.Bits.FUNC = IOCON_PIO;//选择P2.0为KEY2
 IOCON.PioKey2.Bits.MODE = IOCON_UP;//上拉电阻
 PortKey2.DIR.Bits.PinKey2 = 0;//设置输输入方式
 PortKey2.DATA.Bits.PinKey2 = 1;//释放键盘
//Led1Init
 IOCON.PioLed1.Bits.FUNC = IOCON_PIO;//选择PIO1.8为LED1
 IOCON.PioLed1.Bits.MODE = IOCON_UP;//上拉电阻
 PortLed1.DIR.Bits.PinLed1 = 1;//设置输出方式
 PortLed1.DATA.Bits.PinLed1 = 1;//LED1灭
//Led2Init
 IOCON.PioLed2.Bits.FUNC = IOCON_PIO;//选择PIO0.2为LED2
 IOCON.PioLed2.Bits.MODE = IOCON_UP;//上拉电阻
 PortLed2.DIR.Bits.PinLed2 = 1;//设置输出方式
 PortLed2.DATA.Bits.PinLed2 = 0;//LED2亮
//Led3Init
 IOCON.PioLed3.Bits.FUNC = IOCON_PIO;//选择PIO2.7为LED3
 IOCON.PioLed3.Bits.MODE = IOCON_UP;//上拉电阻
 PortLed3.DIR.Bits.PinLed3 = 1;//设置输出方式
 PortLed3.DATA.Bits.PinLed3 = 1;//LED3灭
//Led4Init
 IOCON.PioLed4.Bits.FUNC = IOCON_PIO;//选择PIO2.8为LED4
 IOCON.PioLed4.Bits.MODE = IOCON_UP;//上拉电阻
 PortLed4.DIR.Bits.PinLed4 = 1;//设置输出方式
 PortLed4.DATA.Bits.PinLed4 = 0;//LED4亮
//Led5Init
 IOCON.PioLed5.Bits.FUNC = IOCON_PIO;//选择P2.1为LED5
 IOCON.PioLed5.Bits.MODE = IOCON_UP;//上拉电阻
 PortLed5.DIR.Bits.PinLed5 = 1;//设置输出方式
 PortLed5.DATA.Bits.PinLed5 = 1;//LED5灭
//Led6Init
 IOCON.PioLed6.Bits.FUNC = IOCON_PIO;//选择P1.9为LED6
 IOCON.PioLed6.Bits.MODE = IOCON_UP;//上拉电阻
 PortLed6.DIR.Bits.PinLed6 = 1;//设置输出方式
 PortLed6.DATA.Bits.PinLed6 = 0;//LED6亮
//Led7Init
 IOCON.PioLed7.Bits.FUNC = IOCON_PIO;//选择P3.4为LED7
 IOCON.PioLed7.Bits.MODE = IOCON_UP;//上拉电阻
 PortLed7.DIR.Bits.PinLed7 = 1;//设置输出方式
 PortLed7.DATA.Bits.PinLed7 = 1;//LED7灭
//Led8Init
 IOCON.PioLed8.Bits.FUNC = IOCON_PIO;//选择P3.5为LED8
 IOCON.PioLed8.Bits.MODE = IOCON_UP;//上拉电阻
 PortLed8.DIR.Bits.PinLed8 = 1;//设置输出方式
 PortLed8.DATA.Bits.PinLed8 = 0;//LED8亮


 while(1) {//PX(i)可变真美妙
//  PX(0).DATA.Bits.Pin2 ^= 1;
//  PX(1).DATA.Bits.Pin8 ^= 1;
  PortLed1.DATA.Bits.PinLed1 ^= 1;
  PortLed2.DATA.Bits.PinLed2 ^= 1;
  PortLed3.DATA.Bits.PinLed3 ^= 1;
  PortLed4.DATA.Bits.PinLed4 ^= 1;
  PortLed5.DATA.Bits.PinLed5 ^= 1;
  PortLed6.DATA.Bits.PinLed6 ^= 1;
  PortLed7.DATA.Bits.PinLed7 ^= 1;
  PortLed8.DATA.Bits.PinLed8 ^= 1;
  __NOP(); 
  PortBeep.DATA.Bits.PinBeep ^= 1;//蜂鸣器响
  __NOP(); 
  __NOP(); 
  __NOP(); 
  __NOP(); 
  __NOP();
  for (int i = 0; i < 888888; i ++)//延时
  {
   __NOP();
  } 
  if (PortBeep.DATA.Bits.PinBeep)//蜂鸣器响
  {
   while(!PortKey1.DATA.Bits.PinKey1);//等待Key1释放
  }
  else//蜂鸣器不响
  {
   while(!PortKey2.DATA.Bits.PinKey2);//等待Key2释放
  }
 }
}

文章评论0条评论)

登录后参与讨论
我要评论
0
7
关闭 站长推荐上一条 /2 下一条