[SOLVED] How to define the line Rb0 to Rb6 = hex (x%10); // no Rb7 pin

Status
Not open for further replies.

mdamor01

Newbie level 6
Joined
Sep 5, 2018
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Bangladesh
Visit site
Activity points
95
Hi everyone,
Using MikroC Pro to multiplexing 7 segment the written program is
PORTB = Hex (x%10);
there PORTB means RB0 to RB7 total 8 pins are includes, but I want to use only 7 pins for 7 segments RB0 to RB6, and the pin RB7 as other O/P.
As like Rb0 to Rb6 = hex (x%10) and Rb7_bit = 0 or 1 or something else.

so how to define the line Rb0 to Rb6 = hex (x%10);
 

PORTB = (Hex (x%10) & 0xEF) | (y << 7);
will ensure RB7 is always zero from the 'x' value and is set or reset according to the 'y' value. The value of 'y' should be 1 or 0.

Brian.
 

PORTB = (Hex (x%10) & 0xEF) | (y << 7);
Hi Brian,
Using PORTB = (Hex (x%10) & 0xEF) | (y << 7); I can separately control (0 or 1) RB7 what i needed.
But the new problem is in this way RB4 (E bit for 7 segments) is always zero and thats why E bit of 7 segment (CC) is always off, Everything else okay. so now what can i do for RB4
 

ANDing the modulo division with 0xEF only forces RB7 to a zero, it does not change RB4 at all.
Either the value of 'x' is not allowing segment 'E' to be driven or you have RB7 connected to 'E' by mistake. Can you show your code and schematic around PORTB and the display please.

Brian.
 

Oops - my apologies !!!
It should be 0x7F and not 0xEF. Put it down to old age and an addling brain. In fact using 0xEF would have the effect of breaking RB4 and also messing up RB7.

Brian.
 
Oops - my apologies !!!
It should be 0x7F and not 0xEF. Put it down to old age and an addling brain. In fact using 0xEF would have the effect of breaking RB4 and also messing up RB7.

Brian.
 

Oops - my apologies !!! It should be 0x7F and not 0xEF.

Yes, PORTB = (Hex (x%10) & 0x7F) | (y << 7); is perfectly working what I needed. Thanks you.
Now, would u like to share with me the theory of [ &0x7F and y<<7 ] as i can teach others.
 

Simple - break it down into three parts:

1. Hex(x%10) does the hex conversion of the modulo 10 value of 'x'. I think this is a compiler library function, it isn't standard 'C'.
2. '& 0x7F' results in the value above being logically ANDed with 01111111 so bit 7 is always zero but the other bits are unchanged.
3. '| (y << 7)' means AND the result above with the value of 'y' shifted seven times to the right, so it is in bit 7 position.

Brian
 

@betwixt

You do all the hard work, I will just sit and nit pick :twisted:

3. '| (y << 7)' means AND the result above with the value of 'y' shifted seven times to the right, so it is in bit 7 position.

3. '| (y << 7)' means OR the result above with the value of 'y' shifted seven times to the left, so it is in bit 7 position.

I only help a fraction of the users that you do, so proof reading is easier. No disrespect intended.
 
I put my last mistake down to old age. I'm a day older now so things are even worse.
You are quite right and I should proof read before posting. I will now stand in a dark corner and contemplate my future for a while.
In my defence, I was writing a letter to the Prime Minister at the same time and also fighting to keep a cat off the keyboard!

The proof as I try to type this message:


Brian.
 
If it helps, I make similar mistakes all the time, but with far less reason. I am retired and have no pressures.

... plus it is natural to concentrate on the tough part of the problem, such that the easy mistakes get overlooked.

No need for you to proof read..... I will be happy to do it for you :smile:

Carry on the good work, and if I make corrections, please see it as helping (or tell me to stop if it doesn't help)

Cute cat. I miss having a cat, but sadly the wife is frightened by them

Regards,
 

Thank you very much both of you, my problem is solved and understand how it works. Carry on.

Regards.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…