Pl 3150 and pl 3170 evaluation boards – Echelon Mini FX User Manual
Page 54

Mini FX User's Guide
41
LcdDisplayString(3, 0, “LED1 = “);
LcdDisplayString(2, 7, led ? “ON” : “OFF”);
LcdDisplayString(3, 7, sw ? “ON” : “OFF”);
}
6. Save your main.nc Neuron C source file.
7. Proceed to Step 3: Building the Device Application to compile and build your Neuron
C device application.
For more information on writing Neuron C code to implement your device’s functionality,
see Chapter 5, Developing Device Applications.
PL 3150 and PL 3170 Evaluation Boards
1. Enter the following directives:
//Required to compile Neuron C source code
#pragma num_alias_table_entries 0
//Run application even if device is uncommissioned
#pragma run_unconfigured
2. Add the following code that declares the I/O hardware for the SW1–SW8 buttons and
LED1–LED8 on the PL 3150/PL 3170 EVB (all the switches and LEDs on the Mini
Gizmo I/O board are connected through serial-in parallel-out and parallel-in
serial-out shift registers:
// Configure the I/O pins for SW1–SW8 buttons
IO_4 input bitshift numbits(8) clockedge(-) ioButtons;
IO_6 output bit ioButtonLoad = 1;
// Configure the I/O pins for LED1–LED8
IO_2 output bitshift numbits(8) ioLeds;
IO_1 output bit ioLedLoad = 1;
3. Add the following code that adds functionality to the Switch and LED I/O:
// Read state of MiniGizmo SW1 button
boolean GetButton(void)
{
unsigned debounce;
unsigned data;
data = 0xFF;
for (debounce = 0; debounce < 3; ++debounce) {
// Strobe:
io_out(ioButtonLoad, 0);
io_out(ioButtonLoad, 1);
// Sample data and debounce:
data &= (unsigned)io_in(ioButtons);
}
return ~data & 0x01;
}
// Set MiniGizmo LED1
void SetLeds(boolean led1)
{
unsigned data;
// Compute the data byte for the shift register:
data = led1 ? 0x01 : 0x00;
// Push inverted data into shift register:
io_out(ioLeds, ~data);