外设一个一个学 for ARM_first
根据s5pc100提供的原理图可以看到
使用的控制寄存器为GPG3
查阅相关芯片手册:
GPG0,1,2,3: 25 in/out pin –3xMMC channel (Channel 0 supports 4-bit and 8-bit mode, but channel 1, channel 2 supports on
意思为GPG1GPG2能引导四中总线模式、即(SPI,I2S,PCM,SPDIF).GPG3能引导八种。
进入GPG3的配置寄存器:
GPG3 Configuration (GPG3CON, R/W, Address = 0xE030_01C0)
通过查看可知、input= 0表示输入模式。
而output =1则表示输出模式,这里需要调到输出模式
那么接下来便可以去利用配置寄存器初始化并且去控制LED了。
先来写一个头文件。
Led.h
#ifndef__LED_H__
#define__LED_H__
/* GPG3 */
typedefstruct{
unsignedintGPG3CON; //0xE030_01C0
unsignedintGPG3DAT; //0xE030_01C4
unsignedintGPG3PULL; //0xE030_01C8
unsignedintGPG3DRV; //0xE030_01CC
unsignedintGPG3PDNCON; //0xE030_01D0
unsignedintGPG3PDNPULL; //0xE030_01D4
}gpg3;
#defineGPG3 (* (volatilegpg3 * )0xE03001C0 )
#endif
由上面的地址可以看见、它们在一个连续的内存地址中,所以使用结构体定义了这些连续地址的变量int正好是4个字节。
下面在写一个c文件
#include"led.h"
intmain()
{
GPG3.GPG3CON= (~(0xffff)&GPG3.GPG3CON) | (0x1111);
//配置寄存器表示为output先清0,在:或上0x1111其实就是0001 0001 0001 0001
inti;
while(1)//让程序死循环,不让程序结束
{
GPG3.GPG3DAT= 0x2; //第一个灯高电平LED1接的是GPG3_1 0000 0010
for(i = 0; i <= 1000000; i++);
GPG3.GPG3DAT= 0x4; 0000 0100
for(i = 0; i <= 1000000; i++);
GPG3.GPG3DAT= 0x8; 1000
for(i = 0; i <= 1000000; i++);
GPG3.GPG3DAT= 0x1;
for(i = 0; i <= 1000000; i++);
}
}
关于DAT[0~7]寄存器(芯片手册是这样描述的:If the bit is configured as input, it represents the pin state.If the bit
is configured as output, the pin state is the same as the value of
the bit.If the port is configured as functional pin, an undefined
value is read.包含了所有的PAD CONTORL)
上述GPG3配置寄存器为output.因此If the bit
is configured as output, the pin state is the same as the value of
the bit.
也就是一个DAT位控制一个灯(可以这么理解(高电平给为灯亮、低电平为灯灭))
So … over…
/*-------------*/
printf("keven");
外设ARMfirs 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)