View previous topic :: View next topic |
Author |
Message |
jahan
Joined: 04 Apr 2005 Posts: 63
|
How to ShiftOut and ShiftIN in CCS? (Like PicBasicPro) |
Posted: Mon May 23, 2005 8:52 am |
|
|
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
|
|
Posted: Mon May 23, 2005 10:56 am |
|
|
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
|
does ShiftIN works the same way? |
Posted: Mon May 23, 2005 1:02 pm |
|
|
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
|
|
Posted: Mon May 23, 2005 1:57 pm |
|
|
Take a look at 74165.c in your examples folder |
|
|
bfemmel
Joined: 18 Jul 2004 Posts: 40 Location: San Carlos, CA.
|
|
Posted: Mon May 23, 2005 2:21 pm |
|
|
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
|
|
Posted: Mon May 23, 2005 2:46 pm |
|
|
You are correct. My mistake. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed May 25, 2005 1:09 pm |
|
|
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
|
|
Posted: Tue Oct 18, 2005 7:05 am |
|
|
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
|
|
Posted: Tue Oct 18, 2005 7:10 am |
|
|
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
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
|
|
Posted: Thu Oct 20, 2005 3:43 pm |
|
|
That code don't work right either.
If i send 0b10100100 I get 0b10100101. |
|
|
Futterama
Joined: 17 Oct 2005 Posts: 98
|
|
Posted: Thu Oct 20, 2005 5:44 pm |
|
|
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 |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Oct 20, 2005 6:50 pm |
|
|
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
|
|
Posted: Fri Oct 21, 2005 2:49 am |
|
|
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. |
|
|
|