View previous topic :: View next topic |
Author |
Message |
janiga
Joined: 10 Apr 2006 Posts: 22
|
Help with INPUT bit read |
Posted: Thu Jun 15, 2006 3:38 pm |
|
|
Hello,
I am interfacing a card reader with my project and am having a bit of trouble figuring out how to store the data read into my variable.
I am reading data on two pins my question is, as my pin goes low indicating each bit read, how can I move the bits into my variable.
Example:
int readpin;
if (input(PIN_A0)==0)
readpin = bits read on input(PIN_A0);
For instance if I get four low pulses I want my variable to store a 0b00001000, if only two pulses then 0b00000010;
Thanks! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 15, 2006 3:51 pm |
|
|
Look at the CCS example files in which they do software SPI.
Here's part of the code from the 25640.C file. They want to
read 8 bits from the eeprom into the byte variable 'data'.
They create a for() loop that executes 8 times, once for each bit.
They use the input() function to read the eeprom pin, and they
use the shift_left function to shift the bits into the 'data' variable.
They are also do a short clock pulse after each read operation.
Code: | for(i=0; i<8; ++i)
{
shift_left(&data,1,input(EEPROM_DO));
output_high(EEPROM_CLK);
output_low(EEPROM_CLK);
} |
|
|
|
|