s3c2440跑马灯实验2009-10-27 07:39首先了解下电路图
即是,四个灯的分别连接到ARM的GPB5,GPB6,GPB7,GPB8引脚上。
从该图可以看出,当GPB5~8的输出低电平时,对应led灯亮
以下是s3c2440的datasheet关于IO口的描述
PORT CONTROL DESCRIPTIONS
PORT CONFIGURATION REGISTER (GPACON-GPJCON)
In S3C2440A, most of the pins are multiplexed pins. So, It is determined which function is selected for each pins.
The PnCON(port control register) determines which function is used for each pin.
If PE0 – PE7 is used for the wakeup signal in power down mode, these ports must be configured in interrupt mode.
PORT DATA REGISTER (GPADAT-GPJDAT)
If Ports are configured as output ports, data can be written to the corresponding bit of PnDAT. If Ports are configured
as input ports, the data can be read from the corresponding bit of PnDAT.
PORT PULL-UP REGISTER (GPBUP-GPJUP)
The port pull-up register controls the pull-up resister enable/disable of each port group. When the corresponding bit is
0, the pull-up resister of the pin is enabled. When 1, the pull-up resister is disabled.
If the port pull-up register is enabled then the pull-up resisters work without pin’s functional setting(input, output,
DATAn, EINTn and etc)
PORT B控制寄存器的地址
各寄存器的具体配置在datasheet中有详细描述
GPxCON寄存器:
选择引脚的功能,GPBCON-GPJCON每两位控制一根引脚: 00表示输入,01表示输出,10表示特殊功能,11保留不用。
GPACON特殊,每一位控制一根引脚,共23根,某位为0时,为输出引脚,当某位1时,相应引脚为地址线或用于地址控制, 此时GPADTA无用。
一般的,GPACON设为全1,以便访问外部存储器件。
GPxDAT寄存器:
当引脚为输入时,读其对应位可知电平状态是高还是低。
当引脚为输出时, 写寄存器对应位则引脚输出高电平或低电平。
GPxUP寄存器:
某位为1时,相应引脚无内部上拉电阻,为0时,相应引脚使用内部上拉电阻 。
以下是程序部分(ADS1.2开发环境)
#define GPBCON (*(volatile unsigned *)0x56000010)
#define GPBDAT (*(volatile unsigned *)0x56000014)
#define GPBUP (*(volatile unsigned *)0x56000018)
int Main()
{
void delay(unsigned int x);
unsigned int ledtab[] = {0xEFF, 0xF7F, 0xFBF, 0xFDF};
int i;
GPBUP = 0xe1f; //设置与GPB5~8引脚内部上拉电阻
GPBCON &=0xfd57ff; //将GPB5~8引脚设置为输出
GPBCON |=0x015400;
//GPBDAT = 0xfff;
while(1)
{
for(i = 0; i<4; i++)
{
GPBDAT = ledtab[i];
delay(50);
}
}
return 0;
}
void delay(unsigned int x)
{
unsigned int i, k;
for(i = 0; i <= x; i++)
for(k = 0; k <= 0xfff; k++);
}
汇编初始C运行环境代码
IMPORT |Image$$RO$$Base| ; Base of ROM code
IMPORT |Image$$RO$$Limit| ; End of ROM code (=start of ROM data)
IMPORT |Image$$RW$$Base| ; Base of RAM to initialise
IMPORT |Image$$ZI$$Base| ; Base and limit of area
IMPORT |Image$$ZI$$Limit| ; to zero initialise
IMPORT Main
AREA INITS,CODE,READONLY
CODE32
ENTRY
LDR R0,=0X53000000
mov r1,#0x00000000
str r1,[r0]
ldr sp,=1024*3
b Main
END |