"STM32. Net MF Development Board Learning-02" Gpio Test

Source: Internet
Author: User

The example is simple, mainly the button and led lamp test, Red Bull and em-stm3210e buttons and LEDs are different, so targeted on both the PIN has been defined (this information, you can directly see the development Board corresponding to the schematic diagram, it is easy to get the definition of the relevant pin foot).

function is led every 1s on the lights out once, press the relevant key, then output key information from the debug port.

The core code is as follows:

#define REDOX//Red Bull Development Board
Using System;
Using Microsoft.spot;
Using Microsoft.SPOT.Hardware;
Using System.Threading;
Namespace Gpiotest
{
public class Program
{
Enum Gpio_names
{
PA0, PA1, PA2, PA3, PA4, PA5, PA6, PA7, PA8, PA9, PA10, PA11, PA12, PA13, PA14, PA15,
PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7, PB8, PB9, PB10, PB11, PB12, PB13, PB14, PB15,
PC0, PC1, PC2, PC3, PC4, PC5, PC6, PC7, PC8, PC9, PC10, PC11, PC12, PC13, PC14, PC15,
PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7, PD8, PD9, PD10, PD11, PD12, PD13, PD14, PD15,
PE0, PE1, PE2, PE3, PE4, PE5, PE6, PE7, PE8, PE9, PE10, PE11, PE12, PE13, PE14, PE15,
PF0, PF1, PF2, PF3, PF4, PF5, PF6, PF7, PF8, PF9, PF10, PF11, PF12, PF13, PF14, PF15,
PG0, PG1, PG2, PG3, PG4, PG5, PG6, PG7, PG8, PG9, PG10, PG11, PG12, PG13, PG14, PG15
};
public static void Main ()
{
#if Redox
Wakeup-pa0 tamper-pc13 user1-pa8 user2-pd3
cpu.pin[] Button_pins = new cpu.pin[] {(Cpu.pin) gpio_names. PA0, (Cpu.pin) gpio_names. PC13, (Cpu.pin) gpio_names. PA8, (Cpu.pin) gpio_names. PD3};
Led
cpu.pin[] Led_pins = new cpu.pin[] {(Cpu.pin) gpio_names. PF6, (Cpu.pin) gpio_names. PF7, (Cpu.pin) gpio_names. PF8, (Cpu.pin) gpio_names. PF9, (Cpu.pin) gpio_names. PF10};
#else
User-pg8 up-pg13 left-pg14 right-pg15 down-pd3 Sel-pg7
cpu.pin[] Button_pins = new cpu.pin[] {(Cpu.pin) gpio_names. PG8, (Cpu.pin) gpio_names. PG13, (Cpu.pin) gpio_names. PG14, (Cpu.pin) gpio_names. PG15, (Cpu.pin) gpio_names. PD3, (Cpu.pin) gpio_names. PG7};
Led
cpu.pin[] Led_pins = new cpu.pin[] {(Cpu.pin) gpio_names. PF6, (Cpu.pin) gpio_names. PF7, (Cpu.pin) gpio_names. PF8, (Cpu.pin) gpio_names. PF9};
#endif
interruptport[] button = new Interruptport[button_pins.length];
for (int i = 0; i < button. Length; i++)
{
Button[i] = new Interruptport (Button_pins[i], false, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeBoth);
Button[i]. Oninterrupt + = new Nativeeventhandler (program_oninterrupt);
}
Outputport[] led = new Outputport[led_pins.length];
for (int i = 0; i < LEDs. Length; i++)
{
Led[i] = new Outputport (Led_pins[i], false);
}

while (true)
{
for (int i = 0; i < LEDs. Length; i++)
{
Led[i]. Write (!led[i). Read ());
}
Thread.Sleep (1000);
}
}

static void Program_oninterrupt (UINT data1, uint data2, DateTime time)
{
Debug.Print (Data1. ToString () + ":" + data2. ToString ());
}
}
}

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.