外設(shè)一個一個學(xué) for ARM_first
根據(jù)s5pc100提供的原理圖可以看到
使用的控制寄存器為GPG3
查閱相關(guān)芯片手冊:
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能引導(dǎo)四中總線模式、即(SPI,I2S,PCM,SPDIF).GPG3能引導(dǎo)八種。
進入GPG3的配置寄存器:
GPG3 Configuration (GPG3CON, R/W, Address = 0xE030_01C0)
通過查看可知、input= 0表示輸入模式。
而output =1則表示輸出模式,這里需要調(diào)到輸出模式
那么接下來便可以去利用配置寄存器初始化并且去控制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
由上面的地址可以看見、它們在一個連續(xù)的內(nèi)存地址中,所以使用結(jié)構(gòu)體定義了這些連續(xù)地址的變量int正好是4個字節(jié)。
下面在寫一個c文件
#include"led.h"
intmain()
{
GPG3.GPG3CON= (~(0xffff)&GPG3.GPG3CON) | (0x1111);
//配置寄存器表示為output先清0,在:或上0x1111其實就是0001 0001 0001 0001
inti;
while(1)//讓程序死循環(huán),不讓程序結(jié)束
{
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++);
}
}
關(guān)于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");
評論