其他分享
首页 > 其他分享> > STM8L151C8单片机学习例程(2)——CLK切换

STM8L151C8单片机学习例程(2)——CLK切换

作者:互联网

STM8L_2_CLK:
1.User:工程及main文件
2.Hardware:CLK,LED,Delay
3.STM8L15x_StdPeriph_Driver:STM8自带库文件
4.Debug:hex文件存放于EXE文件夹
5.Function:    不同CLK时,LED闪烁

/**
******************************************************************************
* 	@file    	main.c
* 	@author  	Alex——小白
* 	@version 	V1.0
* 	@date    	2019.5.1
* 	@brief   	CLK_Config:HSI,Choose HSE_Config from CLK.h
*	@store   	有家Proteus仿真店子
*	@Link    	https://shop484534014.taobao.com/
*	@Email	 	844545015@qq.com
******************************************************************************
* 	@attention	All Rights Reserved  
**/

#include "stm8l15x.h"
#include "LED.h"
#include "Delay.h"
#include "CLK.h"

void main(void)
{
    uint8_t i = 0,j = 0;
    LED_Init();
    while(1)
    {
        CLK_HSI_Config(CLK_SYSCLKDiv_8);    //HSI 8分频 2MHz 	
        for(i = 0;i < 5;i++)
        {
            LED0(0);
            LED1(1);
            for(j=0;j<6;j++)Delay(0xFFFF);  //近似80ms*6=0.5s
            LED0(1);
            LED1(0);
            for(j=0;j<6;j++)Delay(0xFFFF);  //近似80ms*6=0.5s
        }
        
        for(i = 0;i < 5;i++)               //延时,分开两次闪烁
        {
            Delay(0xFFFF);
            Delay(0xFFFF);
        }
        
        CLK_HSE_Config(CLK_SYSCLKDiv_4);    //HSE 4分频 4MHz    
        for(i = 0;i < 5;i++)
        {
            LED0(0);
            LED1(1);
            Delay(0xFFFF);
            Delay(0xFFFF);
            LED0(1);
            LED1(0);
            Delay(0xFFFF);
            Delay(0xFFFF);
        }
        
        for(i = 0;i < 5;i++)               //延时,分开两次闪烁
        {
            Delay(0xFFFF);
            Delay(0xFFFF);
        }
        
        CLK_LSI_Config(CLK_SYSCLKDiv_1);    //LSI 1分频 38K
        for(i = 0;i < 5;i++)
        {
            LED0(0);
            LED1(1);
            Delay(0x0FFF);
            LED0(1);
            LED1(0);
            Delay(0x0FFF);
        }
        
        for(i = 0;i < 2;i++)               //延时,分开两次闪烁
        {
            Delay(0x0FFF);
        }

        CLK_LSE_Config(CLK_SYSCLKDiv_1);    //LSE 1分频 32.768K
        for(i = 0;i < 5;i++)
        {
            LED0(0);
            LED1(1);
            Delay(0x07FF);
            LED0(1);
            LED1(0);
            Delay(0x07FF);
        }
        
        for(i = 0;i < 2;i++)               //延时,分开两次闪烁
        {
            Delay(0x07FF);
        }
    }
}

 

Smile_shao 发布了14 篇原创文章 · 获赞 1 · 访问量 4935 私信 关注

标签:main,LED,CLK,例程,HSI,单片机,include,Config
来源: https://blog.csdn.net/Smile_shao/article/details/104079426