高级会员
- 积分
- 900
- 威望
- 455
- 贡献
- 251
- 兑换币
- 206
- 注册时间
- 2012-4-27
- 在线时间
- 97 小时
|
/*
* main implementation: use this 'C' sample to create your own application
*
*/
#include <stdio.h>
#include "derivative.h" /* include peripheral declarations */
#define GPIO_PIN_MASK 0x1Fu
#define GPIO_PIN(x) (((1)<<(x & GPIO_PIN_MASK)))
//Function declarations
void init_gpio(void);
void delay(void);
int main(void)
{
/* Turn on all port clocks */
SIM_SCGC5 = SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTC_MASK | SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTE_MASK;
init_gpio();
for(;;)
{
GPIOA_PTOR=0X0003c000;
delay();//延时
}
return 0;
}
void init_gpio()
{
//Set PTA10, PTA11, PTA28, and PTA29 (connected to LED's) for GPIO functionality
PORTA_PCR14=(0|PORT_PCR_MUX(1));
PORTA_PCR15=(0|PORT_PCR_MUX(1));
PORTA_PCR16=(0|PORT_PCR_MUX(1));
PORTA_PCR17=(0|PORT_PCR_MUX(1));
//Change PTA14, PTA15, PTA16, PTA17 to outputs
GPIOA_PDDR=GPIO_PDDR_PDD(GPIO_PIN(14) | GPIO_PIN(15) | GPIO_PIN(16) | GPIO_PIN(17) );
}
void delay()
{
unsigned int i, n;
for(i=0;i<30000;i++)
{
for(n=0;n<100;n++)
{
asm("nop");
}
}
}
再把其中的引脚配置改成你自己板子上的就行了。是4个灯同时闪烁。 |
|