[mw_shl_code=c,true]
[mw_shl_code=c,true]/* MAIN.C file
*
* Copyright (c) 2002-2005 STMicroelectronics
*/
/*程序描述:切换时钟源*/
#include"stm8s105s4.h"
//函数功能:延时功能
//输入参数:ms--要延时的毫秒数,这里假设cpu的主频为2M
//输出参数:无
//返回参数:无
//备 注: 无
void DelayMs(unsigned int ms)
{
while(ms != 0)
{
unsigned char i;
for(i=0;i<250;i++);
for(i=0;i<75;i++);
ms--;
}
}
void GPIO_Int(void)
{
PD_DDR = 0X18;
PD_CR1 = 0X18;
PD_CR2 = 0X00;
}
_Bool led2 @PD_ODR:3;
_Bool led1 @PD_ODR:4;
main()
{
int i;
GPIO_Int();
CLK_ECKR = 0X01;//enable HSE
while((CLK_ECKR & 0x02) == 0x00);//等待HSE
for(;;)
{
CLK_SWCR = CLK_SWCR | 0x02;//enable switch
CLK_SWR = 0xB4;//set hse as master clock
while((CLK_SWCR & 0x08) == 0);//judge hse ready or not
CLK_SWCR = CLK_SWCR & 0xFD;//clear sign
for(i=0;i<10;i++)
{
led2 = 1;
led1 = 1;
DelayMs(100);
led2 = 0;
led1 = 0;
DelayMs(100);
}
CLK_SWR = 0xE1;
while((CLK_SWCR & 0x08) == 0);
CLK_SWCR = CLK_SWCR | 0x02;
CLK_SWCR = CLK_SWCR & 0xFD;
for(i=0;i<10;i++)
{
led2 = 1;
led1 = 1;
DelayMs(100);
led2 = 0;
led2 = 0;
DelayMs(100);
}
}
}
[/mw_shl_code]
[/mw_shl_code]
为什么我烧录进去之后没有看到任何现象只能看到两个led小灯长亮?
本人新手,感谢高手解答。
|