Screenshot 7 sets up the next Digital Discovery
To post comments on this article and find any associated files and/or downloads,
go to www.nutsvolts.com/magazine/issue/2017/06.
■ SCREENSHOT 2. This is just
a small portion of the code
that was generated
automatically by the MPLAB
Code Configurator. Here, I’ve
used macro code generated
by the Configurator to flip the
bits of the PIC16F18345’s RB5
and RB7 I/O pins.
The physical portion of the switch addition involved
adding a connection between the Discovery’s 28 I/O pin
and the PIC16F18345’s RA2
I/O pin. Screenshot 5 displays
the btn4 macros that were
generated by the Code
Configurator. With the help of
the MPLAB generated I/O
macros, let’s code our app to
illuminate both of the virtual LEDs when the virtual button
is depressed. Otherwise, the virtual LEDs are extinguished
when the button is released.
the PIC16F18345’s designations in Screenshot 3.
Virtual Buttons
Here’s the code we’ll stuff into the main.c file:
The Digital Discovery is also capable of virtualization
involving input devices such as pushbuttons. In
Screenshot 4, I’ve added a PIC16F18345 input on pin
RA2. I’ve also added a pushbutton input in Waveforms.
while (1)
{
// Add your application code
if(btn4_GetValue())
{
out_RB5_SetHigh();
out_RB7_SetHigh();
}
else
{
out_RB5_SetLow();
out_RB7_SetLow();
}
}
The Digital Discovery toggles its 28 output pin
depending on the state of the virtual pushbutton. I
configured the button state to be logically low when
the button was released.
■ SCREENSHOT 3. The Digital Discovery and Waveforms 2015
eliminate the necessity of pushing physical LEDs into a solderless
breadboard.
Capturing Pulses
■ SCREENSHOT 4. Adding an input for our virtual pushbutton is realized with only a couple of mouse clicks and
some minimal typing.
48 June 2017