STM8S GPIO self-study notes

Publisher:740322lwjLatest update time:2021-09-07 Source: eefocusKeywords:STM8S  GPIO  register Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

STM8S105C6T6 48 pins 32KB Flash Package: LQFP temp: -40~85

PA1~PA6,PB0~PB7,PC1~PC7,PD0~PD7,PE0~PE3,PE5~PE7,PG0,PG1,

There are a total of 38 general-purpose I/O ports.


GPIO Registers

Port x Output Data Register (Px_ODR);

Port x input data register (Px_IDR);

Port x output data direction (Px_DDR); 0: input mode 1: output mode;

Port x Control Register 1 (Px_CR1);

When DDR=1; set to 0 for analog open-drain output; set to 1 for push-pull output; (CR2 bit is used for output slew rate control);

When DDR=0; set to 0 floating input; set to 1 pull-up input;

Port x Control Register 2 (Px_CR2);

When DDR=0; set to 0 to disable external interrupt; set to 1 to enable external interrupt;

When DDR=1; set 0 speed 2MHz; set 1 speed 10MHz;

Corresponding GPIO library functions

void GPIO_DeInit(GPIO_TypeDef* GPIOx);

Used to restore the register of the specified port to the default value, 0x00; non-interrupt function floating input.

void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode);

GPIO initialization, configuration of specified port functions

GPIO_Pin:

GPIO_PIN_0 ~GPIO_PIN_7;
GPIO_PIN_HNIB; //High four pins

GPIO_PIN_LNIB; //lower four pins

GPIO_PIN_ALL ; //All pins

GPIO_Mode: input and output mode settings;

void GPIO_Write(GPIO_TypeDef* GPIOx, u8 PortVal);

Write value to the corresponding GPIO output.

void GPIO_WriteHigh(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins);

Sets one or more pins of the specified port and outputs a high level, provided that the port is configured in output mode.

void GPIO_WriteLow(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins);

Sets one or more pins of the specified port and outputs a low level, provided that the port is configured in output mode.

void GPIO_WriteReverse(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef PortPins);

Negate the level state of one or more pins of the specified port and output them, provided that the port is configured in output mode.

u8 GPIO_ReadInputData(GPIO_TypeDef* GPIOx);

Read the specified port data and return an 8-bit unsigned value. The prerequisite is that the port is configured in input mode.

u8 GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);

Read the value of the specified port output register and return an 8-bit unsigned value.

BitStatus GPIO_ReadInputPin(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin);

Read the status of one or more pins of the specified port. If any pin is high, it returns SET, otherwise it returns RESET.

void GPIO_ExternalPullUpConfig(GPIO_TypeDef* GPIOx, GPIO_Pin_TypeDef GPIO_Pin, FunctionalState NewState);

Pin to enable or disable the internal pull-up resistor.

The STM8S series can be programmed using library functions or by directly manipulating registers.

Library function version of GPIO lights up LED (IAR FOR STM8S)

#include "stm8s.h"
#define uint unsigned int
void Delay(uint xms)
{
  uint i,j;
  for(i=xms;i>0;i--)
   for(j=220;j>0;j--);
}


void main()
{
  
   GPIO_Init( GPIOD,GPIO_PIN_0,GPIO_MODE_OUT_PP_HIGH_FAST);

  GPIO_WriteHigh(GPIOD,GPIO_PIN_0);
   Delay(500);
  GPIO_WriteLow(GPIOD,GPIO_PIN_0);
   Delay(500);
   while(1);
 

}


void assert_failed(u8* file, u32 line)
 {
   while (1)
   {
   }
 }

Keywords:STM8S  GPIO  register Reference address:STM8S GPIO self-study notes

Previous article:STM8S independent watchdog configuration and use
Next article:STM8S HSI self-study notes

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号