按键控制le灯c语言程序,C语言按键控制led灯和蜂鸣器

循环流水灯和蜂鸣器,按键结束

#define rGPJ2CON (*(volatile unsigned long *)0xe0200280)

#define rGPJ2DAT (*(volatile unsigned long *)0xe0200284)

#define rGPD0CON (*(volatile unsigned long *)0xe02000a0)

#define rGPD0DAT (*(volatile unsigned long *)0xe02000a4)

#define rGPH2CON (*(volatile unsigned long *)0xe0200c40)

#define rGPH2DAT (*(volatile unsigned long *)0xe0200c44)

void Led_RunDelay(volatile int count);

int main(void)

{

int i=0,temp=0,k1;

rGPJ2CON = 0x1111;

rGPJ2DAT = 0xf;

rGPH2CON =0x00;

rGPH2DAT = 0XFF;

while (k1!=0)

{

rGPJ2DAT = ~(0x1<

流水灯循环5次

#define rGPJ2CON *((volatile unsigned int *)0xe0200280)

#define rGPJ2DAT *((volatile unsigned int *)0xe0200284)

void c_delay(void);

//要定义下函数,如果是放到api.h文件里的,就可以导入不用定义了

void led_test(void)

{

led_init();

int i=5;

while(i--)

{

rGPJ2DAT=0xe;

c_delay();

rGPJ2DAT=0xd;

c_delay();

rGPJ2DAT=0xb;

c_delay();

rGPJ2DAT=0x7;

c_delay();

}

}

int led_init(void)

{

rGPJ2CON&=~(0xffff<<0);

rGPJ2CON|=(0x1111<<0);

rGPJ2DAT|=(0xf<<0);

}

void c_delay(void)

{

volatile int i,j;

for(j = 0; j < 0x100; j++)

for(i = 0; i < 1000; i++);

}

makefile

all:led.bin clean

led.bin:led.o

arm-linux-ld -Ttext=0x40000000 led.o -o led.elf

arm-linux-objcopy -O binary -S led.elf led.bin

led.o:led.c

arm-linux-gcc -c -nostdlib -nostdinc led.c -o led.o

clean:

rm -rf led.o led.elf

你可能感兴趣的:(按键控制le灯c语言程序)