前一段时间由于一直在忙图片和音乐的解码,NXP的板子到了也没时间马上开始弄,前两天下了LPCXpresso软件注册安装一下,觉的用着还比较方便呢。先是直接加载自带的Examples例子。下面是其过程:
首先打开LPCXpresso软件
接着就是插入example例子
通过browse找到example的存档地址,添加文件LPC1000系列中的LPC13xx
然后就可以加载1343examples例子项目
点击Finish后就成功加载了
点击带有昆虫图标的调试按钮后,就成功的把程序下载到板子里了,这样就出现blinky实现的LEC闪烁效果了。
下面看一下程序啦
#define LPC_I2C ((LPC_I2C_TypeDef *) LPC_I2C_BASE )
#define LPC_WDT ((LPC_WDT_TypeDef *) LPC_WDT_BASE )
#define LPC_UART ((LPC_UART_TypeDef *) LPC_UART_BASE )
#define LPC_TMR16B0 ((LPC_TMR_TypeDef *) LPC_CT16B0_BASE)
#define LPC_TMR16B1 ((LPC_TMR_TypeDef *) LPC_CT16B1_BASE)
#define LPC_TMR32B0 ((LPC_TMR_TypeDef *) LPC_CT32B0_BASE)
#define LPC_TMR32B1 ((LPC_TMR_TypeDef *) LPC_CT32B1_BASE)
#define LPC_ADC ((LPC_ADC_TypeDef *) LPC_ADC_BASE )
#define LPC_PMU ((LPC_PMU_TypeDef *) LPC_PMU_BASE )
#define LPC_SSP ((LPC_SSP_TypeDef *) LPC_SSP_BASE )
#define LPC_IOCON ((LPC_IOCON_TypeDef *) LPC_IOCON_BASE )
#define LPC_SYSCON ((LPC_SYSCON_TypeDef *) LPC_SYSCON_BASE)
#define LPC_USB ((LPC_USB_TypeDef *) LPC_USB_BASE )
#define LPC_GPIO0 ((LPC_GPIO_TypeDef *) LPC_GPIO0_BASE )
#define LPC_GPIO1 ((LPC_GPIO_TypeDef *) LPC_GPIO1_BASE )
#define LPC_GPIO2 ((LPC_GPIO_TypeDef *) LPC_GPIO2_BASE )
#define LPC_GPIO3 ((LPC_GPIO_TypeDef *) LPC_GPIO3_BASE )
这些定义了所有程序可能涉及到的寄存器地址,例外LPC13xx.h文件里定义了所有的寄存器,这样以后我们就可以直接使用。
void GPIOInit( void )
{
/* Enable AHB clock to the GPIO domain. */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
#ifdef __JTAG_DISABLED
LPC_IOCON->JTAG_TDO_PIO1_1 &= ~0x07;
LPC_IOCON->JTAG_TDO_PIO1_1 |= 0x01;
#endif
/* Set up NVIC when I/O pins are configured as external interrupts. */
NVIC_EnableIRQ(EINT0_IRQn);
NVIC_EnableIRQ(EINT1_IRQn);
NVIC_EnableIRQ(EINT2_IRQn);
NVIC_EnableIRQ(EINT3_IRQn);
return;
}其函数初始化了I/O口并设置了I/O口中断功能,然后使能中断。
void GPIOSetInterrupt( uint32_t portNum, uint32_t bitPosi, uint32_t sense,
uint32_t single, uint32_t event )
{
switch ( portNum )
{
case PORT0:
if ( sense == 0 )
{
LPC_GPIO0->IS &= ~(0x1<<bitPosi);
/* single or double only applies when sense is 0(edge trigger). */
if ( single == 0 )
LPC_GPIO0->IBE &= ~(0x1<<bitPosi);
else
LPC_GPIO0->IBE |= (0x1<<bitPosi);
}
else
LPC_GPIO0->IS |= (0x1<<bitPosi);
if ( event == 0 )
LPC_GPIO0->IEV &= ~(0x1<<bitPosi);
else
LPC_GPIO0->IEV |= (0x1<<bitPosi);
break;
case PORT1:
if ( sense == 0 )
{
LPC_GPIO1->IS &= ~(0x1<<bitPosi);
/* single or double only applies when sense is 0(edge trigger). */
if ( single == 0 )
LPC_GPIO1->IBE &= ~(0x1<<bitPosi);
else
LPC_GPIO1->IBE |= (0x1<<bitPosi);
}
else
LPC_GPIO1->IS |= (0x1<<bitPosi);
if ( event == 0 )
LPC_GPIO1->IEV &= ~(0x1<<bitPosi);
else
LPC_GPIO1->IEV |= (0x1<<bitPosi);
break;
case PORT2:
if ( sense == 0 )
{
LPC_GPIO2->IS &= ~(0x1<<bitPosi);
/* single or double only applies when sense is 0(edge trigger). */
if ( single == 0 )
LPC_GPIO2->IBE &= ~(0x1<<bitPosi);
else
LPC_GPIO2->IBE |= (0x1<<bitPosi);
}
else
LPC_GPIO2->IS |= (0x1<<bitPosi);
if ( event == 0 )
LPC_GPIO2->IEV &= ~(0x1<<bitPosi);
else
LPC_GPIO2->IEV |= (0x1<<bitPosi);
break;
case PORT3:
if ( sense == 0 )
{
LPC_GPIO3->IS &= ~(0x1<<bitPosi);
/* single or double only applies when sense is 0(edge trigger). */
if ( single == 0 )
LPC_GPIO3->IBE &= ~(0x1<<bitPosi);
else
LPC_GPIO3->IBE |= (0x1<<bitPosi);
}
else
LPC_GPIO3->IS |= (0x1<<bitPosi);
if ( event == 0 )
LPC_GPIO3->IEV &= ~(0x1<<bitPosi);
else
LPC_GPIO3->IEV |= (0x1<<bitPosi);
break;
default:
break;
}
return;
}该函数配置了GPIOnIS、GPIOnIBE、GPIOnIEV等寄存器,设置了中断的边沿触发或者电平触发和边沿方式或者电平方式触发等内容。
static __INLINE void GPIOSetDir( uint32_t portNum, uint32_t bitPosi, uint32_t dir )
{
if(dir)
LPC_GPIO[portNum]->DIR |= 1<<bitPosi;
else
LPC_GPIO[portNum]->DIR &= ~(1<<bitPosi);
}
该函数设置了GPIOnDIR寄存器,位n:0表示输入,位n:1表示输出。
void GPIOIntEnable( uint32_t portNum, uint32_t bitPosi )
{
switch ( portNum )
{
case PORT0:
LPC_GPIO0->IE |= (0x1<<bitPosi);
break;
case PORT1:
LPC_GPIO1->IE |= (0x1<<bitPosi);
break;
case PORT2:
LPC_GPIO2->IE |= (0x1<<bitPosi);
break;
case PORT3:
LPC_GPIO3->IE |= (0x1<<bitPosi);
break;
default:
break;
}
return;
}
该函数设置了管脚的中断是否被屏蔽,以上仅仅是GPIO口的一些设置,内容后续哦……刚开始学习,可能会出现理解偏差,请大家多多指教哦……:loveliness: