1、GPIO接口--s3c2440

一、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
 
二、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
GPACON   0x56000000     Port A control
GPADAT   0x56000004     Port A data
GPBCON   0x56000010     Port B control
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
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
GPFCON   0x56000050     Port F control
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
GPHCON   0x56000070     Port H control
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
 
三、GPIO LED和按键操作实例
  硬件连接管脚图如下:
 
                                图1 按键 K1-6
                       
                           图2 nLED_1-4
四、源程序
    start.S  //初始化代码
  1. .text    //code section
  2. .global _start   //global variable
  3. _start:
  4.   LDR R0,=0X53000000 //WATCHDOG register address
  5. MOV R1,#0X00000000 //turn off watchdog
  6. STR R1,[R0]      
  7. LDR SP,=1024*4 //set stack ,can't big 4KB,because in NAND Flash.
  8. bl main        //call C function
  9. halt_loop:
  10.    b halt_loop
 
  led_on.c  //main 函数
  1. /*

  2. GPBCON 0x56000010 Port B control
  3. GPBDAT 0x56000014 Port B data
  4. GPBUP 0x56000018 Pull-up control B
  5. LED1 GPB5 LED2 GPB6 LED3 GPB7 LED4 GPB8
  6. GPB8 [17:16] 00 = Input 01 = Output
  7.              10 = nXDREQ1 11 = Reserved
  8. GPB7 [15:14] 00 = Input 01 = Output
  9.              10 = nXDACK1 11 = Reserved
  10. GPB6 [13:12] 00 = Input 01 = Output
  11.              10 = nXBREQ 11 = reserved
  12. GPB5 [11:10] 00 = Input 01 = Output
  13.              10 = nXBACK 11 = reserved
  14. #define S3C24X0_GPIO_BASE        0x56000000
  15. GPGCON = 0000 0000 1000 0000 1010 1000 1000 0010=0x80a882
  16. GPG0 Input/output EinT8 – – K1
  17. GPG3 Input/output EinT11 nSS1 –     K2
  18. GPG5 Input/output EinT13 SPIMISO1 – k3
  19. GPG6 Input/output EinT14 SPIMISO1 – k4
  20. GPG7 Input/output EinT15 SPICLK1 – k5
  21. GPG11 Input/output EinT19 TCLK1 – k6
  22. */
  23. #define GPBCON (*(volatile unsigned long *) 0x56000010)
  24. #define GPBDAT (*(volatile unsigned long *) 0x56000014)
  25. #define GPBUP (*(volatile unsigned long *) 0x56000018)
  26. #define GPGCON (*(volatile unsigned long *) 0x56000060)
  27. #define GPGDAT (*(volatile unsigned long *) 0x56000064)
  28. #define GPGUP (*(volatile unsigned long *) 0x56000068)
  29. #define GPX_up 0x00000000
  30. #define GPB5_out (1<<(5*2))
  31. #define GPB6_out (1<<(6*2))
  32. #define GPB7_out (1<<(7*2))
  33. #define GPB8_out (1<<(8*2))
  34. #define GPG0_in ~(3<<(0*2))
  35. #define GPG3_in ~(3<<(3*2))
  36. #define GPG5_in ~(3<<(5*2))
  37. #define GPG6_in ~(3<<(6*2))
  38. void leds_init()
  39. {
  40.     GPBCON = (GPB5_out | GPB6_out | GPB7_out | GPB8_out);
  41.     GPBUP     = GPX_up;
  42. }
  43. void buttons_init()
  44. {
  45.     GPGCON = (GPG0_in & GPG3_in & GPG5_in & GPG6_in);
  46.     GPGUP     = GPX_up;
  47. }
  48. int main()
  49. {
  50.     unsigned long dwDat;
  51.     leds_init();
  52.     buttons_init;
  53.     while (1)
  54.     {
  55.         dwDat=GPGDAT;
  56.         if(dwDat & (1<<0))
  57.             GPBDAT |=(1<<5);
  58.         else
  59.             GPBDAT &=~(1<<5);    
  60.         if(dwDat & (1<<3))
  61.             GPBDAT |=(1<<6);    
  62.         else
  63.             GPBDAT &=~(1<<6);    
  64.         if(dwDat & (1<<5))
  65.             GPBDAT |=(1<<7);
  66.         else
  67.             GPBDAT &=~(1<<7);    
  68.         if(dwDat & (1<<6))
  69.             GPBDAT |=(1<<8);    
  70.         else
  71.             GPBDAT &=~(1<<8);                
  72.     }
  73.     return 0;
  74. }
  Makefile  //Makefile 注意每个命令前加Tab键
  1. led_on.bin:start.S led_on.c
  2.   arm-linux-gcc -g -c -o start.o start.S
  3.   arm-linux-gcc -g -c -o led_on.o led_on.c
  4.   arm-linux-ld -Ttext 0x00000000 -g start.o led_on.o -o led_on_elf
  5.   arm-linux-objcopy -O binary -S led_on_elf led_on.bin
  6.   arm-linux-objdump -D -b binary -m arm led_on_elf > led_on.dis
  7. clean:
  8.   rm -f led_on_elf *.o led_on.dis led_on.bin
以下为能直接运行的二进制文件,下载到Nand Flash Black0 直接以Nand Flash运行。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值