Shop OBEX P1 Docs P2 Docs Learn Events
Chapter 4 — Parallax Forums

Chapter 4

Please Help

Write a single line of code that sets P8 through P12 to output-high.

Write a repeat loop that sets P0 through P7 to the opposite of the states sensed by P8 through P15. You may want to consult the Propeller Manual’s list of assignment operators for the best option

Comments

  • Homework?
    What language are you supposed to write this in?
    You should post the code you've tried so far, the results, and why they aren't what you expect.
  • Write a single line of code that sets P8 through P12 to output-high.
    If using Spin and native commands, this is not possible. One must write to the dira register to set inputs and outputs, and to the outa register to set output states. The Propeller manual only discusses Spin. In C, the set_outputs() function does the trick.
  • ErNaErNa Posts: 1,752
    I suppose, in tachyon forth peter will need half a line ;-)
  • JonnyMac wrote:
    If using Spin and native commands, this is not possible.
    Yes, it is. Think about it some more! :)

    But since it appears to be homework, I'm not going to give the answer, only to suggest that the OP peruse the Spin reference manual some more.

    -Phil
  • Those are Exercises 1 and 5 from page 67 of the Propeller Education Kit textbook.
    https://www.parallax.com/sites/default/files/downloads/122-32305-PE-Kit-Labs-Fundamentals-Text-v1.2.pdf

    The chapter doesn't tell you exactly how to do this but it has pieces that you can put together
    For the first one, can you find a line of code that sets a pin to output high, and then can you find code that changes more than one pin at a time?

    The second one is more complicated.
    First find code that makes a pin an input and then code that gets its value. You can then do this for multiple pins.
    Next, there is an OPERATOR that will turn this value into its opposite so look for it. Then use this value to change the output pins.
    Finally, look at how REPEAT loops are made and place the code for getting the input, reversing the input, and writing it to the output pins.

    The Propeller Manual has a whole section of Spin which is the language that is used in the Propeller Education Kit textbook.
    For example, look up the REPEAT command on page 188 and Operators start on page 143.
    https://www.parallax.com/sites/default/files/downloads/P8X32A-Web-PropellerManual-v1.2.pdf
  • JonnyMac wrote:
    If using Spin and native commands, this is not possible.
    Yes, it is. Think about it some more! :)

    But since it appears to be homework, I'm not going to give the answer, only to suggest that the OP peruse the Spin reference manual some more.

    -Phil

    Okay, you're right, Phil -- I'll blame my head cold, and that I don't like multi-assignment statements.

  • Yes this is homework, but in the professional world you get help from people who are better at it so you can learn and grow.
  • The Parallax community has a long-standing policy that we do not do students' homework for them. The suggestions made above are as much help as can be provided without seeing your work.

    If you would like to receive more in-depth advice and/or suggestions from our community members you will need to post your progress so far.
Sign In or Register to comment.