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

How to ShiftOut and ShiftIN in CCS? (Like PicBasicPro)

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



Joined: 04 Apr 2005
Posts: 63

View user's profile Send private message Send e-mail

How to ShiftOut and ShiftIN in CCS? (Like PicBasicPro)
PostPosted: Mon May 23, 2005 8:52 am     Reply with quote

If I have a 2 wire device with CLK and DAT, can somebody show me a very simple example of sending data out using CCS C?

For example an LCD which only has CLK and DAT lines and I have want to show "Hello".
Thankx
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon May 23, 2005 10:56 am     Reply with quote

Code:

#define OUT_CLOCK   PIN_B1
#define OUT_DO      PIN_B2


void ShiftOut (int8 data)
{
  output_low(OUT_CLOCK);

  if((data&0x80)==0)
    output_low(OUT_DO);
  else
    output_high(OUT_DO);
  data <<= 1;
  output_high(OUT_CLOCK);
  output_low(OUT_CLOCK);
}
jahan



Joined: 04 Apr 2005
Posts: 63

View user's profile Send private message Send e-mail

does ShiftIN works the same way?
PostPosted: Mon May 23, 2005 1:02 pm     Reply with quote

Thank you for your posting.
It's very clean & clear.

can I ask you if ShiftIN works the same way but backward? and can you post a sample for ShiftIN?

Thankx again.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon May 23, 2005 1:57 pm     Reply with quote

Take a look at 74165.c in your examples folder
bfemmel



Joined: 18 Jul 2004
Posts: 40
Location: San Carlos, CA.

View user's profile Send private message Visit poster's website

PostPosted: Mon May 23, 2005 2:21 pm     Reply with quote

Quote:
Take a look at 74165.c in your examples folder

Actually, 74165.c is in the Drivers folder on my setup with 3.224 so it may be there for you too.

- Bruce
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon May 23, 2005 2:46 pm     Reply with quote

You are correct. My mistake.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed May 25, 2005 1:09 pm     Reply with quote

Just an FYI...

If you use

Code:

....................   if(!(data&0x80))
0028:  BTFSC  06.7
002A:  BRA    0032


instead of

Code:

....................   if((data&0x80)==0)
0028:  MOVF   06,W
002A:  ANDLW  80
002C:  XORLW  00
002E:  BNZ   0036


you will save two commands in case you are worried about speed. This was compiled for a 18F452.

Ronald
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Tue Oct 18, 2005 7:05 am     Reply with quote

Code:
#define OUT_CLOCK   PIN_B1
#define OUT_DO      PIN_B2


void ShiftOut (int8 data)
{
  output_low(OUT_CLOCK);

  if((data&0x80)==0)
    output_low(OUT_DO);
  else
    output_high(OUT_DO);
  data <<= 1;
  output_high(OUT_CLOCK);
  output_low(OUT_CLOCK);
}


How does this code work? I don't see how every bit is clocked out in this code, it doesn't loop as far as I can tell.
And I can't find information regarding this line: "data <<= 1;"
What does that line do?

I can't make it work :-/
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Oct 18, 2005 7:10 am     Reply with quote

It should be in a loop
Code:

#define OUT_CLOCK   PIN_B1
#define OUT_DO      PIN_B2


void ShiftOut (int8 data)
{
  int8 i;

  output_low(OUT_CLOCK);

  for (i=0;i<8;i++)
  {
    if((data&0x80)==0)
      output_low(OUT_DO);
    else
      output_high(OUT_DO);
    data <<= 1;
    output_high(OUT_CLOCK);
    output_low(OUT_CLOCK);
  }
}


Quote:
And I can't find information regarding this line: "data <<= 1;"
What does that line do?


same as

Code:
data = data<<1;


And if you don't know what << does, then it is shift left so the statement shifts 1 bit to the left. If you look at the driver files it will show you.
Guest








PostPosted: Thu Oct 20, 2005 3:43 pm     Reply with quote

That code don't work right either.

If i send 0b10100100 I get 0b10100101.
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Thu Oct 20, 2005 5:44 pm     Reply with quote

Sorry, my browser didn't log me in automatically.

I know what my problem was, I needed shift right, not shift left.

Thanks for you help anyways Wink
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Oct 20, 2005 6:50 pm     Reply with quote

Anonymous wrote:
That code don't work right either.

If i send 0b10100100 I get 0b10100101.

Get it where?
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Fri Oct 21, 2005 2:49 am     Reply with quote

Mark wrote:
Anonymous wrote:
That code don't work right either.

If i send 0b10100100 I get 0b10100101.

Get it where?


Mark, my mistake, thought I got that out of OUT_DO, but I was wrong.

I fixed it to work with my program, and I thank you for your help, no need to dig into it further.
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