Digital I/O Pins (PIC)

From Pigmeo - .NET/Mono/CLI (C#, VB.NET, C++/CLI, Nemerle...) for microcontrollers (PIC, dsPIC, AVR...)

This tutorial shows how to configure, read and write to digital input/output pins on PIC Microcontrollers.

First of all, you need to reference your PIC microcontroller, for example adding PIC16F716.dll (or the device you are using) to the list of References in Visual Studio Solution Explorer (or the development environment you are using). Then:

Contents


using Pigmeo.MCU;

Configuration (as input or outputs)

Setup all pins at a time

Ports.A.ConfigAll(DigitalIOConfig.Output);  //setup all PORTA bits as outputs
Ports.B.ConfigAll(DigitalIOConfig.Input); //setup all PORTB bits as inputs

Setup pins individually

Ports.B.ConfigPin(0, DigitalIOConfig.Input);
Ports.B.ConfigPin(1, DigitalIOConfig.Output);
Ports.B.ConfigPin(2, DigitalIOConfig.Output);

Setup all but one

//Configure all PORTA bits as inputs, but PORTA4 as output
Ports.A.ConfigAll(DigitalIOConfig.Input); //Note: for a small amount of time, PORTA4 will be an input
Ports.A.ConfigPin(4, DigitalIOConfig.Output);

Reading and Writing

Example #1

bool foo;
foo = Ports.A[2]; // Copy RA2 value to foo
Ports.A[3] = foo; // Copy foo value to RA3

Example #2

while(Ports.B[2] == true) {
	...
}