您的位置 首页 主动

时钟装备的仿真

在ARM-MDK开发环境中,提供了很好用的时钟配置仿真模式,为学习LPC1114的时钟配置提供了方便,下面就来详细讨论一下它的用法。要进行仿真,…

在ARM-MDK开发环境中,供给了很好用的时钟装备仿真方式,为学习LPC1114的时钟装备供给了便利,下面就来具体评论一下它的用法。

要进行仿真,有必要先把程序进行编译,正确无误后才干进入到仿真方式。为此,先给出主函数的内容,如下。

void SystemInit(void)

{

SysCLK_config();//调用时钟装备函数

}

int main(void)

{

SystemInit ();//调用体系初始化函数

while(1)

{

;//空循环

}

}

在上述程序中能够看出,主函数的写法和一般单片机开发的没有什么两样,都有一个死循环,因为这儿只做时钟装备的仿真,所以在调用时钟装备函数后就进行一个空循环。只需三点要特别注意一下:一是这儿的main函数有必要是整型(int型)的;二是在程序完毕的最终一行要有一个换行(即要回一下车),不然会有正告呈现;三是在项目主动加载的发动文件中规则,程序中有必要要有一个体系初始化的函数(SystemInit),不然程序不能编译链接。所以在上述程序中尽管只调用一个时钟装备函数,但仍是要把它放入到体系初始化函数中去供主函数调用。

可是,把上述函数及前面的时钟装备函数写到主程序后,仍是编译不过的,会报两条过错,说“uint8_t”和“LPC_SYSCON”没有界说。这是因为程序没有包括一些特定的头文件,在这些头文件内才有相关变量的声明。要程序顺畅编译经过,有必要要把这些头文件包括进来。可是,因为开发LPC1114所需求的头文件许多,且有些头文件还有互相的依靠联系,关于不同的开发环境,界说的称号也不一致,因而,为了减小学习的挫折感,先快速的把咱们的第一个程序运转起来,下面用不包括头文件的方法,把程序所用到的内容全部都列出来,这样只需把下面的程序复制到开发环境中,就能够顺畅经过编译了。

程序代码如下:

#define__IOvolatile

#define__Ovolatile

#define__Ivolatile const

typedef unsignedchar uint8_t;

typedef unsigned shortint uint16_t;

typedef unsignedint uint32_t;

