STM8 亮灯程序

 开发环境:ST Visual Develop+STM32 ST-LINK Utility+开发板

原理:定时向指定针脚输出高电平信号

/* MAIN.C file
 *
 * Copyright (c) 2002-2005 STMicroelectronics
 */

#include <stm8s.h>
#include <stm8s_clk.h>
#include <stm8s_gpio.h>

void Init_GPIO(void)
{
    /*** Initialize I/Os in Output Mode Push-Pull ***/
    /* LEDs 2, 3, 4 */
   // GPIO_Init(GPIOB, (GPIO_PIN_4 | GPIO_PIN_5), GPIO_MODE_OUT_PP_LOW_FAST);
    GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_OUT_PP_LOW_FAST);

    //GPIO_WriteHigh(GPIOB, (GPIO_PIN_4 | GPIO_PIN_5));
    GPIO_WriteHigh(GPIOC, GPIO_PIN_4);
}

void Init_Clock(void)
{

    /* Select fCPU = 16MHz */
    CLK_SYSCLKConfig(CLK_PRESCALER_HSIDIV1);

    /* For test purpose output Fcpu on MCO pin */
    //CLK_CCOConfig(CLK_OUTPUT_CPU);

}

void Delay(vu16 nCount)
{
    /* Decrement nCount value */
    while (nCount != 0)
    {
        nCount--;
    }
}

main()
{
    //Init_Clock();
    Init_GPIO();

    while (1) {
        GPIO_WriteReverse(GPIOC,GPIO_PIN_4);

        Delay(0xFFFF);
    }
}

 

posted @ 2017-08-07 23:04  八爻老骥  阅读(702)  评论(0编辑  收藏  举报