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 support@ccsinfo.com

How to read & output 32 bits using shift operator?

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



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

How to read & output 32 bits using shift operator?
PostPosted: Tue Mar 30, 2004 3:48 am     Reply with quote

Dear all,

1) How to write 32 bits through an adc pin using shift operator?

I have successfully output a byte using
output_bit(SDIO,shift_left(&insr,1,0));

Ex:
insr=0x64;

for(i=0;i<8;i++)
{
output_high(SCLK);
output_bit(SDIO,shift_left(&insr,1,0));
delay_us(1);
output_low(SCLK);
delay_us(1);
}

However, I failed to output 32 bits. I check with an oscilloscope & I got low for all the 32 bits. May I know do I make any mistake in my code?
Below is my code:
cmr[3]=0xC0;
cmr[2]=0x00;
cmr[1]=0x02;
cmr[0]=0x27;

delay_us(1);
for(i=0;i<32;i++)
{
output_high(SCLK);
output_bit(SDIO,shift_left(&cmr,4,0));
delay_us(1);
output_low(SCLK);
delay_us(1);
}

2) May I know how should I receive bit through an adc pin? Am I code correct? My code is as shown below...

for(i=0;i<32;i++)
{
output_high(SCLK);
delay_us(1);
output_low(SCLK);
shift_left(cmrrb,4,input(SDIO));
delay_us(1);
}

3) How should I access all the 4 bytes being read?
Is it cmrrb[3], cmrrb[2], cmrrb[1], cmrrb[0]...?


Thanks a lot:-)



Yours truly,
Einly
_________________
Einly
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Tue Mar 30, 2004 6:39 am     Reply with quote

1) You need to pass the address of the variable into the shift_left() function. Since cmr is an array, its name is already its address, so you'll need to change your code to:
output_bit(SDIO,shift_left(cmr,4,0)); //The & is not needed anymore

2) Please explain more what you are trying to do.

3) You can declare a int32 variable and use it:
int32 cmrrb;
shift_left(&cmrrb,4,input(SDIO)); //The & is needed here


By the way, if you are using the delay statements just to wait for the value of the pins to change, it is better to use delay_cycles(1) rather than delay_us(1), in case your crystal speed is (or will ever be) less than 4MHz.
Einly



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

replace int32?
PostPosted: Wed Mar 31, 2004 6:20 am     Reply with quote

Dear Haplo, Rolling Eyes

Hi, Thanks for your reply. Actually I'm using PCM 2.73 which doesn't support int32.

For your answer in question 3. What are the methods that you can suggest?

Wait for your good news.


Regards: Einly,

_________________
Einly
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Wed Mar 31, 2004 6:50 am     Reply with quote

The first ever PCM I used was PCM 3.112 so I'm afraid I'm not aware of the limitations in PCM 2.73. If it doesn't support int32 then you're probaby stuck with cmrrb[3], cmrrb[2], cmrrb[1], cmrrb[0]. Or if working with int16 variables are easier for you then you can try this code:

Code:
union Convert
{
    byte  Bytes[4];
    int16 Integers[2];
};

union Convert cmrrb;
shift_left(cmrrb.Bytes,4,input(SDIO));


Then cmrrb.Integers[0] and cmmrrb.Integers[1] will be it two int16 variables holding your data.

Or someone who has experience with PCM 2.xx may be able to suggest a better solution?
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