I / O control is the most basic and core thing for the microcontroller, in fact, in addition to the AD DA conversion. Most other things I/O can do. I/O control is simple but can be varied.
I/O is the English abbreviation of Input/Output, which is translated as input/output.
I/O is the most basic thing for the MCU. In addition to the AD and DA conversion, most of the I/O can be done.
If you are new to electronics, then you better know what the I/O port can do. A perceptual understanding is very helpful for your study. The I/O port outputs a high (low) level that can be used to illuminate an LED. It can be connected to a relay to turn on the motor to turn on the sound. Open a lot of things, can also be used for communication and so on. Entering a high (low) level can be used to detect buttons, detect infrared inputs, detect signals, and more.
2. Correspondence between the TRISA register and the io port:
First look at the schematic of the next chip. Pay attention to the mouths of RA5~RA0
Look at the direction control register TRISA of the RA port
Look at the RA port data control register PORTA
It can be seen that the second pin RA5 in the chip schematic and the TRISA5 bit in the TRISA register correspond to the RA5 bit in the PORTA register, and RA4~RA0 correspond to this.
This means that the TRISA5 bit in the TRISA register and the RA5 bit in the PORTA register control the RA5 port of the second pin.
3. How to control the I/O port?
In fact, controlling the microcontroller, is to control the various bits on the register, set the high setting to low. It's like giving you a button with 8 machines. Then according to the instructions, press or release the corresponding button according to your needs to get the function you want. But we are not using the hand but the C language to press and release these buttons.
The TRISA register is the direction control register. Is to control the I / O input or output. For example, the TRISA5 bit in the TRISA register is set to 0. The RA5 port is set to 1 and the RA5 port is input.
4, the specific implementation of C language:
Several ways to set the RA5 port as input
The first type of TRISAbits.TRISA5=1; //Simple and clear, it is convenient to only affect one bit to set a single I/O.
The second TRISA |= 0x20; / / is not clear enough, only affect one bit
The third type of TRISA = 0x20; / / is not clear enough, affecting other bits, it is convenient to set multiple I / O
Several ways to set the RA5 port to output
The first type of TRISAbits.TRISA5=0;
The second type of TRISA &= ~0x20;
The third type of TRISA = 0x00;
The PORTA register is a data control register. If it is the output state: the RA5 bit in the PORTA register is 0, then the RA5 port outputs a low level, and the RA5 bit in the PORTA register is 1 the RA5 port outputs a high level.
If it is the input state: the RA5 bit in the PORTA register is 0, indicating that the RA5 port is currently low, and the RA5 bit in the PORTA register is 1, indicating that the RA5 port is currently high.
Example program:
If an LED is connected to the RA5 port. How will we light him?
/*
The development environment is MPLAB X IDE, the chip model is PIC16LF1823
*/
#include //Head file
__CONFIG(FOSC_INTOSC&WDTE_OFF&PWRTE_ON&MCLRE_OFF&CP_ON&CPD_OFF&BOREN_ON
&CLKOUTEN_OFF&IESO_ON&FCMEN_ON);//This is going to the previous line.
__CONFIG(PLLEN_OFF&LVP_OFF) ;//Configuration bit
Int main(int argc, char** argv) {
ANSELA=0; / / set the RA port to a digital port,
TRISAbits.TRISA5=0;//Set RA5 as output
PORTAbits.RA5=1;//Set the output high level to light the LED
While(1);//Program in this infinite loop
}
Header file: As long as the #include compiler is in the program, it will automatically find the header file of the corresponding model. The header file defines the address of each register, the address of the bit, and so on.
Configuration bit: This is very important even if the program does not have any error configuration bits that are not configured. How to configure it can be seen (based on the MPLAB X IDE configuration bit settings).
Analog digital port: When using the I/O port, make sure that the corresponding I/O port is set to digital port.
MARSHINE splice sleeve straightener serves to straighten the bent splice sleeve with its specification of LGJ720 or below after the crimping process. This product weighs 12kg, and its maximum straightening force reaches 20kN. The item number is 17211.
Ningbo MARSHINE Power Technology Co., Ltd. is a professional engaged in the development, design and manufacture of power engineering construction equipment and tools.
MARSHINE company produces circuit construction tools, including foundation construction, tower group lap. Wiring structure. Cable construction, cable construction, mobile knife mill, insulated overhead cable and high voltage cable stripper, all kinds of aluminum alloy pull rod, guide rail, grounding device, high strength shackle, ratchet wrench and pointed wrench, double hook tight line device, lifting pulley, nylon wheel and aluminum wheel, punching machine ect.
MARSHINE continues to carry forward the enterprise spirit of "integrity, development, innovation" and strive for the prosperity and development of the electric power industry.
Welcome to contact MARSHINE and reach cooperation, thank you!
Splice Sleeve Straightener,Splicing Sleeve Straightener,Fusion Splice Sleeves
MARSHINE , https://www.puller-tensioner.com