STM8 study notes (I): GPIO

Publisher:CreativeMindLatest update time:2015-12-14 Source: eefocusKeywords:STM8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I soldered a STM8 minimum system board last night, it can run and download

 I worked on it all night... but got nothing.

Maybe influenced by STM32, I always wanted to use its own library, but I was depressed for a long time.

No, without its own library

I went online to look up a routine for operating an LED.

I looked at several GPIO registers myself

There are mainly the following

1. Port x output data register (Px_ODR)

In output mode, the value written to the register is added to the corresponding pin through the latch. Reading the ODR register returns the previously latched register value.
In input mode, the value written to the ODR will be latched into the register, but will not change the pin state. The ODR register is always 0 after reset. Bit manipulation instructions (BSET, BRST) can be used to set the DR register to drive the corresponding pin, but will not affect other pins.
 

2. Port x input register (Px_IDR)

IDR[7:0]: Port input data register bit
Whether the pin is in input or output mode, the pin status value can be read through this register. This register is a read-only register.
0: logic low level
1: logic high level
 

3. Port x data direction (Px_DDR)

These bits can be set to 1 or 0 by software to select the pin as input or output
0: Input mode
1: Output mode
 

4. Port x Control Register 1 (Px_CR1)

In input mode (DDR=0):
0: floating input
1: input with pull-up resistor
In output mode (DDR=1):
0: simulated open-drain output (not true open-drain output)
1: push-pull output, output slew rate controlled by the corresponding bit of CR2
 

5. Port x control register 2 (Px_CR2) in input mode (DDR=0):

0: Disable external interrupt
1: Enable external interrupt
In output mode (DDR=1):
0: Maximum output speed is 2MHZ.
1: Maximum output speed is 10MHZ
 

The IDE I use is STVD. After creating a new project, put the STM8S208R.h library file in the newly created file

The following is programming

This is the code I wrote... It's pretty bad

///////////////////////////////////////////////////////////

/*============================================================================*/
/* PROJECT: LED Control by timer OC */
/* MODULE: main.c */
/* COMPILER: STM8 Cosmic C Compiler */
/* DATE: Feb 2009 */
/*----------------------------------------------------------------------------*/
/* DESCRIPTION: Demonstration firmware for STM8 Mini Kit */
/* Control LED blink, on/off/, brightness. */
/*============================================================================*/
/******************************************************************************
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* COPYRIGHT 2008 STMicroelectronics
******************************************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include "stm8s208r.h" /* Registers and memory mapping file. */

/******************************************************************************/
/* Function definitions */
/******************************************************************************/
/* -------------------------------------------------------------------------- */
/* ROUTINE NAME: GPIO_Init */
/* INPUT/OUTPUT: None. */
/* DESCRIPTION: Initialize GPIOs. */
/* IN: None. */
/* OUT: None. */
/* -------------------------------------------------------------------------- */
void GPIO_Init(void) 
{
/* LED IO Configuration */
/* LD3: PD3 */
/* LD2: PD1 */
/* LD1: PD0 */
PD_DDR |= 0xFF; /* Output. */
PD_CR1 |= 0xFF; /* PushPull. */
PD_CR2 = 0x00; /* Output speed up to 2MHz. */
PD_ODR |= 0x55;//IO口要输出的数据
}
/* -------------------------------------------------------------------------- */
/* ROUTINE NAME: CLK_Init */
/* INPUT/OUTPUT: None. */
/* DESCRIPTION: Initialize the clock source */
/* -------------------------------------------------------------------------- */
void CLK_Init(void)
{
/* Configure HSI prescaler*/
CLK_CKDIVR &= ~0x10; /* 01: fHSI= fHSI RC output/2. */

/* Configure CPU clock prescaler */
CLK_CKDIVR |= 0x01; /* 001: fCPU=fMASTER/2. */
}
/* -------------------------------------------------------------------------- */
/* ROUTINE: main */
/* main entry */
/* -------------------------------------------------------------------------- */
void main ( void )

while(1)
{
CLK_Init();
GPIO_Init();
}

/*---------------------------- End of file -----------------------------------*/

////////////////////////////////////////////////////////////////

This is just a very simple function

The road is long and arduous, and there is still a long way to go

Keywords:STM8 Reference address:STM8 study notes (I): GPIO

Previous article:STM8 study notes - PWM module
Next article:STM8 study notes (II): GPIO input

Recommended ReadingLatest update time:2024-11-15 14:44

Learn about LPC1200 GPIO together
Introduction to LPC1200 The LPC1200 series Cortex-M0 microcontroller can run at up to 45MHz CPU frequency, including up to 128KB on-chip Flash memory and 8KB data memory. The smaller 512-byte Flash erase sector brings a variety of design benefits, such as more sophisticated EEPROM emulation, support for boot loading
[Microcontroller]
Learn about LPC1200 GPIO together
STM32 GPIO usage summary
STM32 GPIO usage summary STM32 GPIO usage steps: 1. Enable the peripheral clock corresponding to GPIO For example: // Enable the peripheral clock corresponding to GPIOA, GPIOB, and GPIOC RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE); 2. Declare a GPIO_InitStructure
[Microcontroller]
A topic about STM8 interrupt application exception
One day, an engineer told me that he was developing a product using the STM8S chip, using a certain ADC channel, using the continuous acquisition mode, and enabling the ADC conversion end interrupt. The entire interrupt program execution time is about 200us. Because of the continuous acquisition conversion, a new EOC
[Microcontroller]
A topic about STM8 interrupt application exception
STM8 realizes perpetual calendar (highlight time adjustment)
1. Design content: This design uses stm8s to realize a simple perpetual calendar, the main functions are to display time, adjust time, and set alarms. In addition, game auxiliary functions are added. 2. Design requirements: 1. The main control chip uses stm8s 2. Use PCB board 3. At least the digital tube sho
[Microcontroller]
STM32 GPIO usage steps ST3.0.0 library
Steps to initialize a normal IO 1: GPIO_InitTypeDef GPIO_InitStructure defines a structure for initializing IO 2: Enable IO clock. STM32 IOs are all high-speed IOs. There are two situations The first is that IO is a high-speed clock: void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState
[Microcontroller]
stm8 unique ID number encryption method. Idea
1. Read out the ID number #if defined(STM8S103)      #define ID_BaseAddress (0x4865) #else // defined(STM8S105)      #define ID_BaseAddress (0x48CD) #endif void GetUniqueID(unsigned char *p) {      unsigned char i;      unsigned char *pIDStart=(unsigned char *)(ID_BaseAddress);         for(i=0;i!=12;i++){*p++=*pIDSt
[Microcontroller]
STM8 Getting Started Learning and Experiments (I) GPIO and UART
Introduction: This chapter will describe how to configure GPIO and how to configure UART STM8 project template: http://download.csdn.net/detail/u012388993/9904051 The basic system configuration initialization function that will be used in these two experiments CLK_PeripheralClockConfig(CLK_PERIPHERAL_UART1, ENA
[Microcontroller]
STM8 Getting Started Learning and Experiments (I) GPIO and UART
ARM development uses Linux general GPIO interface macro functions to operate IO ports
ARM development board: S5PV210 Driving steps: 1. Define a cdev device structure variable 2. Apply for a device number for cdev 3. Define a file operation set 4. Device initialization 5. Register the device into the kernel 6. Apply for GPIO port GPIO related function interface: 1.gpio_request(pi
[Microcontroller]
ARM development uses Linux general GPIO interface macro functions to operate IO ports
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号