INS OUT AND DIRS....omg
???O? ????
Posts: 18
Before you tell me to read the stamp manual or do a search. I can assure you that I am asking this very basic question as a last resort.· But I am sure this is also something I must understand before i move on, or worse smoke something.
So....here it goes.
What are ins, outs, and dirs, and how are they used?
Here is my understanding...this may or may not help.
INS. This are the actual state of the pin. can not be controlled internally.
Outs. This is the state at which you set the output
Dirs. this is setting each pin in or out.
Example.
OUTS=0
· DIRS=%1111111011111111
· '······ ··· fedcba9876543210
I have set all pins to out puts, except for pin 8. pin·8 is anout input. all output pins are low·until otherwise toggled in the code.
Am I close? am i hopeless?
can each out be addressed individually like the dirs?
is there a need to ever do anything with ins?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
DP
(ΜΟΛΩΝ ΛΑΒΕ[noparse];)[/noparse]
So....here it goes.
What are ins, outs, and dirs, and how are they used?
Here is my understanding...this may or may not help.
INS. This are the actual state of the pin. can not be controlled internally.
Outs. This is the state at which you set the output
Dirs. this is setting each pin in or out.
Example.
OUTS=0
· DIRS=%1111111011111111
· '······ ··· fedcba9876543210
I have set all pins to out puts, except for pin 8. pin·8 is anout input. all output pins are low·until otherwise toggled in the code.
Am I close? am i hopeless?
can each out be addressed individually like the dirs?
is there a need to ever do anything with ins?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
DP
(ΜΟΛΩΝ ΛΑΒΕ[noparse];)[/noparse]
Comments
The IO pins can be grouped in sets of 4
> [noparse][[/noparse]DIRA | INA | OUTA ]·- [noparse][[/noparse]DIRB | INB | OUTB ]·- [noparse][[/noparse]DIRC | INC | OUTC ]·- [noparse][[/noparse]DIRD | IND | OUTD ]
sets of 8
> [noparse][[/noparse]DIRL | INL | OUTL ]·- [noparse][[/noparse]DIRH | INH | OUTH ]
1 set of 16
>[noparse][[/noparse]DIRS | INS | OUTS ]
or as individual bits IN1 , OUT1 , IN2 , OUT2 etc
The INS· can be read at any time·. Before OUTS has any effect you must set the DIR register.
For example to set P0 P1 P2 and P3 to output and make P1 P2 and P3 high and P0 low simultaneously
This instruction is useful for controlling devices such as stepper motors and recently there was a post where this instruction was used to control traffic lights.
Also useful for reading binary inputs say from a binary switch.
Jeff T.
Thank you,
It sounds as if i was close. So if i set DirA= %1110 , i would be making pin3 an input. and then OUTA%1110 would not matter if written like OUTA%1111, pin 3 as an input can show only acutally state, and cannot be driven internally? which would be random unless pulled down or up correctly.
In reallty, this whole thing would be the same as
'intialize
output 0
out0 = 1
output 1
out1 = 1
output 2
out2 = 1
input 3
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
DP
(ΜΟΛΩΝ ΛΑΒΕ[noparse];)[/noparse]
So your notation "DirA= %1110" is setting P0 to an input and P1 through P3 to output. Apart from that you seem ok with it.
The DIR,IN and OUT instructions are a strong feature of PBasic.
Jeff T.
INS (and all of its named pieces like INA/B/C/D) reflects the actual state of the I/O pins regardless of whether they're input or output mode. It's normally only useful if the I/O pins of interest are input mode. In other words, the INS bits are always connected to their corresponding I/O pins.
OUTS (and all of its named pieces like OUTA/B/C/D) is a register and all 16 bits have a value you can set (and they stay at that value until changed by your program). You can test them if you want. They only affect the I/O pin if the pin is in output mode.
I really appreciate your help!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
DP
(ΜΟΛΩΝ ΛΑΒΕ[noparse];)[/noparse]