
One other thing to notice here is the button in the lower left: “Datasheet”. Each of these components has a very
well written datasheet describing what it does, what
every
setting in the configuration window if for, how to use the
API, and how much of your available digital or analog resources you can expect it to consume.
The last thing to do before we can write some code is to assign these logical pins to a physical pin on the package.
To do this, open the
.cydwr
file from the workspace explorer on the left side of the window. You’ll get something
that looks like this:
Ignore the tabs along the bottom edge for now.
On the right side, there’s a list of pin objects, port pins, and physical pin numbers. If you don’t assign a pin to a
physical port, the IDE will do it for you. On the FreeSoC2, the user button is attached to port 1, pin 2, and the user
LED to port 6, pin 7, so let’s make those assignments now. Note how the “lock” box becomes checked when you
change the setting; that prevents the IDE from reassigning that pin.
You’ll also notice that many pins have some extra text associate with their port/pin information; for example, P1.2
is also labeled as “XRES:opt”. These are special functions that can be associated with the pin for improved
performance, rather than mandates that a given pin be used for a specific function.
Software
Let’s write some code!
The first thing to do is to create the necessary API files to support the hardware you placed in the schematic
earlier. To do that, choose the “Generate Application” item in the “Build” menu.
You’ll note that a bunch of new files pop up in the workspace explorer. These are the support files for the
components.
Don’t edit them.
They are, in fact, just standard C files, and you
could
rework them to fit your needs,
but the IDE can, and does, frequently regenerate those files, which would wipe out any changes you’ve made.