ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

Publisher:月光男孩Latest update time:2017-04-04 Source: eefocusKeywords:ARM7 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Input/output port GPIO programming

1--(01), one-digit digital tube static display (realized by 74HC595)

1. Pin connection module

First, let me introduce the relevant pins of LPC2106~~

Features: Independent pin configuration is possible

Application: The purpose of the pin connection module is to configure the pins to the required functions (this chapter mainly introduces the GPIO function~~ Others will be introduced in the following chapters~~)

Description: The pin connection module enables selected pins to have more than one function. Configuration registers control multiplexers to connect pins to on-chip peripherals. Peripherals must be connected to the appropriate pins before activation and any related read-only enables. Any enabled peripheral function is considered invalid if it is not mapped to the corresponding pin.

Register Description:

The pin connection module consists of two registers:

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

Pin function register 0: (PINSEL0)

The PINSEL0 register controls the function of the pin according to the settings in the table below.

The direction control bit in the IODIR register is only valid when the pin is selected as GPIO function (which is what this chapter will describe). For other functions, the direction is automatically controlled.

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01
Pin function register 1: (PINSEL1)

The PINSEL1 register sets the function of the control pin according to the following table.

The direction control bit in the IODIR register is only valid when the pin selects the GPIO function. For other functions, the direction is automatically controlled.

When DBGSEL is pulled low during reset, the function control of pins P0.17-P0.31 is valid. (I really don't know this~~ ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01)

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01  
ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

Pin function register value:

The PINSEL register controls the function of the device pins. See the figure below.
Each pair of register bits corresponds to a specific device pin.

The direction control bit of the IODIR register is valid only when the pin is selected as the GPIO function.

The direction of other functions is controlled automatically.

Each derivative typically has a different pinout, so each pin may have a different function.

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

2. GPIO

characteristic:

1) Single bit direction control

2) Individually control the setting and clearing of outputs

3) All I/O ports default to input after reset

application:

1) General I/O port

2) Driving LED or other indicators

3) Driving off-chip devices

4) Detect digital input

Pin Description:ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

Register Description:

GPIO contains 4 registers, as shown in the following table:

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

GPIO pin value register IOPIN:

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01
GPIO output set register IOSET:

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

GPIO output clear register:

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

GPIO direction register:

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01
Okay, that's it~~

Then here is today’s experiment:

Static display of a digital tube

 I'm dizzy~~ I just can't adjust it well with IAR for ARM~~

shit~~

Then I switched to Keil~~

Waste a lot of my time~~

If I had known this earlier, I would have used Keil~~

I have to debug IAR again later~~

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01~~

Okay, post the picture~~

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

Then there is the procedure~~

MDK1_1.c (main program first, you know)

//------------------------------------------------------------------------------
//LED digital tube display
//Connect with 74HC595 through I/O analog synchronous serial interface, control 74HC595 to drive LED digital tube display
//------------------------------------------------------------------------------
#include"lpc210x.h"
typedef unsigned long uint32;
typedef unsigned char uchar;
#define SPI_IO 0x00000150 //SPI interface I/O setting word
uchar const seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
                   0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//------------------------------------------------------------------------------
//Delay function
void delay(uint32 z)
{
 uint32 i;
 for(;z>0;z--)
   for(i=0;i<50000;i++);
}
//------------------------------------------------------------------------------
//main
int main()
{
 uchar i;
 PINSEL0=0X00000000;
 PINSEL1=0X00000000; //Set the left and right pins to connect to GPIO
 
 IODIR=SPI_IO; //Set the SPI control port to output~~Since this is simulated, you need to set the direction bit yourselfwhile
 (1)
 {
   for(i=0;i<16;i++)
   {
     HC595_send_data(seg[i]);
     delay(1);
   }
 }  
}

74HC595.c