typedef struct
{
__IO uint32_t SYSMEMREMAP; /*!< Offset: 0x000 (R/W) System memory remap Register */
__IO uint32_t PRESETCTRL; /*!< Offset: 0x004 (R/W) Peripheral reset control Register */
__IO uint32_t SYSPLLCTRL; /*!< Offset: 0x008 (R/W) System PLL control Register */
__I uint32_t SYSPLLSTAT; /*!< Offset: 0x00C (R/ ) System PLL status Register */
uint32_t RESERVED0[4];

__IO uint32_t SYSOSCCTRL; /*!< Offset: 0x020 (R/W) System oscillator control Register */
__IO uint32_t WDTOSCCTRL; /*!< Offset: 0x024 (R/W) Watchdog oscillator control Register */
__IO uint32_t IRCCTRL; /*!< Offset: 0x028 (R/W) IRC control Register */
uint32_t RESERVED1[1];
__I uint32_t SYSRSTSTAT; /*!< Offset: 0x030 (R/ ) System reset status Register */
uint32_t RESERVED2[3];
__IO uint32_t SYSPLLCLKSEL; /*!< Offset: 0x040 (R/W) System PLL clock source select Register */
__IO uint32_t SYSPLLCLKUEN; /*!< Offset: 0x044 (R/W) System PLL clock source update enable Register */
uint32_t RESERVED3[10];

__IO uint32_t MAINCLKSEL; /*!< Offset: 0x070 (R/W) Main clock source select Register */
__IO uint32_t MAINCLKUEN; /*!< Offset: 0x074 (R/W) Main clock source update enable Register */
__IO uint32_t SYSAHBCLKDIV; /*!< Offset: 0x078 (R/W) System AHB clock divider Register */
uint32_t RESERVED4[1];

__IO uint32_t SYSAHBCLKCTRL; /*!< Offset: 0x080 (R/W) System AHB clock control Register */
uint32_t RESERVED5[4];
__IO uint32_t SSP0CLKDIV; /*!< Offset: 0x094 (R/W) SSP0 clock divider Register */
__IO uint32_t UARTCLKDIV; /*!< Offset: 0x098 (R/W) UART clock divider Register */
__IO uint32_t SSP1CLKDIV; /*!< Offset: 0x09C (R/W) SSP1 clock divider Register */
uint32_t RESERVED6[1];
uint32_t RESERVED7[11];

__IO uint32_t WDTCLKSEL; /*!< Offset: 0x0D0 (R/W) WDT clock source select Register */
__IO uint32_t WDTCLKUEN; /*!< Offset: 0x0D4 (R/W) WDT clock source update enable Register */
__IO uint32_t WDTCLKDIV; /*!< Offset: 0x0D8 (R/W) WDT clock divider Register */
uint32_t RESERVED9[1];

__IO uint32_t CLKOUTCLKSEL; /*!< Offset: 0x0E0 (R/W) CLKOUT clock source select Register */
__IO uint32_t CLKOUTUEN; /*!< Offset: 0x0E4 (R/W) CLKOUT clock source update enable Register */
__IO uint32_t CLKOUTDIV; /*!< Offset: 0x0E8 (R/W) CLKOUT clock divider Register */
uint32_t RESERVED10[5];

__I uint32_t PIOPORCAP0; /*!< Offset: 0x100 (R/ ) POR captured PIO status 0 Register */
__I uint32_t PIOPORCAP1; /*!< Offset: 0x104 (R/ ) POR captured PIO status 1 Register */
uint32_t RESERVED11[11];
uint32_t RESERVED12[7];
__IO uint32_t BODCTRL; /*!< Offset: 0x150 (R/W) BOD control Register */
__IO uint32_t SYSTCKCAL; /*!< Offset: 0x154 (R/W) System tick counter calibration Register */
uint32_t RESERVED13[1];
uint32_t RESERVED14[5];
uint32_t RESERVED15[2];
uint32_t RESERVED16[34];

__IO uint32_t STARTAPRP0; /*!< Offset: 0x200 (R/W) Start logic edge control Register 0 */
__IO uint32_t STARTERP0; /*!< Offset: 0x204 (R/W) Start logic signal enable Register 0 */
__O uint32_t STARTRSRP0CLR; /*!< Offset: 0x208 ( /W) Start logic reset Register 0 */
__I uint32_t STARTSRP0; /*!< Offset: 0x20C (R/ ) Start logic status Register 0 */
__IO uint32_t STARTAPRP1; /*!< Offset: 0x210 (R/W) Start logic edge control Register 1 (LPC11UXX only) */
__IO uint32_t STARTERP1; /*!< Offset: 0x214 (R/W) Start logic signal enable Register 1 (LPC11UXX only) */
__O uint32_t STARTRSRP1CLR; /*!< Offset: 0x218 ( /W) Start logic reset Register 1 (LPC11UXX only) */
__I uint32_t STARTSRP1; /*!< Offset: 0x21C (R/ ) Start logic status Register 1 (LPC11UXX only) */
uint32_t RESERVED17[4];

__IO uint32_t PDSLEEPCFG; /*!< Offset: 0x230 (R/W) Power-down states in Deep-sleep mode Register */
__IO uint32_t PDAWAKECFG; /*!< Offset: 0x234 (R/W) Power-down states after wake-up from Deep-sleep mode Register*/
__IO uint32_t PDRUNCFG; /*!< Offset: 0x238 (R/W) Power-down configuration Register*/
uint32_t RESERVED18[110];
__I uint32_t DEVICE_ID; /*!< Offset: 0x3F4 (R/ ) Device ID Register */
} LPC_SYSCON_TypeDef;

#define LPC_APB0_BASE(0x40000000UL)

#define LPC_AHB_BASE(0x50000000UL)

#define LPC_SYSCON_BASE(LPC_APB0_BASE + 0x48000)

#define LPC_SYSCON((LPC_SYSCON_TypeDef *) LPC_SYSCON_BASE)

//************************************************************************************************

void SysCLK_config(void)

{

uint8_t i;

LPC_SYSCON->PDRUNCFG &= ~(1 << 5);//给体系振动器上电

LPC_SYSCON->SYSOSCCTRL = 0x00000000;//体系振动器未旁路,1~12MHz输入

for (i = 0; i < 200; i++) __nop();//延时等候振动器安稳

LPC_SYSCON->SYSPLLCLKSEL = 0x00000001;//PLL输入挑选外部晶体振动

LPC_SYSCON->SYSPLLCLKUEN = 0x00;

LPC_SYSCON->SYSPLLCLKUEN = 0x01;//先写0后写1更新时钟源

while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01));//等候更新完结

