View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
Will this statement work ?? |
Posted: Sat Dec 12, 2009 1:35 am |
|
|
Hi,
As per the code below , a high state on MMC_DI sets a bit while a low state clears the bit...correct ??
Code: | shift_left(in,1,input(MMC_DI)); |
Now I need to modify the above statement so that a high on MMC_DI should clear the bit, while a low state sets the bit value.
How do I do this ??
thanks
a |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 12, 2009 3:15 am |
|
|
Did you try a C bit inverting operator? |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Sat Dec 12, 2009 3:27 am |
|
|
Will this work ??
shift_left(in,1,!input(MMC_DI));
How to do a C bit inversion ??? |
|
|
Guest
|
Re: RE: |
Posted: Sat Dec 12, 2009 5:58 am |
|
|
Quote: | How to do a C bit inversion ??? |
Just ex. "bit inversio"
Code: | void Tproc1(){
int1 bit1;
int8 byte1;
bit1 =~bit1;
byte1 = ~(byte1&0x01)&~0x01;
} |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 12, 2009 8:11 am |
|
|
If you have a CCS compiler, you may want to check yourself.
Are you interested in programming or just chatting? |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
RE: |
Posted: Sat Dec 12, 2009 9:41 am |
|
|
Quote: |
Are you interested in programming or just chatting? |
I was busy working on the problem.
I tried it, it doesn't seem to work (but its possible I may be missing out something). First I want to know if the approach is right.
shift_left(in,1,!input(MMC_DI));
is correct or ...
shift_left(in,1,~input(MMC_DI));
I am trying to get an MMC card working, I am using the driver in PICC folder, mmc_spi.c.
The problem is that the MMC_DI pin is connected through a npn transistor (used for level shifting from 3.3 V to 5 V). A common emitter amplifier configuration.
So a high on MMC_DI becomes a low on the amplifier output.
I am using a 18F4620 mcu. The system works when the MMC_DI pin is directly connected to the mcu pin a5. (in this case no modification to the driver code is required).
But I would like to use the amplifier instead of a direct connection, so I thought the code could be modified to invert the MMC_DI pin states.
arunb
Last edited by arunb on Sat Dec 12, 2009 9:52 am; edited 1 time in total |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sat Dec 12, 2009 9:50 am |
|
|
The first is the correct syntax for one bit (logical inversion) and gives correct result with CCS C, I think. The second may work as well. |
|
|
|