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 shift_right and shift_left

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







help with shift_right and shift_left
PostPosted: Mon Jun 16, 2003 3:50 pm     Reply with quote

Hi All,

I'm trying to use the shift_right and shift_left functions to communicate with a serially connected (CLK and DATA) external sensor. I first need to shift out an 8 bit command to the sensor, and then shift in a byte that comprises the requested data. I don't seem to be able to compile these functions, and I'm not sure where I'm going wrong. Here is the code:

// This shifts 8 bits out on SDATA, LSB first each time SCLK goes high. Value to be shifted out is contained in Cmd.
int Cmd = 0x05;
int i;

for(i=0;i<8;++i)
{
output_bit(SDATA,shift_right(Cmd,1,0));
SCLK = 1; // Clock high
SCLK = 0; // Clock low
}

AND

// This shifts a byte in on SDATA, MSB first each time SCLK goes high.
int8 databyte;
output_float(SDATA); //release the data line
for(i=0; i<8; ++i)
{
SCLK = 1; // Clock to high
shift_left(databyte,2,input(SDATA));
SCLK = 0; // Clock to low
}

BTW, SDATA and SCLK are defined above using:

//-----< Port location defines >-----
#byte port_a = 0x05
#byte port_b = 0x06


//-----< Pin defines >-----

//Interface Bit Definitions
#bit SDATA = port_b.0 // Data
#bit SCLK = port_b.1 // Clock

The PIC is a 16F84.

Thanks,

John
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515308
john cutler



Joined: 06 Sep 2003
Posts: 82
Location: Hot Tub, California

View user's profile Send private message

Re: help with shift_right and shift_left
PostPosted: Mon Jun 16, 2003 4:39 pm     Reply with quote

for(i=0;i<8;++i)
:= {
:= output_bit(SDATA,shift_right(Cmd,1,0));
:= SCLK = 1; // Clock high
:= SCLK = 0; // Clock low
:= }


Look in compiler manual - I think you need:

output_bit(SDATA,shift_right(&Cmd,1,0));

Also don't you want the clock to make it's transtion before and after the shifting?

Hope this is helpful

Jc
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515310
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