//------------------------------------------------------------------------------
//74HC595 simulates SPI communication for easy calling
#include "lpc210x.h"
typedef unsigned long uint32;
typedef unsigned char uchar;
#define SPI_CS 0x00000100 //P0.8 simulates chip select
#define SPI_DA 0x00000040 //P0.6 simulates data transmission port
#define SPI_CLK 0x00000010 //P0.4 simulates CLK
//------------------------------------------------------------------------------
//Send a byte function to 74HC595 (when sending data, the high bit is in front)
//Let's give a brief introduction to 74HC595:
//74HC595 has an 8-bit shift register and a memory, and a three-state output function.
//The shift register and memory are clocked separately.
//Data is input to the shift register at the rising edge of SH_CP and input to the storage register at the rising edge of ST_CP.
//If the two clocks are connected together, the shift register is always one pulse earlier than the storage register (usually it is not used this way~~).
//The shift register has a serial shift input (DS), a serial output (Q7'), and an asynchronous low-level reset.
//The storage register has a parallel 8-bit bus output with three states. When OE is enabled (low level), the data of the storage register is output to the bus.
void HC595_send_data(uchar dat)
{
 uchar i;
 IOCLR=SPI_CS; //SPI_CS=0
 for(i=0;i<8;i++) //Simulate SPI~~
 {
   IOCLR=SPI_CLK; //SPI_CLK=0
   if((dat&0x80)!=0) //Set the output value of SPI_DA
     IOSET=SPI_DA; //To send from the highest bit, when the highest bit is 1, set SPI_DA
   else
     IOCLR=SPI_DA; //When the highest bit is 0, clear SPI_DA
   dat<<=1; //dat is cyclically shifted left by one bit
   IOSET=SPI_CLK; //SPI_CLK is 1, a pulse rising edge, the data is moved into the shift register
 }
 IOSET=SPI_CS; //SPI_CS=1, input to the storage register, because the chip select is always low, the displayed data is directly output
}


Keywords:ARM7 Reference address:ARM7 microcontroller (learning) - (I), input/output port GPIO programming - 01

Previous article:ARM7 MCU (Learning) - (I) Input/output port GPIO programming - 02
Next article:ARM microcontroller (learning) - my first ARM7 microcontroller program

Recommended ReadingLatest update time:2024-11-15 16:46

STC89C52 single chip digital tube static display
///////////////////////////////////////////////////// /////////////////////////////   Function: statically light up the digital tube on the experimental board to display each number from 0 to 9 on the digital tube, and                     the switching time interval is 0.5 seconds   Experimental board model: BS-XYD-
[Microcontroller]
Intelligent inverter power control system based on PIC microcontroller
  With the advancement of science and technology, power quality has become the basis for the normal and good operation of various electrical equipment. A continuous research topic in the field of power technology is to study the reliability and stability of power supply, which is the lifeblood of the electronic inform
[Microcontroller]
Intelligent inverter power control system based on PIC microcontroller
The difference between CPU, MPU, MCU and SOC (concept)
 1. CPU (Central Processing Unit) is the computing core and control core of a computer. CPU is composed of arithmetic unit, controller and register and the data, control and status bus that realize the connection between them. The operation principle of almost all CPUs can be divided into four stages: fetch, decode, e
[Microcontroller]
ARM and 51 MCU communication
The hardware is a mini2440 core board and another MCU learning board with a serial port (with DS18B20). The learning board continuously outputs the temperature value of DS18B20 with a baud rate of 19200. Create a new file in a folder, mine is voltage_set.c (to be used for voltage adjustment later)   #include stdio
[Microcontroller]
Practice of hardware anti-interference in single chip microcomputer system
Commonly used methods for hardware anti-interference of single-chip microcomputer systems Practice The main factors affecting the reliable and safe operation of single-chip microcomputer systems mainly come from various electrical interferences inside and outside the system, and are affected by the system structure des
[Microcontroller]
PIC microcontroller CCS C language (#BYTE usage)
      #BYTE Syntax: #byte id=x id is a valid C identifier; x is a constant or a C variable; Purpose: If id is a known C variable, it will be located at address x. In this case, the original definition of the variable type will not be changed. If id is not a known C variable, then #byte id=x will create a new C v
[Microcontroller]
Brushless controller detection design based on speed regulation using microcontroller and PWM control method
introduction With the process of urbanization, the transportation distance where people live continues to expand. The popularity of electric vehicles that replace fuel vehicles and bicycles has greatly improved the utilization efficiency of power resources and promoted the healthy development of the national economy.
[Microcontroller]
Brushless controller detection design based on speed regulation using microcontroller and PWM control method
What is a single chip microcomputer? Classification of single chip microcomputers
What is a microcontroller?     A single-chip microcomputer is a complete computer system integrated on a single chip. On a small chip, there are most of the components required for a complete computer: CPU, memory, internal and external bus systems. Most of them now also have external memory. At the same time, they al
[Microcontroller]
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号