Shop OBEX P1 Docs P2 Docs Learn Events
pin direction example in prop c — Parallax Forums

pin direction example in prop c

I have been struggling with the pin direction commands in prop C.
I want to take this from SPIN:


dira[CS_PIN]~~
dira[WR_PIN]~~
dira[RS_PIN]~~
dira[REST_PIN]~~
dira[14..7]~~
dira[disp_pin]~~

to propeller C.
The information in the propgcc manual is not forthcomming

Any suggestions wold help. I have tried the suggestions in:
https://learn.parallax.com/tutorials/robot/elev-8/io-elev-8-flight-controller/pin-control-registers

copied and pasted the stuff there but got error messages.

Thanks

Looking in the

Comments

  • twm47099twm47099 Posts: 867
    edited 2018-03-11 01:13
    If you are using SimpleIDE for propC, there are 2 libraries that deal with pins.
    They are both documented at the following link:

    https://cdn.rawgit.com/parallaxinc/propsideworkspace/master/Learn/Simple%20Libraries%20Index.html

    simpletools.h is as its name suggests the easy way. I have copied the IO pin functions and brief descriptions below.

    The other library is propeller.h. For the pins the propeller.h library does not use functions. You enter the 32 bit pin values into:
    DIRA
    INA
    OUTA
    
    

    The advantage of propeller.h is that it may be a more familiar way for people used to spin or PASM, and it executes faster than the simpletools.h functions.

    Hope this helps,
    Tom M.
    From simpletools.h
    
    void 	high (int pin)
     	Set an I/O pin to output-high.
    void 	low (int pin)
     	Set an I/O pin to output-low.
    int 	input (int pin)
     	Set an I/O pin to input and return 1 if pin detects a high signal, or 0 if it detects low.
    
    More Individual I/O
    unsigned int toggle (int pin)
     	Toggle the output state of the I/O pin.
    unsigned int reverse (int pin)
     	Reverse the direction of an I/O pin.
    unsigned int get_state (int pin)
     	Check the state of an I/O pin without setting it to input.
    unsigned int get_direction (int pin)
     	Check the direction of the I/O pin.
    unsigned int get_output (int pin)
     	Get I/O pin output state.
    void 	set_direction (int pin, int direction)
     	Set an I/O pin to a given direction.
    void 	set_output (int pin, int state)
     	Set I/O pin output register bit to either 1 or 0.
    
    Group I/O
    unsigned int get_states (int endPin, int startPin)
     	Get states of a contiguous group of I/O pins.
    unsigned int get_directions (int endPin, int startPin)
     	Get directions for a contiguous group of I/O pins.
    unsigned int get_outputs (int endPin, int startPin)
     	Get output settings for a contiguous group of I/O pins.
    void 	set_directions (int endPin, int startPin, unsigned int pattern)
     	Set directions for a contiguous group of I/O pins.
    void 	set_outputs (int endPin, int startPin, unsigned int pattern)
     	Set output states for a contiguous group of I/O pins.
    



  • JonnyMacJonnyMac Posts: 8,918
    edited 2018-03-11 02:12
    I think this will work -- as long as your pin constants are defined.
    void setup()
    {
      DIRA |= 1 << CS_PIN;
      DIRA |= 1 << WR_PIN;
      DIRA |= 1 << RS_PIN;  
      DIRA |= 1 << REST_PIN;
      DIRA |= 0xFF << 7;
      DIRA |= 1 << DISP_PIN;
    }
    
  • If you have Spin code that you want to see the C equivalent for, you can use the spin2cpp tool (or its GUI version spincvt) to do the translation for you. For example, for the Spin program:
    CON
      CS_PIN = 1
    
    PUB test
      dira[CS_PIN]~~
      dira[14..7]~~
    
    spin2cpp produces:
    //
    // automatically generated by spin2cpp v3.6.4 on Sat Mar 10 22:09:26 2018
    // /home/ersmith/Parallax/spin2cpp/build/spin2cpp --ccode foo.spin 
    //
    
    #include <stdlib.h>
    #include <propeller.h>
    #include "foo.h"
    
    #ifdef __GNUC__
    #define INLINE__ static inline
    #else
    #define INLINE__ static
    #define waitcnt(n) _waitcnt(n)
    #define coginit(id, code, par) _coginit((unsigned)(par)>>2, (unsigned)(code)>>2, id)
    #define cognew(code, par) coginit(0x8, (code), (par))
    #define cogstop(i) _cogstop(i)
    #endif
    
    void foo_test(void)
    {
      DIRA |= (1 << FOO_CS_PIN);
      DIRA |= (255 << 7);
    }
    

    The stuff inside the "#ifdef __GNUC__" block is fluff that allows the output to be compiled by Catalina as well as PropGCC, so you can ignore that. The interesting stuff is the foo_test() function, where you can see how to set DIRA the way Spin does.
  • Thanks for the help.
    I tried the method like the one Johnny Mac indicated but I got error messages. I will post it.
    Thanks to all.
    I will get back
  • BTW I am porting SPIN code or the ssd 1963 that I got fairly working in SPIN and going to Prop C. That is why I wanted to attempt it with the DIRA commands as it works in SPIN but not in C.
  • I tried the method like the one Jonny Mac indicated but I got error messages.
    Perhaps it's just the magic of Hollywood, but it compiles here....
    1920 x 1080 - 65K
  • I will give it a try
    thanks

  • See attached it did not compile. The errors are the same that I got originally.


  • David BetzDavid Betz Posts: 14,511
    edited 2018-03-11 17:53
    pilot0315 wrote: »
    See attached it did not compile. The errors are the same that I got originally.

    Remove the "=" in the #define statements:
    #define RD_PIN 6
    #define CS_PIN 15
    #define WR_PIN 5
    #define RS_PIN 4
    #define REST_PIN 16
    #define disp_pin 19
    #define backl 3
    
  • Just did not see that.
    Thanks
  • Just did not see that.
    Sometimes compiler warnings can be tricky. I'm having to learn the Arduino so that its users can connect to Stamp- and Propeller-based EFX-TEK products, and I often shake my head at the warnings and error messages it spits out.
  • David BetzDavid Betz Posts: 14,511
    edited 2018-03-11 20:13
    JonnyMac wrote: »
    Just did not see that.
    Sometimes compiler warnings can be tricky. I'm having to learn the Arduino so that its users can connect to Stamp- and Propeller-based EFX-TEK products, and I often shake my head at the warnings and error messages it spits out.
    While I agree that that is often true, in this case the error messsages seem to point directly to the problem. They mention a problem with '='.

  • Unhelpful error messages are what I have liked least about every C compiler I have ever tried to use.
Sign In or Register to comment.