arm流水灯

#define GPX2CON (*(volatile unsigned int *)0x11000c40)
#define GPX2DAT (*(volatile unsigned int *)0x11000c44)

#define GPX1CON (*(volatile unsigned int *)0x11000c20)
#define GPX1DAT (*(volatile unsigned int *)0x11000c24)

#define GPF3_4CON (*(volatile unsigned int *)0x114001E0)
#define GPF3_4DAT (*(volatile unsigned int *)0x114001E4)

#define GPF3_5CON (*(volatile unsigned int *)0x114001E0)
#define GPF3_5DAT (*(volatile unsigned int *)0x114001E4)

void delay(int d)
{
        int i, j;
        while (d--)
        {
                for (i = 0; i < 5; i++)
                        for (j = 0; j < 514; j++)
                                ;
        }
}

void led_on(int num)
{
        switch (num)
        {
        case 2:
                GPX2DAT |= (1 << 7);
                delay(1000);
               
                break;
        case 3:
                GPX1DAT |= (1 << 0);
                delay(1000);
               
                break;
        case 4:
                GPF3_4DAT |= (1<<4);
                 delay(1000);
                 
                break;
        case 5:
                GPF3_5DAT |=(1<<5);
                delay(1000);
               
                break;
        default:
                break;
        }
}

void led_off(int num)
{
        switch (num)
        {
        case 2:
                 GPX2DAT &= ~(1 << 7);
                delay(1000);
                break;
        case 3:
                 GPX1DAT &= ~(1<<0);
                delay(1000);
                break;
        case 4:
                GPF3_4DAT &= ~(1<<4);
                  delay(1000);
                break;
        case 5:
                 GPF3_5DAT &=~(1<<5);
                delay(1000);
                break;
        default:
                break;
        }
}

void leds_init()
{
        GPX2CON = GPX2CON & (~(0xf << 28)) | (0x1 << 28);
        GPX1CON = GPX1CON & (~(0xf<<0)) | (0x1<<0);
        GPF3_4CON = GPF3_4CON & (~(0xf << 16)) | (0x1 << 16);
        GPF3_5CON = GPF3_5CON & (~(0xf << 20)) | (0x1 << 20);
}


int main()
{
        
	int i=0;
        leds_init();
        while (1)
        {
                for(i=2;i<6;i++)
                {
                        led_on(i);
                        led_off(i);
                }
        }
        

        return 0;
}

Makefile

all:
	arm-none-linux-gnueabi-gcc led_zld.c -o led_zld.o  -c
	arm-none-linux-gnueabi-ld -Ttext 0x40008000 start.o led_zld.o -o led_zld.elf
	arm-none-linux-gnueabi-objcopy -O binary -S led_zld.elf led_zld.bin
clean:

你可能感兴趣的:(C语言,嵌入式硬件,arm开发)