分享一个简单的流水灯程序:
#include "common.h"
#define LED1(a) if(a)\
GPIOA_PDOR &= ~(1<<10);\
else\
GPIOA_PDOR |= (1<<10)
#define LED2(a) if(a)\
GPIOA_PDOR &= ~(1<<11);\
else\
GPIOA_PDOR |= (1<<11)
#define LED3(a) if(a)\
GPIOA_PDOR &= ~(1<<28);\
else\
GPIOA_PDOR |= (1<<28)
#define LED4(a) if(a)\
GPIOA_PDOR &= ~(1<<29);\
else\
GPIOA_PDOR |= (1<<29)
void init_gpio(void);
void delay(long count);
void main (void)
{
init_gpio();
LED2(0);
LED3(0);
while(1)
{
LED4(0); //灭
LED1(1); //亮
delay(3000000);
LED2(1);
LED1(0);
delay(3000000);
LED3(1);
LED2(0);
delay(3000000);
LED3(0);
LED4(1);
delay(3000000);
}
}
void init_gpio()
{
PORTA_PCR10 &= ~0x700; //MUX 000
PORTA_PCR10 |= PORT_PCR_MUX(1); //MUX 001 GPIO模式
PORTA_PCR11 &= ~0x700;
PORTA_PCR11 |= PORT_PCR_MUX(1);
PORTA_PCR28 &= ~0x700;
PORTA_PCR28 |= PORT_PCR_MUX(1);
PORTA_PCR29 &= ~0x700;
PORTA_PCR29 |= PORT_PCR_MUX(1);
GPIOA_PDDR |= ((1<<10)|(1<<11)|(1<<28)|(1<<29)); //设置为输出
}
void delay(long count)
{
while(count--)
asm("nop");
}
I0口初始化
寄存器功能
|