Shop OBEX P1 Docs P2 Docs Learn Events
How to access the input an output register bits using C — Parallax Forums

How to access the input an output register bits using C

RudyCRudyC Posts: 6
edited 2008-12-30 02:36 in Propeller 1
What is the most effective way of accessing several outputs or inputs of the PROP chip using the imagecraft C compiler?· I have tried several ways, I used the·blinkLed.c with only one output and had·expected results.· I then modified the code to only blink 1 led on my demo board but, I didn't get good results when I added another output.· I tried creating a structure, but don't know what I am doing wrong.· I hope this is an easy one for one of you, because I am trying to communicate with a DS1620 using the C code.

Comments

  • jazzedjazzed Posts: 11,803
    edited 2008-12-28 18:31
    Try this ?
    
    #include <propeller.h>
    
    void main(void)
    {
      int val;
      DIRA |= 0x5555; // set even number bits to outputs
      OUTA |= 0x5; // set bit 0 and 2 high  
      OUTA &= 0x4; // set bit 2 low 
      CLR(val, 0); // clear bit 0
      SET(val, 0); // set bit 0
      FLIP(val,0); // flip bit 0
      val = INA; // get input from odd bits + state of output bits
    }
    
    
    

    Bit numbers were wrong in CLR/SET/FLIP sorry. Corrected now.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Post Edited (jazzed) : 12/28/2008 9:24:23 PM GMT
  • RudyCRudyC Posts: 6
    edited 2008-12-28 19:58
    I had success playing with the Or then Anding of value in the OUTA. I had some confusion on what the SET, CLR, and FLIP functions were doing.· I have the demo board that I am working with so I had to move all of the values up to 16 through 23 to show on the LED's.· Thanks for the help
  • jazzedjazzed Posts: 11,803
    edited 2008-12-28 21:19
    There is a manual that comes with ICC, but I'm not sure where to find the Propeller support function/macro API. Attached is an HTML API reference that may help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • RudyCRudyC Posts: 6
    edited 2008-12-29 02:54
    After looking at your example and the manual that you sent and playing with the example. I believe I understand what I need to do with this. My little project has a matrox display on bits 0 and 1 that is working off of the serial functions from Steve Denson and a driver that I made for the formatting of the display, and characters from the keyboard. I also want to have 3 different temperature sensors reading an outdoor,indoor, and flu temperature. For the in/out temp sensors I am trying to use the DS1620 chips and duplicate the functions for the DS1620 that are in spin code. I wanted to use bits 2,3, and 4 for one of the temp sensors. This made it necessary for me to toggle bits 2,3, and 4 independent of 0 and 1. To do this I think I will need to read the INA register at the beginning of the project, I can then use the SET, CLR, and or FLIP functions to toggle the 3 bits then load them back into the OUTA register for the command code serial string. Does this sound like I am on the right track? I was just hoping that I could use a struct. But, I think the 3 functions will get the same results for me. Thanks and please let me know of any more tricks I can use.
  • jazzedjazzed Posts: 11,803
    edited 2008-12-29 17:12
    Hi.

    The obex C FullDuplexSerial is the best C serial driver library to use if you don't mind using a Propeller COG (The alternative is the ASIO library). I believe you are on a fair track. A better way (for me at least) would be to use a different kind of command for changing up to 3 bits at once. SET/CLR/FLIP are one bit at a time. Consider this:

    
    // untested but should work
    #define BITS 0x1c
    // the long way
    void setBits(int newbits) {
      int var = INA;
      var &= BITS;
      var |= newbits;
      OUTA = val;
    }
    // alternatively ...
    void setBits(int newbits) {
      OUTA = (INA & ~BITS) | newbits;
    }
    
    
    



    I hope you get a chance to share DS1620 C library in obex when it is complete.
    Best of luck with your project.

    Steve

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • RudyCRudyC Posts: 6
    edited 2008-12-30 02:36
    I will try this routine.· I will also share my code as soon as it is complete.· It will not look as clean or as optimized as a lot of the code I have seen so far, but it·will be functional.· I appreciate your help with this.
Sign In or Register to comment.