| |
SPL GPIO TristatePort programming - How to start GPIO TristatePort programming
1. TristatePort
- TristatePort is a combined port of InputPort and OutputPort.
- It works one of input port or output port.
- If "Active" propery is set as "true", it works as output port.
- If "Active" propery is set as "false", it works as input port.
- You can change "Active" property dynamically on the runtime.
|
|
|
2. Add "TristatePort" command
- Double click "TristatePort" item on the tree.
| |
TristatePort port8
/Pin:8
/InitialState:false
/GlitchFilter:false
/ResistorMode:PullDown
/Active:true
| |
|
- You can change "Pin" number as one of between 5 ~ 10.
- You can change "GlitchFilter" as true.
- You can change "ResistorMode" as one of among the "PullUp, PullDown, and Disabled".
- You can change "Active" as one of among the "true and false".
- In above sample, tristate port was set as "OutputPort" because its Active option was set as "true".
3. Add simple logic to change current state of port
- You can change the state of port only for the Output Port.
- You can use below methods to read and write state.
portname.Read()
portname.Write(bool state)
- Add lines to read and change current state of port.
| |
TristatePort port8
/Pin:8
/InitialState:false
/GlitchFilter:false
/ResistorMode:PullDown
/Active:true
s = port8.Read()
s = !s
port8.Write(s)
print "Port8's state was set as " + s
| |
|
4. Re-launch SPL emulator
- if SPL emulator is running, please terminate emulator.
- Press "F5" key to re-launch SPL emulator on the editor.
5. Send SPL script to emulator
- Click "Send Script" button to send SPL script to emulator
- Executed result will be shown as follows.
6. How to change the function of tristate port from output port to input port
- Continued in the next tutorial.
|