View previous topic :: View next topic |
Author |
Message |
bwgames
Joined: 21 Jul 2005 Posts: 36
|
Capturing stream data from a pin? |
Posted: Thu Jul 21, 2005 5:15 am |
|
|
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](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Jul 21, 2005 5:56 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
bwgames
Joined: 21 Jul 2005 Posts: 36
|
|
Posted: Thu Jul 21, 2005 6:08 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Jul 21, 2005 6:16 am |
|
|
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);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|