裸机 TEST2

//===================================================================
// File Name : 2410lib.c
// Function  : S3C2410 PLL,Uart, LED, Port Init
// Program   : Shin, On Pil (SOP)
// Date      : May 14, 2002
// Version   : 0.0
// History
//   0.0 : Programming start (February 20,2002) -> SOP
//===================================================================




#include "option.h"
#include "2440addr.h"
#include "2440lib.h"




void ClearPending(int bit)
{
rSRCPND = bit;
rINTPND = bit;
}




 
 void ClearSubPending(int bit)
{
rSUBSRCPND = bit;
}   
 
//========================*[ MPLL ]==============================*
void SetSysFclk(int val)
{
rMPLLCON = val;
}


void ChangeMPllValue(int mdiv,int pdiv,int sdiv)
{
    rMPLLCON = (mdiv<<12) | (pdiv<<4) | sdiv;
}






// Modified for 2440.
void ChangeClockDivider(int hdivn_val,int pdivn_val)
{
int hdivn=2, pdivn=0;

     // hdivn_val (FCLK:HCLK)ratio hdivn
     // 11           1:1       (0)
     // 12           1:2       (1)
     // 13           1:3       (3) 
     // 14           1:4       (2)
     // pdivn_val (HCLK:PCLK)ratio pdivn
     // 11           1:1       (0)
     // 12           1:2       (1)
switch(hdivn_val) 
{
case 11: hdivn=0; break;
case 12: hdivn=1; break;
case 13:
case 16: hdivn=3; break;
case 14: 
case 18: hdivn=2; break;
}

switch(pdivn_val)
{
case 11: pdivn=0; break;
case 12: pdivn=1; break;
}

//Uart_Printf("Clock division change [hdiv:%x, pdiv:%x]\n", hdivn, pdivn);
rCLKDIVN = (hdivn<<1) | pdivn;
//Uart_Printf("rCLKDIVN:%x]\n", rCLKDIVN);


switch(hdivn_val) 
{
case 16: // when 1, HCLK=FCLK/6.
// rCAMDIVN = (rCAMDIVN & ~(3<<8)) | (1<<8); 
break; 
case 18: // when 1, HCLK=FCLK/8.
// rCAMDIVN = (rCAMDIVN & ~(3<<8)) | (1<<9); 
break;
}
}


//**************************[ UPLL ]*******************************
void ChangeUPllValue(int mdiv,int pdiv,int sdiv)
{
    rUPLLCON = (mdiv<<12) | (pdiv<<4) | sdiv;
}







//=========================================================================
//  工程名称: Demo2440_GPIO_key13  
//  组成文件: key_in.c
//  功能描述: 实现三个独立按键,练习GPIO的输入功能
//  硬件连接: GPG2~GPG4与key1,key2,key3相连
//=========================================================================




#include "2440addr.h"           //声明S3C2440的寄存器及其常用变量
#include "2440lib.h"




void  delay(unsigned long dly)
{
for(; dly > 0; dly--);
}


int Main(void)
{
unsigned int uikey;
ChangeMPllValue(0x5c,1,1); //PCLK = 400M
ChangeClockDivider(14,12); //HCLK = 100M , PCLK = 50M


rGPFCON &= ~((0x3<<2*2) | (0x3<<3*2) | (0x3<<4*2));    //GPF2,3,4设置为输入
rGPFUP &= ~((0x1<<2*1) | (0x1<<3*1) | (0x1<<4*1));         //使能GPF2,3,4上拉电阻  


rGPGCON &= ~((0x3<<0*2) | (0x3<<1*2) | (0x3<<2*2));    //GPG0,1,2设置为输出  
rGPGCON |= ((0x1<<0*2) | (0x1<<1*2)|(0x1<<2*2));         
    
rGPGUP  &= ~((0x01<<0)|(0x01<<1)|(0x01<<2));               //使能GPG0,1,2上拉电阻



while(1)
{

#if 1
uikey = rGPFDAT;
uikey = ~(uikey>>2);
rGPGDAT = uikey;
#else

uikey = rGPFDAT;
uikey = ((uikey>>2)&0x07);

switch(uikey)
{
case 0x06:
case 0x05:
case 0x03:
rGPGDAT = ~uikey;
break;
}
#endif


}
}



















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值