LPC_SYSCON->SYSPLLCTRL = 0x00000023;//M=4、P=2,倍频后的时钟为48MHz

LPC_SYSCON->PDRUNCFG &= ~(1 << 7);//给PLL上电

while (!(LPC_SYSCON->SYSPLLSTAT & 0x01));//等候PLL确定

LPC_SYSCON->MAINCLKSEL = 0x00000003;//主时钟挑选PLL倍频后的时钟

LPC_SYSCON->MAINCLKUEN = 0x00;

LPC_SYSCON->MAINCLKUEN = 0x01;//先写0后写1更新时钟源

while (!(LPC_SYSCON->MAINCLKUEN & 0x01));//等候更新完结

LPC_SYSCON->SYSAHBCLKDIV = 0x00000001;//AHB为1分频,AHB时钟为48MHz

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);//使能GPIO时钟

}

void SystemInit(void)

{

SysCLK_config();

}

int main(void)

{

SystemInit ();//调用时钟装备函数

while(1)

{

;//空循环

}

}

(不要忘掉最终一行有一个强制换行)

从上面能够看到,变量的声明都是以结构体的方式呈现的,较为杂乱,现在先不去评论它。先把上述程序编译链接(点击工具条上的“Rebuild”按钮)无误后,点击工具条上的“Start/Stop Debug Session”按钮(或按Ctrl+F5)进入到调试方式。点击菜单Peripherals->Clocking & Power Control->Clock Generation Schematic,将会呈现一个显现时钟结构的对话框,如下图所示。

从图中能够清楚地看出装备后各时钟的分配情况(假如时钟不对,可能是没有运转程序,只需点击工具条上的“Run”按钮(或直接按F5)就能够了),十分直观。我们还可对照前面的程序,自行更改相关内容,再仿真看看改动,以加深对时钟装备的了解。要更改仿真中的外部晶振的值可点击菜单Peripherals->Clocking & Power Control->System Oscillator Control进行更改,要更改内部RC振动的值可点击菜单Peripherals->Clocking & Power Control->Internal Oscillator Control进行更改,要更改看门狗振动的值可点击菜单Peripherals->Clocking & Power Control->Watchdog Oscillator Control进行更改。乃至你还能够看到在设置过错(如把PLL倍频后的时钟设置了超越50MHz)的情况下,主时钟会主动转到默许的12MHz内部RC振动中去履行,真是十分了不得。

除了仿真以外,LPC1114还供给了一个时钟输出端口CLKOUT,它被复用在P0.1引脚,能够经过程序控制它来输出内部RC振动时钟、体系振动器时钟(外部晶振)、看门狗振动时钟和主时钟。

下面就给出一个CLKOUT引脚输出时钟的函数,如下:

void CLKOUT_EN(uint8_t CLKOUT_DIV)

{

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16);//使能IOCON时钟

LPC_IOCON->PIO0_1=0XD1;//把P0.1设置为CLKOUT引脚

LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<16);//制止IOCON时钟

LPC_SYSCON->CLKOUTDIV = CLKOUT_DIV;//输出分频为48/ CLKOUT_DIV

LPC_SYSCON->CLKOUTCLKSEL= 0X00000003;//CLKOUT时钟挑选主时钟

LPC_SYSCON->CLKOUTUEN =0X00;

LPC_SYSCON->CLKOUTUEN =0X01;//先写0后写1更新时钟源

while (!(LPC_SYSCON->CLKOUTUEN & 0x01));//等候更新完结

}

假如运用的是48MHz的主时钟,分频系数CLKOUT_DIV也取48,则该函数履行完后,LPC1114的P0.1脚就会有1MHz的脉冲输出,可经过示波器来进行调查。

在上述程序中能够看出,要改动一个具有复用的引脚功用时,有必要先翻开IOCON的时钟,不然装备不收效!而在装备完结后,要及时封闭IOCON时钟,以降低功耗。关于IOCON的装备将会在后边评论GPIO时进行具体评论,这儿先不赘述。下面给出的是“CLKOUT时钟源挑选寄存器(CLKOUTCLKSEL)”的位结构。

符号

