STM32 8-bit IO operation

Publisher:真瓷堂Latest update time:2017-09-18 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The bottom line is that it is a matter of reading and writing the eight IO ports. You can either write two functions, WriteData() and ReadData(), or call the GPIO bit manipulation functions separately.
void WriteData(u8 data)
{
   // Operate the IO ports connected to the LCD separately, in the order from high to low
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x80) >> 7 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x40) >> 6 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x20) >> 5 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x10) >> 4 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x08) >> 3 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x04) >> 2 ); 
    GPIO_WriteBit(GPIO number, Pin number, (data & 0x02) >> 1 ); 
    GPIO_WriteBit(GPIO number, Pin number, data & 0x01);
 }
u8 ReadData (void)
{
   u8 data;
   data = GPIO_ReadInputDataBit (GPIO number, Pin number); //8-bit
   data << 1;
   data |= GPIO_ReadInputDataBit (GPIO number, Pin number); //7-bit
   data << 1;
   data |= GPIO_ReadInputDataBit (GPIO number, Pin number); //6-bit
   data << 1;
   data |= GPIO_ReadInputDataBit (GPIO number, Pin number); //5-bit
   data << 1;
   data |= GPIO_ReadInputDataBit (GPIO number, Pin number); //4-bit
   data << 1;
   data |= GPIO_ReadInputDataBit (GPIO number, Pin number); //3-bit
   data << 1;
   data |= GPIO_ReadInputDataBit (GPIO number, Pin number); //2-bit
   data << 1;
   data |= GPIO_ReadInputDataBit(GPIO number, Pin number); //1 bit
   return data;
  }
With the read and write functions, the rest is the data interaction with the LCD controller.

Keywords:STM32 Reference address:STM32 8-bit IO operation

Previous article:Understanding STM32 network communication DM9000
Next article:The difference between mov and ldr in arm instructions

Recommended ReadingLatest update time:2024-11-16 20:34

STM32 ADC configuration
For STM32, several parameters need to be configured when using ADC. (1)     The first parameter is ADC_Mode, which is set to independent mode here: ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; In this mode, the dual ADCs cannot be synchronized, and each ADC interface works independently. So if ADC synchroni
[Microcontroller]
stm32 can communication sending explanation
uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage) {   uint8_t transmit_mailbox = 0;   /* Check the parameters */   assert_param(IS_CAN_ALL_PERIPH(CANx));   assert_param(IS_CAN_IDTYPE(TxMessage- IDE));   assert_param(IS_CAN_RTR(TxMessage- RTR));   assert_param(IS_CAN_DLC(TxMessage- DLC));     /* Select one e
[Microcontroller]
Based on STM32-button input and eight IO port modes
Key detection uses the basic input function of the GPIO peripheral. When the mechanical contacts of the key are opened or closed, due to the elastic effect of the contacts, the key switch will not be immediately stably connected or disconnected. When the key is used, a ripple signal as shown in the figure will be gene
[Microcontroller]
Based on STM32-button input and eight IO port modes
STM32 serial port uart
uart initialization steps Baud rate calculation formula: Baud rate = Fpclkx / (16 * USARTDIV) Take uart1 as an example to illustrate that uart1 uses PA9, PA10 1. Calculate the baud rate parameter  temp = (float) (pclk2 * 1000000) / (bound * 16); // Get USARTDIV  mantissa = temp; // Get the integer part  fraction
[Microcontroller]
STM32 I2C HAL library reads HTU21D
The following code is a routine to use I2C library functions to read the temperature data of HTU21D. ret=HAL_I2C_Mem_Read(&hi2c1,0x80,0xf3,I2C_MEMADD_SIZE_8BIT,rx_buf,2,2000); if(ret == HAL_OK) { rx_buf &= 0xfc; temp = rx_buf ; temp *= 256;    //wendu =8; temp += rx_buf ; temp *= 17572; temp /= 6553
[Microcontroller]
STM32 UVC study notes 3
Host environment: Windows 7 SP1 Development environment: MDK5.18 Target board: STM32F103C8T6 Development library: STM32F1Cube library and STM32_USB_Device_Library Continuing with yesterday's study notes, it was mentioned before that there was no data loss when comparing the data captured from the USBTrace software wit
[Microcontroller]
STM32 about printf redirection to serial port
Simply put: if you want to use printf in mdk, you need to redefine the fputc function and avoid using semihosting (semihosting mode). The default output device of the standard library function is the display. To achieve output on the serial port or LCD, you must redefine the functions related to the output device call
[Microcontroller]
IIC Topic 2 - STM32 driving AT24C02
1 Overview The EEPROM chip model on the MiniSTM32 development board is 24C02. The total capacity of the chip is 256 bytes, and the chip is connected to the outside through the IIC bus. Here we directly use the AT24C02 on the Atom board, mainly for learning software programming. 2. Hardware Connection The thre
[Microcontroller]
IIC Topic 2 - STM32 driving AT24C02
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号