accessing hardware in the. Net Micro Framework

Source: Internet
Author: User
Tags port number

Summary: This article describes the simple and unique way of accessing hardware in the. Net Micro Framework. involves gpio,rs232 serial port and so on. A concise routine illustrates how to create an IO port and how to send the process of accepting data.

1.GPIO

Generally speaking, a MCU to communicate with the surrounding environment, the use of Gpio (General purpose Input/output) is undoubtedly the most common way. A gpio port that can be used for input or output after being initialized. A GPIO port can be described by two states-low (about 0 volts) and high (usually considered to be 3.3 volts of forward voltage).

In the. Net Micro Framework, the GPIO state is defined as a Boolean,false-> low, true-> high.

Tips here say Low (0 volts) and high (3.3 volts) are the voltages you actually add to the Gpio when you set the Gpio. And when considering the input of the general 1v below will be considered to be lower logic, 1.7~5.5 Volt is generally considered to be high logic. More than 5.5 of the voltage is not protected if the circuit is usually damaged your hardware.

1.1 Output

Under the Microsoft.SPOT.Hardware namespace, you can find the Outputport class, which inherits from the Microsoft.SPOT.Hardware.Port---a base class for describing Gpio.

Defining Outputport typically initializes a default value (True for high, false for low).

Outputport outputport = new Outputport (mypins.statusled, true);

/* The first parameter is enumerated type Microsoft.SPOT.Hardware.Cpu.Pin, but in order to make your code more flexible, it is highly recommended that you use your own encapsulated class to bind the Cpu's pin name and the GPIO port number. */

Then, Outputport's write and read methods can be used, the Write method controls the level state of the PIN, and the Read method returns the current state, which is the last set state.

The following example is used to let a custom pin's LEDs blink at a 1hz frequency (which is actually light and dark on each 0.5s).

Outputport outputport = new Outputport (mypins.statusled, true);
while (true)
{
thread.sleep;
Outputport.write (!outputport.read ()); Toggle Port
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.