一、GPIO硬件介绍
S3C2440A has 130 multi-functional input/output port pins and there are eight ports as shown below:
Port A(GPA): 25-output port
Port B(GPB): 11-input/out port
Port C(GPC): 16-input/output port
Port D(GPD): 16-input/output port
Port E(GPE): 16-input/output port
Port F(GPF): 8-input/output port
Port G(GPG): 16-input/output port
Port H(GPH): 9-input/output port
Port J(GPJ): 13-input/output port
Port A(GPA): 25-output port
Port B(GPB): 11-input/out port
Port C(GPC): 16-input/output port
Port D(GPD): 16-input/output port
Port E(GPE): 16-input/output port
Port F(GPF): 8-input/output port
Port G(GPG): 16-input/output port
Port H(GPH): 9-input/output port
Port J(GPJ): 13-input/output port
二、GPIO寄存器
GPXCON 0x56000000 R/W Configures the pins of port A 0xffffff 选择引脚功能
GPXDAT 0x56000004 R/W The data register for port A Undef. 用于读写引脚,
GPXUP 0x56000018 R/W Pull-up disable register for port B 0x0 为1则无内部上拉电阻
Table 1-4. S3C2440A Special Registers (Sheet 11 of 14) (Continued)
Register Name Address Unit Read/Write Function
I/O port
Register Name Address Unit Read/Write Function
I/O port
GPBCON 0x56000010 Port B control
GPBDAT 0x56000014 Port B data
GPBUP 0x56000018 Pull-up control B
GPBDAT 0x56000014 Port B data
GPBUP 0x56000018 Pull-up control B
GPCCON 0x56000020 Port C control
GPCDAT 0x56000024 Port C data
GPCUP 0x56000028 Pull-up control C
GPCDAT 0x56000024 Port C data
GPCUP 0x56000028 Pull-up control C
GPDCON 0x56000030 Port D control
GPDDA1T 0x56000034 Port D data
GPDUP 0x56000038 Pull-up control D
GPECON 0x56000040 Port E control
GPEDAT 0x56000044 Port E data
GPEUP 0x56000048 Pull-up control E
GPDDA1T 0x56000034 Port D data
GPDUP 0x56000038 Pull-up control D
GPECON 0x56000040 Port E control
GPEDAT 0x56000044 Port E data
GPEUP 0x56000048 Pull-up control E
GPFCON 0x56000050 Port F control
GPFDAT 0x56000054 Port F data
GPFUP 0x56000058 Pull-up control F
GPFDAT 0x56000054 Port F data
GPFUP 0x56000058 Pull-up control F
GPGCON 0x56000060 Port G control
GPGDAT 0x56000064 Port G data
GPGUP 0x56000068 Pull-up control G
GPGDAT 0x56000064 Port G data
GPGUP 0x56000068 Pull-up control G
GPHCON 0x56000070 Port H control
GPHDAT 0x56000074 Port H data
GPHUP 0x56000078 Pull-up control H
GPHDAT 0x56000074 Port H data
GPHUP 0x56000078 Pull-up control H
GPJCON 0x560000D0 Port J control
GPJDAT 0x560000D4 Port J data
GPJUP 0x560000D8 Pull-up control J
GPJDAT 0x560000D4 Port J data
GPJUP 0x560000D8 Pull-up control J
三、GPIO LED和按键操作实例
硬件连接管脚图如下:
图1 按键 K1-6
图2 nLED_1-4
四、源程序
start.S //初始化代码
- .text //code section
- .global _start //global variable
- _start:
- LDR R0,=0X53000000 //WATCHDOG register address
- MOV R1,#0X00000000 //turn off watchdog
- STR R1,[R0]
- LDR SP,=1024*4 //set stack ,can't big 4KB,because in NAND Flash.
- bl main //call C function
- halt_loop:
- b halt_loop
led_on.c //main 函数
- /*
- GPBCON 0x56000010 Port B control
- GPBDAT 0x56000014 Port B data
- GPBUP 0x56000018 Pull-up control B
- LED1 GPB5 LED2 GPB6 LED3 GPB7 LED4 GPB8
- GPB8 [17:16] 00 = Input 01 = Output
- 10 = nXDREQ1 11 = Reserved
- GPB7 [15:14] 00 = Input 01 = Output
- 10 = nXDACK1 11 = Reserved
- GPB6 [13:12] 00 = Input 01 = Output
- 10 = nXBREQ 11 = reserved
- GPB5 [11:10] 00 = Input 01 = Output
- 10 = nXBACK 11 = reserved
- #define S3C24X0_GPIO_BASE 0x56000000
- GPGCON = 0000 0000 1000 0000 1010 1000 1000 0010=0x80a882
- GPG0 Input/output EinT8 – – K1
- GPG3 Input/output EinT11 nSS1 – K2
- GPG5 Input/output EinT13 SPIMISO1 – k3
- GPG6 Input/output EinT14 SPIMISO1 – k4
- GPG7 Input/output EinT15 SPICLK1 – k5
- GPG11 Input/output EinT19 TCLK1 – k6
- */
- #define GPBCON (*(volatile unsigned long *) 0x56000010)
- #define GPBDAT (*(volatile unsigned long *) 0x56000014)
- #define GPBUP (*(volatile unsigned long *) 0x56000018)
- #define GPGCON (*(volatile unsigned long *) 0x56000060)
- #define GPGDAT (*(volatile unsigned long *) 0x56000064)
- #define GPGUP (*(volatile unsigned long *) 0x56000068)
- #define GPX_up 0x00000000
- #define GPB5_out (1<<(5*2))
- #define GPB6_out (1<<(6*2))
- #define GPB7_out (1<<(7*2))
- #define GPB8_out (1<<(8*2))
- #define GPG0_in ~(3<<(0*2))
- #define GPG3_in ~(3<<(3*2))
- #define GPG5_in ~(3<<(5*2))
- #define GPG6_in ~(3<<(6*2))
- void leds_init()
- {
- GPBCON = (GPB5_out | GPB6_out | GPB7_out | GPB8_out);
- GPBUP = GPX_up;
- }
- void buttons_init()
- {
- GPGCON = (GPG0_in & GPG3_in & GPG5_in & GPG6_in);
- GPGUP = GPX_up;
- }
- int main()
- {
- unsigned long dwDat;
- leds_init();
- buttons_init;
- while (1)
- {
- dwDat=GPGDAT;
- if(dwDat & (1<<0))
- GPBDAT |=(1<<5);
- else
- GPBDAT &=~(1<<5);
- if(dwDat & (1<<3))
- GPBDAT |=(1<<6);
- else
- GPBDAT &=~(1<<6);
- if(dwDat & (1<<5))
- GPBDAT |=(1<<7);
- else
- GPBDAT &=~(1<<7);
- if(dwDat & (1<<6))
- GPBDAT |=(1<<8);
- else
- GPBDAT &=~(1<<8);
- }
- return 0;
- }
Makefile //Makefile 注意每个命令前加Tab键
- led_on.bin:start.S led_on.c
- arm-linux-gcc -g -c -o start.o start.S
- arm-linux-gcc -g -c -o led_on.o led_on.c
- arm-linux-ld -Ttext 0x00000000 -g start.o led_on.o -o led_on_elf
- arm-linux-objcopy -O binary -S led_on_elf led_on.bin
- arm-linux-objdump -D -b binary -m arm led_on_elf > led_on.dis
- clean:
- rm -f led_on_elf *.o led_on.dis led_on.bin
以下为能直接运行的二进制文件,下载到Nand Flash Black0 直接以Nand Flash运行。