博主以循循渐进的方式理解
总结如下:
GPxCON 配置引脚功能 一般把引脚配置为输出模式进行对外设的控制
GPxDAT 设置引脚高低电平 一般设置为高/低电平
解释如下:
OVERVIEW:
总览
S3C2451 has 174 multi-functional input/output port pins and there are 12 ports as shown below:
S3C2451具有174个多功能输入/输出端口引脚,如下所示12个端口
• Port B(GPB) : 11-input/output port//端口B 下的0---27这28个引脚既有输出功能又有输入功能
......
• Port L(GPL) : 15-input/output port
• Port M(GPM) : 2-input port
Each port can be easily configured by software to meet various system configurations and design requirements.
每个端口都可以通过软件轻松地配置,以满足不同的系统配置和设计要求
You have to define which function of each pin is used before starting the main program. If a pin is not used for
multiplexed functions, the pin can be configured as I/O ports.
在启动主程序之前,必须定义每个pin的功能。如果该引脚没被用作多路复用,则该引脚可以配置为I / O端口
那么问题来了,如何配置引脚功能?
2 PORT CONTROL DESCRIPTIONS:
端口控制描述
2.1 PORT CONFIGURATION REGISTER (GPACON-GPMCON)
端口配置寄存器(GPACON-GPMCON)
In S3C2451, most of the pins are multiplexed pins. So, It is determined which function is selected for each pins.
The GPxCON(port control register) determines which function is used for each pin.
GPxCON(端口控制寄存器)决定哪个引脚使用什么功能。
2.2 PORT DATA REGISTER (GPADAT-GPMDAT)
端口数据寄存器(GPADAT-GPMDAT)
If ports are configured as output ports, data can be written to the corresponding bit of GPxDAT. If Ports are
configured as input ports, the data can be read from the corresponding bit of GPxDAT.
如果将端口配置为输出端口,则S3C2451可以将数据写入相应的GPxDAT中。如果端口是
那么问题来了,何为输入何为输出?
引脚配置为输入是指处理器通过寄存器采集引脚状态 比如,通过GPIOB的某个引脚采集按键Key1是否按下
引脚配置为输出是指处理器通过配置寄存器来给引脚赋值 比如,通过配置GPIOB的某个引脚来控制LED灯的亮灭
回过头来,看GPxCON 、GPxDAT的配置方法(暂且只谈这俩,因为常用)
以GPB为例
3.2 PORT B CONTROL REGISTERS (GPBCON, GPBDAT, GPBUDP, GPBSEL)
Register AddressR/W Description Reset Value
GPBCON 0x56000010R/W Configures the pins of port B(配置端口B的引脚) 0x0
GPBDAT 0x56000014R/W The data register for port B (用于端口B的数据寄存器)0x0
GPBUDP 0x56000018 R/W Pull-up/down control register for port B0x00154555
GPBSEL 0x5600001cR/W Selects the function of port B 0x1
GPBCON Bit Description
Reserved [31:22] Reserved
GPB10 [21:20]//两bit控制一个引脚00 = Input01 = Output
10 = nXDREQ[0] 11 = XDREQ[0]
GPB9 [19:18] 00 = Input 01 = Output
10 = nXDACK[0] 11 = XDACK[0]
GPB8 [17:16] 00 = Input 01 = Output
10 = nXDREQ[1] 11 = XDREQ[1]
GPB7 [15:14] 00 = Input 01 = Output
10 = nXDACK[1] 11 = XDACK[1]
GPB6 [13:12] 00 = Input 01 = Output
10 = nXBREQ 11 = XBREQ
GPB5 [11:10] 00 = Input 01 = Output
10 = nXBACK 11 = XBACK
GPB4//特殊 [9:8] 00 = Input 01 = Output
10 = TCLK 11 = reserved
GPB3 [7:6] 00 = Input 01 = Output
10 = TOUT3 11 = reserved
GPB2 [5:4] 00 = Input 01 = Output
10 = TOUT2 11 = reserved
GPB1 [3:2] 00 = Input 01 = Output
10 = TOUT1 11 = reserved
GPB0 [1:0] 00 = Input 01 = Output
10 = TOUT0 11 = reserved
GPBDAT Bit Description
Reserved(预留位) [31:11] Reserved(未定义的值)
GPBDAT [10:0] [10:0] When the port is configured as input port, the corresponding bit is the pin
state. When the port is configured as output port, the pin state is the same
as the corresponding bit. When the port is configured as functional pin, the
undefined value will be read.
当端口被配置为输入端口时,相应的位就是引脚的
//至此原理部分理解完了 文章太长 所以代码部分贴到了我的资源里。为方便,S3C2451的手册和原理图一并贴过去。