Shop OBEX P1 Docs P2 Docs Learn Events
Managing I\O's — Parallax Forums

Managing I\O's

ThePenguinMasterThePenguinMaster Posts: 89
edited 2007-06-19 20:21 in Propeller 1
hey guys,
·· hey this might be a simple question to some, but i need a little help managing my ins and outs.. im connecting the prop to a hard drive and all is well, but im unsure of how toget and set all the data properly. now i know thewres a better way to do it then typoing in all the pin numbers everytime, and i know i can declare and set a variable and then call ina[noparse][[/noparse]x], but im looking at some other chips and the language and im a little confused as to how they do it.

it looks like i should be able to do this:

con
·LowByte = $FF·········'ports 0-7
·HighByte = $FF0000· 'ports 16-23

·DataCommand = $EC

then i should be able to set the command to thease pins without effecting 8-15 or any of the others right? also i need to read from a specific range of pins... id rather not do the whole "ina[noparse][[/noparse]0..7]"

so for input can·i just say:
x:=ina[noparse][[/noparse]highbus]

or will that not work? any help would be mutch appreciated!
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-16 14:47
    You can say "x := ina[noparse][[/noparse] 7..0 ]" to read I/O pins 0 to 7 (with 0 the least significant bit). If you happen to have the bits reversed, you can do
    "x := ina[noparse][[/noparse] 0..7 ]" and I/O pin 7 will be the least significant bit. You can do this for any sequential block of pins. It also works for outa and dira like
    "outa[noparse][[/noparse] 7..0 ] := x". You can use constant names for the bit numbers for clarity, but there's no way to name a group of I/O pins. You could use the whole ina register and a named mask like
    "x := ina & LowByte" and you can combine these terms like in
    "x := ((ina & HighByte) >> 8) | (ina & LowByte)".

    Post Edited (Mike Green) : 6/16/2007 2:52:07 PM GMT
  • ThePenguinMasterThePenguinMaster Posts: 89
    edited 2007-06-16 15:22
    ok sorry about that.. i really didnt finish the question lol,
    after this section:

    con
    LowByte = $FF 'ports 0-7
    HighByte = $FF0000 'ports 16-23

    DataCommand = $EC


    could i call a line like this or something like it? i know there was an sta() function or something they could use to acess the port a register directly maybe i could use that.. but heres what im trying to do.. or well, something like it..

    outa[noparse][[/noparse]highbyte]:=datacommand

    highbyte are pins 16-23 and i dont want to effect the lower pins, or higher pins while doing this transaction..
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-16 16:39
    You can do: outa := (outa & !HighByte) | (datacommand << 16)
    or you can do: outa[noparse][[/noparse] 23..16 ] := datacommand
    The latter assumes that I/O pin 16 is the least significant bit.
  • ThePenguinMasterThePenguinMaster Posts: 89
    edited 2007-06-19 19:32
    now in this situation i dont have to worry about it resetting or interfering with the lower pins right? like if i was listening for input on the lower or higher pins of the chip and i used a mask like you demonstrated? heres what i mean:

    well say pins 0-7

    pins 0 - 3 are inputs, pins 4-7 are outputs,

    using a mask of 11110000 will not effect the pins 0-3? (basically outputting to the 4 pins)

    i know this may seem rather simple, i just dont want to wright a whole program relying on a concept that i may not fully understand. id do some experiments with my chip, but i dont want to pull it out of the project for that just yet.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-19 20:09
    I don't know precisely what sequence of instructions is used to implement "outa[noparse][[/noparse] msb..lsb ] := value", but it has been described as not affecting the remaining bits of OUTA. The way the cog processor is constructed, the two operands (source and destination) are fetched, some result is computed, and the the result is written back to the destination, so all instructions that store a result will store the result in the full 32-bit destination register. On the other hand, a variety of instructions will leave some of the result bits unchanged and these unchanged bits will be written back to the destination.

    Complicating this is the fact that INA always represents the state of the I/O pins no matter what is in the OUTA or DIRA registers. When you set INA to some value, you are not affecting the input register. You're changing a "shadow register". This is part of the reason why you can't use INA as a destination address for an instruction. In that case, you're actually referencing the "shadow register" which does exist in the hardware and can be used in this way if you're desperate for an extra memory location in the cog.

    If the corresponding DIRA bit is a zero (indicating an input I/O pin), the state of the OUTA bit doesn't matter to the I/O circuitry.

    Does this help?
  • ThePenguinMasterThePenguinMaster Posts: 89
    edited 2007-06-19 20:21
    yes! that exactally awnsers my question! and then some.. lol thanks mike, i really appreciate the help. knowing that i think i have a pretty good idea of how to set this whole thing up. im just so used to looking at somem of the code people made for other chips that have multiple ports and they can group them togather better.. where it feels like im mixing them togather. but anyways, thank you for your help
Sign In or Register to comment.