CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Capturing stream data from a pin?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bwgames



Joined: 21 Jul 2005
Posts: 36

View user's profile Send private message

Capturing stream data from a pin?
PostPosted: Thu Jul 21, 2005 5:15 am     Reply with quote

Hiya,

I'm looking to capture 12 incoming bits from an input pin, then output on the rs232.
i.e. :

capture 1st bit to an array(?)
function loops
capture second..
loops
capture 3rd etc..
when number of captures = 12, then output array to rs232 serially.

I looked at gets etc, but that only seems to work for an rs232 input, when I want to do it differently.

Any pointers?
Thanks Smile
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Jul 21, 2005 5:56 am     Reply with quote

How is the bit duration controlled? Do you supply a clock signal? Is a clock signal supplied to you? Or do you receive a start transition and everything else is based on a time period? If so, what's the time period?
bwgames



Joined: 21 Jul 2005
Posts: 36

View user's profile Send private message

PostPosted: Thu Jul 21, 2005 6:08 am     Reply with quote

I supply a clock signal, its part of a timing circuit.
Not on the coding computer at the moment so I can't paste, but its basically in the form of:

set t=1
while(true) //so it loops the following code permenantely
set clock pin high
read input bit t of 12
t=++t
if(t==12({t=1}
set clock pin low
delay_cycles(10)

what i want to put in there is if(t==12){output all the bits via rs232)};, but not sure what code to use to store the bits...

thanks
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Jul 21, 2005 6:16 am     Reply with quote

Here is one example on how to read in the data. It assumes the data is send msb first. It will return a 16 bit number that you can then send via RS232.

Code:

#define IN_CLOCK    PIN_B4
#define IN_DATA       PIN_B5


int16 read_bits(void)
{
  int8 i;
  int16 data;


  for(i=1;i<=12;++i)
  {
    output_high(IN_CLOCK);
    shift_left(&data, 2, input(EXP_IN_DATA));
    output_low(IN_CLOCK);
    delay_cycles(10);
  }
  return (data);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group