A total of three files: head. S LED_ON_C.C Makefile
- Head. The contents of s are as follows:
1 /*2* * Time: 2016year April 8: About: *3 * * location: Dormitory. 4 * * Function: Initialize some hardware related things, call C function. 5 ** 6 * * Additional information:7**1, operating Environment: JZ2440V2 Development Board. 8**2, program compilation Environment: UBUNTU9.Ten+ cross-compilation tool ARM-LINUX-GCC. 9**3, the registers used are: Gpfcon, Gpfdat, Wtcon. Ten**4, the pin that the led1 receives is the GPF4 pin. One */ A - . equ Wtcon, 0X53000000 @ macro definition Wtcon to 0x53000000 - the . Text - - . Global _start - + _start: - / * Close the watchdog to prevent the CPU from constantly starting. */ + Ldr R0, = Wtcon A movR1, #0 at StrR1, [R0] - - / * Set the stack first before calling the C function. */ -Ldr sp, =4096 - - / * Call the C function. */ in BL main - to Halt_loop: +b halt_loop
- LED_ON_C.C content is as follows:
1 /* 2* * Time: 2016year April 8: to: at3 * * location: Dormitory. 4 * * Function: Light the first led:led1. 5 */6 7 #define GPFCON * (volatile unsigned long *) 0x56000050)8 #define GPFDAT * (volatile unsigned long *) 0x56000054)9 Ten intmain (void) One { A / * Configure the GPF4 pin as the output pin. */ -Gpfcon = 0x00000100; - the / * Let the GPF4 pin output low, light led1. */ -Gpfdat = 0x00000000; - -while (1); + -Return0; +}
- The contents of the makefile file are as follows:
#
#时间: April 8, 2016 17:11:09
#
Led_on_c.bin:head. S LED_ON_C.C
Arm-linux-gcc-wall-g-C head. S-o HEAD.O
Arm-linux-gcc-wall-g-C Led_on_c.c-o LED_ON_C.O
Arm-linux-ld-ttext 0x00000000-g HEAD.O Led_on_c.o-o led_on_c_elf
Arm-linux-objcopy-o binary-s led_on_c_elf Led_on_c.bin
arm-linux-objdump-d-M arm led_on_c_elf > Led_on_c_elf.dis
arm-linux-objdump-d-B binary-m arm led_on_c.bin > Led_on_c_bin.dis
Clean:
Rm-f *.o *.dis *.bin *elf
2nd program: Use C language to illuminate an LED