STSW-STM8069
,版本号:2.3.1
STSW-STM8069
官方资源下载地址:https://www.st.com/zh/embedded-software/stsw-stm8069.html
3.11.1
以
STM8S208RB
芯片为实验目标开发芯片,围绕其基本功能和外设进行该系列工程案例的创建和学习。目前已经基本完善了该系列的常规应用和外设驱动的案例示例的开发和验证工作。反而文字行的内容摘要跟不上,只能一点点写,陆续更新发布出来。
● 可选择的输入模式:浮动输入和带上拉输入
● 可选择的输出模式:推挽式输出和开漏输出
stm8s_gpio.h
typedef enum
{
GPIO_MODE_IN_FL_NO_IT = (uint8_t)0x00, /*!< Input floating, no external interrupt */
GPIO_MODE_IN_PU_NO_IT = (uint8_t)0x40, /*!< Input pull-up, no external interrupt */
GPIO_MODE_IN_FL_IT = (uint8_t)0x20, /*!< Input floating, external interrupt */
GPIO_MODE_IN_PU_IT = (uint8_t)0x60, /*!< Input pull-up, external interrupt */
GPIO_MODE_OUT_OD_LOW_FAST = (uint8_t)0xA0, /*!< Output open-drain, low level, 10MHz */
GPIO_MODE_OUT_PP_LOW_FAST = (uint8_t)0xE0, /*!< Output push-pull, low level, 10MHz */
GPIO_MODE_OUT_OD_LOW_SLOW = (uint8_t)0x80, /*!< Output open-drain, low level, 2MHz */
GPIO_MODE_OUT_PP_LOW_SLOW = (uint8_t)0xC0, /*!< Output push-pull, low level, 2MHz */
GPIO_MODE_OUT_OD_HIZ_FAST = (uint8_t)0xB0, /*!< Output open-drain, high-impedance level,10MHz */
GPIO_MODE_OUT_PP_HIGH_FAST = (uint8_t)0xF0, /*!< Output push-pull, high level, 10MHz */
GPIO_MODE_OUT_OD_HIZ_SLOW = (uint8_t)0x90, /*!< Output open-drain, high-impedance level, 2MHz */
GPIO_MODE_OUT_PP_HIGH_SLOW = (uint8_t)0xD0 /*!< Output push-pull, high level, 2MHz */
}GPIO_Mode_TypeDef;
GPIO_Mode_In_FL_No_IT
:浮空输入无中断GPIO_Mode_In_PU_No_IT
:上拉输入无中断GPIO_Mode_In_FL_IT
:浮空输入有中断GPIO_Mode_In_PU_IT
:上拉输入有中断GPIO_Mode_Out_OD_Low_Fast
:开漏-输出低-高速 Output open-drain, low level, 10MHzGPIO_Mode_Out_PP_Low_Fast
:推挽-输出低-高速 Output push-pull, low level, 10MHzGPIO_Mode_Out_OD_Low_Slow
:开漏-输出低-低速 Output open-drain, low level, 2MHzGPIO_Mode_Out_PP_Low_Slow
:推挽-输出低-低速 Output push-pull, low level, 2MHzGPIO_Mode_Out_OD_HiZ_Fast
:开漏-输出高阻-高速 Output open-drain, high-impedance level, 10MHzGPIO_Mode_Out_PP_High_Fast
:推挽-输出高-高速 Output push-pull, high level, 10MHzGPIO_Mode_Out_OD_HiZ_Slow
:开漏-输出高阻-低速 Output open-drain, high-impedance level, 2MHzGPIO_Mode_Out_PP_High_Slow
:推挽-输出高-低速 Output push-pull, high level, 2MHz#define LED_GPIO_PORT ((GPIO_TypeDef *)GPIOC)
#define LED_GPIO_PINS (GPIO_PIN_7 | GPIO_PIN_6 | GPIO_PIN_3)
#define LED1_ON() GPIO_WriteLow(GPIOC , GPIO_PIN_7) //LED1亮
#define LED1_OFF() GPIO_WriteHigh(GPIOC , GPIO_PIN_7) //LED1灭
#define LED1_TOGGLE GPIO_WriteReverse(GPIOC , GPIO_PIN_7) //LED1状态取反
#define LED2_ON() GPIO_WriteLow(GPIOC , GPIO_PIN_6) //LED2亮
#define LED2_OFF() GPIO_WriteHigh(GPIOC , GPIO_PIN_6) //LED2灭
#define LED2_TOGGLE GPIO_WriteReverse(GPIOC , GPIO_PIN_6) //LED2状态取反
#include "stm8s.h"
#include "led.h"
#include "delay.h"
/* Private defines -----------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
void Delay(uint16_t nCount)
{
/* Decrement nCount value */
while (nCount != 0)
{
nCount--;
}
}
void main(void)
{
//内部时钟为1分频 = 16Mhz
CLK_SYSCLKConfig( CLK_PRESCALER_HSIDIV1 );//不启用,则系统时钟为8MHz
LED_Init();
while (1)
{
/* Toggles LEDs */
GPIO_WriteReverse(LED_GPIO_PORT, (GPIO_Pin_TypeDef)LED_GPIO_PINS);
// Delay(0xFFFF);
delay_ms(1000);
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval : None
*/
void assert_failed(u8* file, u32 line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
delay.c
#include "delay.h"
/*********************************************************************************
* 函 数 名: delay_us
* 功能说明: 微秒延时程序,注意此函数的运行环境为(16M时钟速度)
* 形 参:nCount要延时的微秒数,输入nCount=1微妙
* 返 回 值: 无
*********************************************************************************/
void delay_us(unsigned int nCount) //16M 晶振时 延时 1个微妙
{
nCount*=3;//等同于 nCount=nCount*3 相当于把nCount变量扩大3倍
while(--nCount);//nCount变量数值先减一,再判断nCount的数值是否大于0,大于0循环减一,等于0退出循环。
}
/*******************************************************************************
**函数名称:void delay(unsigned int ms)
**功能描述:大概延时
**入口参数:unsigned int ms 输入大概延时数值
**输出:无
*******************************************************************************/
void delay_ms(unsigned int ms)
{
unsigned int x , y;
for( x = ms; x > 0; x-- ) /* 通过一定周期循环进行延时*/
for( y = 3147 ; y > 0 ; y-- );
__asm( "nop" ); //Perform no operation //assembly code
__asm( "nop" );
}
在没有频繁中断任务运行时,该阻塞延时精度还是可以满足一般需求。
链接: https://pan.baidu.com/s/1t1IRwIJUJGjncKU1AeiTfw
提取码: xyvs