描绘

复位值

1∶0

SEL

(CLKOUT时钟源)

00

IRC振动器

0

01

体系振动器

10

看门狗振动器

11

主时钟

31∶2

保存

0

试验时可根据上表来改动CLKOUTCLKSEL的值,然后调查不同的时钟频率输出。

因为在CLKOUT函数中加入了一些新的寄存器(比方IOCON、GPIO等),所以程序有必要在头文件中把相关的声明包括进来,才干正确编译经过。这儿同前面相同,为了便利,运用不包括头文件的方式来书写程序,下面给出其全部内容。

#define__IOvolatile

#define__Ovolatile

#define__Ivolatile const

typedef unsignedchar uint8_t;

typedef unsigned shortint uint16_t;

typedef unsignedint uint32_t;

typedef struct
{
__IO uint32_t SYSMEMREMAP; /*!< Offset: 0x000 (R/W) System memory remap Register */
__IO uint32_t PRESETCTRL; /*!< Offset: 0x004 (R/W) Peripheral reset control Register */
__IO uint32_t SYSPLLCTRL; /*!< Offset: 0x008 (R/W) System PLL control Register */
__I uint32_t SYSPLLSTAT; /*!< Offset: 0x00C (R/ ) System PLL status Register */
uint32_t RESERVED0[4];

__IO uint32_t SYSOSCCTRL; /*!< Offset: 0x020 (R/W) System oscillator control Register */
__IO uint32_t WDTOSCCTRL; /*!< Offset: 0x024 (R/W) Watchdog oscillator control Register */
__IO uint32_t IRCCTRL; /*!< Offset: 0x028 (R/W) IRC control Register */
uint32_t RESERVED1[1];
__I uint32_t SYSRSTSTAT; /*!< Offset: 0x030 (R/ ) System reset status Register */
uint32_t RESERVED2[3];
__IO uint32_t SYSPLLCLKSEL; /*!< Offset: 0x040 (R/W) System PLL clock source select Register */
__IO uint32_t SYSPLLCLKUEN; /*!< Offset: 0x044 (R/W) System PLL clock source update enable Register */
uint32_t RESERVED3[10];

__IO uint32_t MAINCLKSEL; /*!< Offset: 0x070 (R/W) Main clock source select Register */
__IO uint32_t MAINCLKUEN; /*!< Offset: 0x074 (R/W) Main clock source update enable Register */
__IO uint32_t SYSAHBCLKDIV; /*!< Offset: 0x078 (R/W) System AHB clock divider Register */
uint32_t RESERVED4[1];

__IO uint32_t SYSAHBCLKCTRL; /*!< Offset: 0x080 (R/W) System AHB clock control Register */
uint32_t RESERVED5[4];
__IO uint32_t SSP0CLKDIV; /*!< Offset: 0x094 (R/W) SSP0 clock divider Register */
__IO uint32_t UARTCLKDIV; /*!< Offset: 0x098 (R/W) UART clock divider Register */
__IO uint32_t SSP1CLKDIV; /*!< Offset: 0x09C (R/W) SSP1 clock divider Register */
uint32_t RESERVED6[1];
uint32_t RESERVED7[11];

__IO uint32_t WDTCLKSEL; /*!< Offset: 0x0D0 (R/W) WDT clock source select Register */
__IO uint32_t WDTCLKUEN; /*!< Offset: 0x0D4 (R/W) WDT clock source update enable Register */
__IO uint32_t WDTCLKDIV; /*!< Offset: 0x0D8 (R/W) WDT clock divider Register */
uint32_t RESERVED9[1];

__IO uint32_t CLKOUTCLKSEL; /*!< Offset: 0x0E0 (R/W) CLKOUT clock source select Register */
__IO uint32_t CLKOUTUEN; /*!< Offset: 0x0E4 (R/W) CLKOUT clock source update enable Register */
__IO uint32_t CLKOUTDIV; /*!< Offset: 0x0E8 (R/W) CLKOUT clock divider Register */
uint32_t RESERVED10[5];

__I uint32_t PIOPORCAP0; /*!< Offset: 0x100 (R/ ) POR captured PIO status 0 Register */
__I uint32_t PIOPORCAP1; /*!< Offset: 0x104 (R/ ) POR captured PIO status 1 Register */
uint32_t RESERVED11[11];
uint32_t RESERVED12[7];
__IO uint32_t BODCTRL; /*!< Offset: 0x150 (R/W) BOD control Register */
__IO uint32_t SYSTCKCAL; /*!< Offset: 0x154 (R/W) System tick counter calibration Register */
uint32_t RESERVED13[1];
uint32_t RESERVED14[5];
uint32_t RESERVED15[2];
uint32_t RESERVED16[34];

__IO uint32_t STARTAPRP0; /*!< Offset: 0x200 (R/W) Start logic edge control Register 0 */
__IO uint32_t STARTERP0; /*!< Offset: 0x204 (R/W) Start logic signal enable Register 0 */
__O uint32_t STARTRSRP0CLR; /*!< Offset: 0x208 ( /W) Start logic reset Register 0 */
__I uint32_t STARTSRP0; /*!< Offset: 0x20C (R/ ) Start logic status Register 0 */
__IO uint32_t STARTAPRP1; /*!< Offset: 0x210 (R/W) Start logic edge control Register 1 (LPC11UXX only) */
__IO uint32_t STARTERP1; /*!< Offset: 0x214 (R/W) Start logic signal enable Register 1 (LPC11UXX only) */
__O uint32_t STARTRSRP1CLR; /*!< Offset: 0x218 ( /W) Start logic reset Register 1 (LPC11UXX only) */
__I uint32_t STARTSRP1; /*!< Offset: 0x21C (R/ ) Start logic status Register 1 (LPC11UXX only) */
uint32_t RESERVED17[4];

__IO uint32_t PDSLEEPCFG; /*!< Offset: 0x230 (R/W) Power-down states in Deep-sleep mode Register */
__IO uint32_t PDAWAKECFG; /*!< Offset: 0x234 (R/W) Power-down states after wake-up from Deep-sleep mode Register*/
__IO uint32_t PDRUNCFG; /*!< Offset: 0x238 (R/W) Power-down configuration Register*/
uint32_t RESERVED18[110];
__I uint32_t DEV%&&&&&%E_ID; /*!< Offset: 0x3F4 (R/ ) Device ID Register */
} LPC_SYSCON_TypeDef;

