4 Replies Latest reply on Feb 1, 2016 2:31 AM by user_1377889

    psoc1,how to get a pin input value

    cao.jian

      psoc1,how to get a pin input value?

         

      select StdCPU and High Z Analog?

         

      What is StdCPUInput?

         

      Thank you!

        • 1. Re: psoc1,how to get a pin input value
          user_1377889

          Welcome in the forum!

             

          StdCPU means: the pin's logical value can be read by the CPU. To get a digital input pin set the drive-mode to High-Z.

             

          You read a pin by reading the complete port and mask out all unused pins by

             

          PRTnDR & (0x01 << PinNumber) where n is the port number 0,1 etc and PinNumber is 0..7

             

           

             

          Bob

          • 2. Re: psoc1,how to get a pin input value
            cao.jian

            Thank you Bob!

               

            But I fail again. I set P7 stdcpu stong,P8 stdcpu High Z Analog,P9 stdcpu stong.And I connect P7 and P8,then P9 havent set high final.I can measure P7 is high. Please help.

               

            My code:

               

            #include <m8c.h>        // part specific constants and macros
            #include "PSoCAPI.h"    // PSoC API definitions for all User Modules
            #include "PSoCGPIOINT.h"
            #define P7_1() P7_Data_ADDR |= P7_MASK
            #define P7_0() P7_Data_ADDR &= (~P7_MASK)
            #define P8_1() P8_Data_ADDR |= P8_MASK
            #define P8_0() P8_Data_ADDR &= (~P8_MASK)
            #define P9_1() P9_Data_ADDR |= P9_MASK
            #define P9_0() P9_Data_ADDR &= (~P9_MASK)
            #define Get_P8() P8_Data_ADDR & P8_MASK

               

            void Delay_ms(int x)
            {    

               

                int y;
                int z;
                
                for (y=0; y<x; y++)
                    for (z=0; z<51; z++)    //1ms delay when CPUCLK=24MHz
                    {
                        z++;z--;z++;z--;
                    }
            }

               

            void main(void)
            {
                // Insert your main routine code here.
                P7_1();
                while(1)
                {
                    if(Get_P8())
                    {
                        P9_1();
                    }else
                    {
                        P9_0();
                    }
                    Delay_ms(100);
                }

               

                
            }

            • 3. Re: psoc1,how to get a pin input value
              cao.jian

              By the way,I am using cy8c20446.

                 

              Thank you!

              • 4. Re: psoc1,how to get a pin input value
                user_1377889

                Please do not provide code snippets only. Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
                Designer->File->Archive Project...
                and attach the resulting file.

                   

                Are you trying to learn PSoC? If so, I would suggest you to use a (more modern) prototyping kit which allows you to debug your program.

                   

                 

                   

                Bob