Implement simple application control with simple control levels

    What MCU does in most applications is input high and low level, output high and low level. It is through this simple control level to achieve most of the application control.

    What is an I/O port?

    What is I/O is whether IN/OUT is input/output.

    What can I/O do specifically?

    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.

    Correspondence between I/O port and register

    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.

    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.

    The specific implementation of the C language:

    Several ways to set the RA5 port as input

    The first TRISAbits.TRISA5=1; // Simple and straightforward, it only makes it easier to set a single I/O for one bit.

    The second TRISA |= 0x20; / / is not clear enough, only affect one bit

    The third TRISA = 0x20; / / is not clear enough, affecting other bits, setting up multiple I / O is more convenient

    Several ways to set the RA5 port to output

    The first type TRISAbits.TRISA5=0;

    The second TRISA &= ~0x20;

    The third 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

    &CLKOUTEN_OFF&IESO_ON&FCMEN_ON);//This should be placed on the previous line to __CONFIG(PLLEN_OFF&LVP_OFF) ;//Configuration bit int main(int argc, char** argv) {

    ANSELA=0;//Set all RA ports to digital port, TRISAbits.TRISA5=0; //Set RA5 as output PORTAbits.RA5=1; //Set output high level to light LED

    While(1);//Program in this infinite loop}

    Header file: as long as #include in the program

    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.


    Smart Motor Protector

    ARD series ARD2 series start timeout motor protector (hereinafter referred to as protector) can perform various conditions such as start timeout,over load, phase failure, unbalance, under load, ground/leakage, blockage, short circuit and external fault during motor operation. Protection, and SOE fault event recording function, convenient for on-site maintenance personnel to find the cause of the fault. Suitable for coal petrochemical,smelting, electric power, ships, and civil construction. The protector has RS485 remote communication interface, DC 4 ~ 20mA analog output, and PLC, PC and other control machines form a network system. Remote monitoring of motor operation.

    Ard2f 25 90l 132



    Founded in 2003, one of the few leading companies in China who provides various systematic solutions of power monitoring, power control, energy management and electrical safety for smart grid users. Substation automation system, power quality management system, energy management system, electrical fire monitoring system, IT distribution system for medical locations, precise distribution management system, FEPS power supply monitoring system, fire emergency lighting and evacuate indicating system, smart lighting control system and electric vehicle charging system.

    Start Timeout Motor Protector,Short Circuit Motor Protector,Residual Current Motor Protector,Motor Comprehensive Protection Device

    Jiangsu Acrel Electrical Manufacturing Co., LTD. , https://www.acrel.com.pk

    Previous Post: How to use spatial light modulator _ spatial light modulator function and application
    Next Post: New scalable graphics terminal boosts productivity for small applications – PanelView 5310 graphics terminal provides machine manufacturers with the right size HMI solution
    Home
    Recent Posts
    • A fixed ratio high voltage high power switched c…
    • How to implement LED lantern control with Dragon…
    • Coal chemical investment accelerates or welcomes…
    • What kind of microphone is the moving coil, capa…
    • Industrial Internet from the perspective of smar…
    • Let the product be full of human care, Foxconn w…
    • I understand the difference between scala and ja…
    • Create a smart life science and technology life …
    • TDK high voltage DC contactor has a freewheeling…
    • Introduction to PLC programming
    • Design scheme based on industrial control platfo…
    • Details timer and timer interrupts
    • AIoT ecosystem embarks on cloud resource sharing…
    • Analysis of the development trend and current si…
    • How does mcgs make buttons in the picture?
    • Summarize the concentration of ARM abort and giv…
    • Apple's “Unmanned Autonomous Navigation Sy…
    • Is the new energy vehicle safe? Tesla Global Rec…
    • Power sequencing is too important! What are the …
    • Plode measurement and control announced transfor…