|
![](static/image/common/ico_lz.png)
楼主 |
发表于 2012-7-27 00:27:37
|
显示全部楼层
#include <c8051f120.h>
#define uchar unsigned char
#define uint unsigned int
sbit LED = P1^6;
//------------------------- 端口配置函数 -------------------------------//
void Port_Init(void)
{
char SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page
SFRPAGE = CONFIG_PAGE; // 寄存器页配置
XBR0 = 0x00; // Enable UART0
XBR1 = 0x00;
XBR2 = 0x40; // Enable crossbar and weak pull-up
P1MDOUT |= 0x40; // LED IO 推挽输出
SFRPAGE = SFRPAGE_SAVE; // Restore SFR page
}
/***********************************************************/
void SYSCLK_Init(void)
{
int loop; // Software timer
unsigned char data SFRPAGE_SAVE=SFRPAGE;
SFRPAGE= CONFIG_PAGE;
PLL0CN=0X05; //选择外部振荡器、PLL电源使能
SFRPAGE=LEGACY_PAGE; //设置FLASH读时间
FLSCL=0X30; //100M
SFRPAGE=CONFIG_PAGE;
PLL0DIV=0X01; //参考时钟不分频
PLL0FLT=0X01; //PLL滤波器
PLL0MUL=0X04; //倍频系数等于4
for (loop=0; loop < 256; loop++); // Wait at least 5us
PLL0CN|=0X02; //PLL使能
while(!(PLL0CN&0X10)); //等待时钟稳定
CLKSEL=0x02; //选择PLL振荡器
SFRPAGE=SFRPAGE_SAVE; //恢复寄存器页
// Multiply SYSCLK by M (M = 2) 倍频寄存器 2倍
}
/*******************************/
void delay(uint z)
{
uint x,y;
for(x=0;x<z;x++)
for(y=0;y<121;y++);
}
/*******************************/
//--------------------------- 主函数 ----------------------------------//
void main(void)
{
WDTCN = 0xDE;
WDTCN = 0xAD; // 关闭看门狗
SYSCLK_Init();
Port_Init();
while (1)
{
LED = 0;
delay(2000);
LED = 1;
delay(2000);
}
} |
|