Si100x - General I/O
This page shows how to configure a Si100x microcontroller’s pins to standard I/O functions such as a digital input, digital output, and analog input.
Configuring A Digital Output
With Push/Pull
The following code sets channel P2.2 for use as a digital output
Channel P2.2 is then set high and low by writing the following code
With Open Drain
Open-drain allows for higher voltages to be present on the pin than with push/pull drive. However it cannot source current, so if you are switching a signal using an open-drain configuration you will notice the rise-time is much slower than the fall time (since the rise-time will be set by external pull-ups, if any). The code for configuring a digital output with push/pull procedure is followed, except that the bit in P2MDOUT
is cleared rather than set. So that it now becomes:
Configuring A Digital Input
The following code sets channel P1.7 for use as a digital input
Configuring An Analog Input
Setting a pin to an analog input disables all digital drivers and allows the pin to be used for an analog function such as the ADC. The analog input configuration is the lowest power state for a pin, and it is recommended to set any unused pins to analog inputs when designing a low power circuit. The last two lines of code are not strictly necessary, but are good practice. This code uses channel P2.2 as the example pin.
Macro For Specific Pin Addressing
Keil allows a method of writing a function macro so that from that point on you can address a pin directly (as opposed to above where we were modifying the whole byte). The first step is to define a function typically called SBIT
(although it could be named anything)
This function takes a word to represent the pin, the special function register that controls the entire port that the pin is on, and the pin number on that port. The next trick is to associate a word with a pin, and use the sbit function as a macro to replace the word whenever you use it in the code.
Now the pin can be addressed with just the keyword, LED1. For example,