typedef struct
{
__IO uint32_t PIO2_6; /*!< Offset: 0x000 (R/W) I/O configuration for pin PIO2_6 */
uint32_t RESERVED0[1];
__IO uint32_t PIO2_0; /*!< Offset: 0x008 (R/W) I/O configuration for pin PIO2_0/DTR/SSEL1 */
__IO uint32_t RESET_PIO0_0; /*!< Offset: 0x00C (R/W) I/O configuration for pin RESET/PIO0_0 */
__IO uint32_t PIO0_1; /*!< Offset: 0x010 (R/W) I/O configuration for pin PIO0_1/CLKOUT/CT32B0_MAT2 */
__IO uint32_t PIO1_8; /*!< Offset: 0x014 (R/W) I/O configuration for pin PIO1_8/CT16B1_CAP0 */
uint32_t RESERVED1[1];
__IO uint32_t PIO0_2; /*!< Offset: 0x01C (R/W) I/O configuration for pin PIO0_2/SSEL0/CT16B0_CAP0 */

__IO uint32_t PIO2_7; /*!< Offset: 0x020 (R/W) I/O configuration for pin PIO2_7 */
__IO uint32_t PIO2_8; /*!< Offset: 0x024 (R/W) I/O configuration for pin PIO2_8 */
__IO uint32_t PIO2_1; /*!< Offset: 0x028 (R/W) I/O configuration for pin PIO2_1/nDSR/SCK1 */
__IO uint32_t PIO0_3; /*!< Offset: 0x02C (R/W) I/O configuration for pin PIO0_3 */
__IO uint32_t PIO0_4; /*!< Offset: 0x030 (R/W) I/O configuration for pin PIO0_4/SCL */
__IO uint32_t PIO0_5; /*!< Offset: 0x034 (R/W) I/O configuration for pin PIO0_5/SDA */
__IO uint32_t PIO1_9; /*!< Offset: 0x038 (R/W) I/O configuration for pin PIO1_9/CT16B1_MAT0 */
__IO uint32_t PIO3_4; /*!< Offset: 0x03C (R/W) I/O configuration for pin PIO3_4 */

__IO uint32_t PIO2_4; /*!< Offset: 0x040 (R/W) I/O configuration for pin PIO2_4 */
__IO uint32_t PIO2_5; /*!< Offset: 0x044 (R/W) I/O configuration for pin PIO2_5 */
__IO uint32_t PIO3_5; /*!< Offset: 0x048 (R/W) I/O configuration for pin PIO3_5 */
__IO uint32_t PIO0_6; /*!< Offset: 0x04C (R/W) I/O configuration for pin PIO0_6/SCK0 */
__IO uint32_t PIO0_7; /*!< Offset: 0x050 (R/W) I/O configuration for pin PIO0_7/nCTS */
__IO uint32_t PIO2_9; /*!< Offset: 0x054 (R/W) I/O configuration for pin PIO2_9 */
__IO uint32_t PIO2_10; /*!< Offset: 0x058 (R/W) I/O configuration for pin PIO2_10 */
__IO uint32_t PIO2_2; /*!< Offset: 0x05C (R/W) I/O configuration for pin PIO2_2/DCD/MISO1 */

__IO uint32_t PIO0_8; /*!< Offset: 0x060 (R/W) I/O configuration for pin PIO0_8/MISO0/CT16B0_MAT0 */
__IO uint32_t PIO0_9; /*!< Offset: 0x064 (R/W) I/O configuration for pin PIO0_9/MOSI0/CT16B0_MAT1 */
__IO uint32_t SWCLK_PIO0_10; /*!< Offset: 0x068 (R/W) I/O configuration for pin SWCLK/PIO0_10/SCK0/CT16B0_MAT2 */
__IO uint32_t PIO1_10; /*!< Offset: 0x06C (R/W) I/O configuration for pin PIO1_10/AD6/CT16B1_MAT1 */
__IO uint32_t PIO2_11; /*!< Offset: 0x070 (R/W) I/O configuration for pin PIO2_11/SCK0 */
__IO uint32_t R_PIO0_11; /*!< Offset: 0x074 (R/W) I/O configuration for pin TDI/PIO0_11/AD0/CT32B0_MAT3 */
__IO uint32_t R_PIO1_0; /*!< Offset: 0x078 (R/W) I/O configuration for pin TMS/PIO1_0/AD1/CT32B1_CAP0 */
__IO uint32_t R_PIO1_1; /*!< Offset: 0x07C (R/W) I/O configuration for pin TDO/PIO1_1/AD2/CT32B1_MAT0 */

__IO uint32_t R_PIO1_2; /*!< Offset: 0x080 (R/W) I/O configuration for pin nTRST/PIO1_2/AD3/CT32B1_MAT1 */
__IO uint32_t PIO3_0; /*!< Offset: 0x084 (R/W) I/O configuration for pin PIO3_0/nDTR */
__IO uint32_t PIO3_1; /*!< Offset: 0x088 (R/W) I/O configuration for pin PIO3_1/nDSR */
__IO uint32_t PIO2_3; /*!< Offset: 0x08C (R/W) I/O configuration for pin PIO2_3/RI/MOSI1 */
__IO uint32_t SWDIO_PIO1_3; /*!< Offset: 0x090 (R/W) I/O configuration for pin SWDIO/PIO1_3/AD4/CT32B1_MAT2 */
__IO uint32_t PIO1_4; /*!< Offset: 0x094 (R/W) I/O configuration for pin PIO1_4/AD5/CT32B1_MAT3 */
__IO uint32_t PIO1_11; /*!< Offset: 0x098 (R/W) I/O configuration for pin PIO1_11/AD7 */
__IO uint32_t PIO3_2; /*!< Offset: 0x09C (R/W) I/O configuration for pin PIO3_2/nDCD */

__IO uint32_t PIO1_5; /*!< Offset: 0x0A0 (R/W) I/O configuration for pin PIO1_5/nRTS/CT32B0_CAP0 */
__IO uint32_t PIO1_6; /*!< Offset: 0x0A4 (R/W) I/O configuration for pin PIO1_6/RXD/CT32B0_MAT0 */
__IO uint32_t PIO1_7; /*!< Offset: 0x0A8 (R/W) I/O configuration for pin PIO1_7/TXD/CT32B0_MAT1 */
__IO uint32_t PIO3_3; /*!< Offset: 0x0AC (R/W) I/O configuration for pin PIO3_3/nRI */
__IO uint32_t SCK_LOC; /*!< Offset: 0x0B0 (R/W) SCK pin location select Register */
__IO uint32_t DSR_LOC; /*!< Offset: 0x0B4 (R/W) DSR pin location select Register */
__IO uint32_t DCD_LOC; /*!< Offset: 0x0B8 (R/W) DCD pin location select Register */
__IO uint32_t RI_LOC; /*!< Offset: 0x0BC (R/W) RI pin location Register */
} LPC_IOCON_TypeDef;

