Shop OBEX P1 Docs P2 Docs Learn Events
PBASIC to Prop C conversion: DIRH and OUTH — Parallax Forums

PBASIC to Prop C conversion: DIRH and OUTH

John KauffmanJohn Kauffman Posts: 653
edited 2013-11-13 11:03 in Propeller 1
I'm having problems finding help on this conversion from PBASIC to Prop C. What are search terms to find info on this?

DIRH %11111111 ‘set high pins (8-15) as outputs
DIRL %00000000 ‘set low pins (0-7) as inputs
Equivalent in Prop C?

OUTH %11111111 ‘set high pins (8-15) to output HIGH
OUTL %00000000 ‘set low pins (0-7) to output LOW
Equivalent in Prop C?

- Thanks

Comments

  • SRLMSRLM Posts: 5,045
    edited 2013-11-13 07:43
    On the Propeller the 32 bit DIRA register controls the pin direction, the 32 bit INA register is for reading inputs, and the 32 bit OUTA register is for setting outputs.

    If you're interested in working with a single pin or seeing examples of how to use these registers then there are a number of different options for doing so (propgcc, simpletools, or libpropeller).
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-11-13 08:40
    Try this. It should work OK unless I missed something.
    #include <propeller.h>
    #define DIRL(val) DIRA = (DIRA & 0xffffff00) | ((val) & 0xff)
    #define DIRH(val) DIRA = (DIRA & 0xffff00ff) | (((val) & 0xff) << 8)
    #define OUTL(val) OUTA = (OUTA & 0xffffff00) | ((val) & 0xff)
    #define OUTH(val) OUTA = (OUTA & 0xffff00ff) | (((val) & 0xff) << 8)
    
    int main()
    {
        DIRH(0b11111111);
        DIRL(0b00000000);
        OUTH(0b11111111);
        OUTL(0b00000000);
        return 0;
    }
    
  • John KauffmanJohn Kauffman Posts: 653
    edited 2013-11-13 10:48
    Thanks guys. If I correctly understand Dave's and the three links SRLM, the shortest and easiest technique uses about 8 lines of code.

    Transition for H.S. students & hobbyists from STAMP/PBASIC to PROP/C looks out of reach. A one-liner in PBASIC when converted to Prop C means ten lines of code, including an understanding of bitwise OR and bitwise left shift. That is a pretty big jump.
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-11-13 10:58
    The definitions for DIRL, DIRH, OUTL and OUTH can be hidden in a header file, so the programmer would then only need to write 1 line of C code for every line of STAMP/PBASIC code. The Prop could be made as easy to program as the Stamp with the appropriate header files and libraries.
  • SRLMSRLM Posts: 5,045
    edited 2013-11-13 11:03
    It's not as bad as that. Dave Hein's solution is good, and is a 1:1 replacement for what you posted. The students can just copy the #defines to the top of their program and never have to look at them again. You could even put it in a library that you distribute to your students. From the student perspective, there is absolutely nothing different or new that they have to learn (over the BS2 material).

    And if all you want is a single pin then then you can use any of the three links that I posted and do that in one or two lines.

    Note that Dave's solution only works on the lower 16 pins (for a match to the BS2 commands). It's easy enough to extend to the upper 16 pins, but you'd have to choose your own names.
Sign In or Register to comment.