📄 common.c
字号:
/************************************************************/
/* PROJECT NAME: GPIO */
/* Project: LPC2129 Training course */
/* Engineer: Y.Stalin stalin@nstlindia.com */
/* Filename: common.c */
/* Language: C */
/* Compiler: Keil ARM GCC */
/* Assembler: */
/* */
/************************************************************/
/* COPYRIGHT: NSTL 2008 */
/* LICENSE: PROPRIETORY */
/************************************************************/
/* Function: */
/* */
/* Example */
/* */
/* Demonstrates Use of the LPC2129 GPIO */
/* */
/* Oscillator frequency 12.000 Mhz */
/* Target board NSTL NST2100 */
/************************************************************/
#include <LPC214X.H>
#include"common.h"
void delay(int count)
{
int i,j;
int count1 = DELAY_COUNT;
for (i=0;i<count1;i++)
{
for (j=0;j<count;j++);
}
}
void delaym(int count)
{
int i,j;
for (i=0;i<count;i++)
for (j=0;j<11;j++)
;
}
unsigned char* getBCD(unsigned int hexData)
{
unsigned int i,q,r,temp = 10000;
static unsigned char bcdAry[6];
q = hexData;
r = q;
for(i=0;i<5;i++)
{
q = q / temp;
r = r % temp;
bcdAry[i] = q+0x30;
q = r;
temp = temp / 10;
}
bcdAry[i] = NUL;
return bcdAry;
}
unsigned char* getBCDP(unsigned int hexData,unsigned int nod)
{
unsigned int i,q,r,temp = 10000;
static unsigned char bcdAry[6];
q = hexData;
r = q;
for(i=0;i<5;i++)
{
q = q / temp;
r = r % temp;
bcdAry[i] = q+0x30;
q = r;
temp = temp / 10;
}
bcdAry[i] = NUL;
for(i=0;bcdAry[i]!= NUL;i++)
bcdAry[i] = bcdAry[i+5-nod];
bcdAry[i] = NUL;
return bcdAry;
}
unsigned char* getASCII(unsigned int hexData)
{
static unsigned char tempAry[3];
int i,temp;
for(i=0;i<2;i++)
{
if(i==0)
temp = (hexData & 0xF0) >> 4;
else
temp = hexData & 0x0F;
if(temp <= 0x09)
tempAry[i] = temp + 0x30;
else
tempAry[i] = temp + 0x37;
}
tempAry[i] = NUL;
return tempAry;
}
void setClock(void)
{
unsigned int M,P = 2;
M = F_CLK/F_XTAL;
PLL0CFG =(P << 4)|(M-1);
PLL0FEED = 0xAA;
PLL0FEED = 0x55;
if(F_PCLK == (F_CLK / 4))
VPBDIV = 0x00;
else if(F_PCLK == F_CLK)
VPBDIV = 0x01;
else if(F_PCLK == (F_CLK / 2))
VPBDIV = 0x02;
else
VPBDIV = 0x01;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -