0

Hi all,
I have to interface an IC which is giving serial output bitwise from a single pin this pin is directly connected to a microcontroller i have to read this single pin to an unsigned int.
i have written a function something like that but its not working.

unsigned int read_val()
{
 unsigned char i;
 unsigned int data=0;//initially zero
 for(i=0;i<=15;i++)
   {
    data<<=1;
    if(PINB==1)
     {data|=1;}
     else
      {
      data|=0;
      }
   }
   return data;
   }

So the output of that function should be if pin is toggling as 1110110001100110
then data should contain data=0X EC66.
Thanks.

3
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by Ab000dy_85
0

Please explain what "not working" means in your situation.

Through the crystal ball I can see that you need to pace out the sampling. A single pin IO usually implies a time-based protocol.

0

I would change one thing and test, hope it works

unsigned int read_val()
{
 unsigned char i;
 unsigned int data=0;//initially zero
 for(i=0;i<=15;i++)
   {
    data<<=1;
    if(PINB==1)
     {data|=1;}
     else
      {
      data&=0;
      }
   }
   return data;
   }
0
    if(PINB==1)
     {data|=1;}
     else
      {
      data&=0;
      }
      data<<=1; // here maybe more logical
      // also a delay might be neccessary here
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.