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 CCS Technical Support

Help with INPUT bit read

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



Joined: 10 Apr 2006
Posts: 22

View user's profile Send private message

Help with INPUT bit read
PostPosted: Thu Jun 15, 2006 3:38 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 15, 2006 3:51 pm     Reply with quote

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);
   }
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