3 Replies Latest reply on May 8, 2011 11:51 PM by jim.greenhaw

    Setting a bit

    shawn.upton

      I wanted software control over a bit (just goes to the LED, on the CY8CKIT-001).  I see in the .c file for the pin/port a "write" command ("LED_Write(uint8 value)"--I called the pin "LED", as all I wanted to do was to flip the LED off and on).  However, if I try to build with just a pin in the TopDesign.cysch, I get errors.  So I put on a ControlRegister, and put the pin onto that.

         

      I sorta get this, sorta don't: if I do a build, and get the errors, I see the command to write to the pin, which makes me think I should be able to do a direct write.  Then again, I can see why I would need to go through a control register--it would represent a physical location for the code to access, a layer or firewall if you will.  Or am I missing something--can I write directly to the pin, w/o the ControlRegister?

         

      Shawn

        • 1. Re: Setting a bit
          robert.teufel

          Shawn,

             

          I am not quite sure I understand your question but I will give it a shot. You can write to a bit any time as long as it is actually just a bit in memory. If the "bit" is actually a port pin it is different. The port pin has the options of being an input or an output, you need to make that disctinction. As an output it can still be in different modes such as open drain or Push/Pull, another decision for you to make... That's why you need to control a pin with a control register. For a bit in memory there is no such need. Did I get your question right?

             

          Robert

          • 2. Re: Setting a bit
            shawn.upton

            Close enough for me.  I saw the write command, and thought it might be more simple than using a Control_Register.  Simple enough to use one of those, especially once I get these sheet connector symbols working.

               

            Thanks.

               

            Shawn

            • 3. Re: Setting a bit
              jim.greenhaw

              I have been dealing with a similar issue, and found that unchecking "HW Connection" on the pin configuration dialog will allow me to place a pin with nothing internal connected to it, and let me use the read and write functions on it.

                 

              There is a PSoC attribute that still hasn't sunk in for me yet. Even though you can patch various internal signals to any I/O pin that you want, these pins are still associated with an 8-bit port. I suppose the value of using a control register (instead of writing directly to a port pin) is that you could map a 4-bit control register to any 4 pins of choice, not necessarily on the same port. HOWEVER, if you look at the API code for this there is probably a bunch of bit-twiddling, masks and shifts going on, so it isn't "free." Even writing directly to the pin will create the same API code that you would need to write yourself to control a single bit of an 8-bit port.

                 

              I hope this is helpful... Jim