#define LPC_APB0_BASE(0x40000000UL)

#define LPC_AHB_BASE(0x50000000UL)

#define LPC_IOCON_BASE(LPC_APB0_BASE + 0x44000)

#define LPC_SYSCON_BASE(LPC_APB0_BASE + 0x48000)

#define LPC_SYSCON((LPC_SYSCON_TypeDef *) LPC_SYSCON_BASE)

#define LPC_IOCON((LPC_IOCON_TypeDef*) LPC_IOCON_BASE )

#define LPC_GPIO0_BASE(LPC_AHB_BASE+ 0x00000)

#define LPC_GPIO1_BASE(LPC_AHB_BASE+ 0x10000)

#define LPC_GPIO2_BASE(LPC_AHB_BASE+ 0x20000)

#define LPC_GPIO3_BASE(LPC_AHB_BASE+ 0x30000)

#define LPC_GPIO0((LPC_GPIO_TypeDef*) LPC_GPIO0_BASE )

#define LPC_GPIO1((LPC_GPIO_TypeDef*) LPC_GPIO1_BASE )

#define LPC_GPIO2((LPC_GPIO_TypeDef*) LPC_GPIO2_BASE )

#define LPC_GPIO3((LPC_GPIO_TypeDef*) LPC_GPIO3_BASE )

