|
|
View previous topic :: View next topic |
Author |
Message |
John Morley Guest
|
help with shift_right and shift_left |
Posted: Mon Jun 16, 2003 3:50 pm |
|
|
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
|
Re: help with shift_right and shift_left |
Posted: Mon Jun 16, 2003 4:39 pm |
|
|
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 |
|
|
|
|
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
|