//************************************************************************************

void SysCLK_config(void)

{

uint8_t i;

LPC_SYSCON->PDRUNCFG &= ~(1 << 5);//给体系振动器上电

LPC_SYSCON->SYSOSCCTRL = 0x00000000;//体系振动器未旁路,1~12MHz输入

for (i = 0; i < 200; i++) __nop();//延时等候振动器安稳

LPC_SYSCON->SYSPLLCLKSEL = 0x00000001;//PLL输入挑选外部晶体振动

LPC_SYSCON->SYSPLLCLKUEN = 0x00;

LPC_SYSCON->SYSPLLCLKUEN = 0x01;//先写0后写1更新时钟源

while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01));//等候更新完结

LPC_SYSCON->SYSPLLCTRL = 0x00000023;//M=4、P=2,倍频后的时钟为48MHz

LPC_SYSCON->PDRUNCFG &= ~(1 << 7);//给PLL上电

while (!(LPC_SYSCON->SYSPLLSTAT & 0x01));//等候PLL确定

LPC_SYSCON->MAINCLKSEL = 0x00000003;//主时钟挑选PLL倍频后的时钟

LPC_SYSCON->MAINCLKUEN = 0x00;

LPC_SYSCON->MAINCLKUEN = 0x01;//先写0后写1更新时钟源

while (!(LPC_SYSCON->MAINCLKUEN & 0x01));//等候更新完结

LPC_SYSCON->SYSAHBCLKDIV = 0x00000001;//AHB为1分频,AHB时钟为48MHz

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);//使能GPIO时钟

}

void SystemInit(void)

{

SysCLK_config();

}

void CLKOUT_EN(uint8_t CLKOUT_DIV)

{

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16);

LPC_IOCON->PIO0_1=0XD1;

LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<16);

LPC_SYSCON->CLKOUTDIV = CLKOUT_DIV;

LPC_SYSCON->CLKOUTCLKSEL= 0X00000003;

LPC_SYSCON->CLKOUTUEN =0X00;

LPC_SYSCON->CLKOUTUEN =0X01;

while (!(LPC_SYSCON->CLKOUTUEN & 0x01));

}

int main(void)

{

SystemInit ();//调用时钟装备函数

CLKOUT_EN(48);//CLKOUT输出1MHz的脉冲

while(1)

{

;//空循环

}

}

从程序中能够看出,它加入了对“IOCON寄存器”和“GPIO寄存器”的界说,依然运用结构体的方式。把上述程序拷贝到开发环境中编译,然后下载到LPC1114中,就能够经过示波器调查到P0.1脚上的波形了。至于怎么经过开发环境生成下载文件,怎么把它下载到LPC1114中,会在后边进行评论。

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/zhudong/272803.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部