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

high and low nibble
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nina



Joined: 20 Apr 2007
Posts: 111

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

high and low nibble
PostPosted: Sun Jul 04, 2010 9:09 am     Reply with quote

Hello everybody...

I am reading a byte from ds1307 and I don't know how to show first and second digit at different display 7 segments.

Ex: x = 00001101 (number 13)
how to show number 1 at one display and number 3 at second display.

I was thinking use operators >> and &.


Could someone give me some orientation, please.

Many thanks

nina
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Jul 04, 2010 11:49 am     Reply with quote

Code:

unsigned char x, y;
x = 00001101 (number 13);
    y = (x / 10) << 4; //  y = 1 shift left and leave in high nibble   
    y = y | (x % 10);  //  applying the module operator gives the rest, leave it in the low nibble,
                       //  ORed with the high nibble, and you get
y = 0b00010011 that is what you need, number 1 and 3 in two nibbles

You can write your own function to convert an HEX to BCD:

Code:

unsigned char hex2bcd (unsigned char x)
{
    unsigned char y;
    y = (x / 10) << 4;
    y = y | (x % 10);
    return (y);
}


Humberto
nina



Joined: 20 Apr 2007
Posts: 111

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

high and low nibble
PostPosted: Sun Jul 04, 2010 1:07 pm     Reply with quote

thank you humberto for your prompt answer..

could you please explain in details steb by step convertion?

y = (x / 10) << 4;

what is the result of x/10 ??

y = 0b00010011 that is what you need, number 1 and 3 in two nibbles

To be displayed 0b00010011 at two display of 7 segments, dont I need something like?

first = 0b00000001
second = 0b00000011

how to compare those variable with table below to be displayed at two 7 segments display?

char const segments[11]={
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01100111 // 9
};


many thanks

nina
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 04, 2010 1:31 pm     Reply with quote

Look at this CCS example file. It shows how to do it.
Quote:

c:\program files\picc\examples\ex_92lcd.c

They use the printf function to split an integer number into 4 separate
ASCII digits (bytes). Then they send the ASCII digits (bytes) to the
lcd_putc() function, one at at time.

The lcd_putc() function subtracts the ASCII bias ('0') from the byte to
get a number from 0 to 9. This number is used as an index into the
segment data array. They get a byte of segment data (for a digit)
and give it to the lcd_symbol() function, which displays the segments
on the LCD to show the digit.
nina



Joined: 20 Apr 2007
Posts: 111

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

nibble
PostPosted: Sun Jul 04, 2010 1:48 pm     Reply with quote

pcm programer

what i need is regarding to 7 segments display?
using lcd with printf we can convert to decimal...but what about seven segments display?

thank you

nina
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 04, 2010 1:53 pm     Reply with quote

Do you have a driver for your 7-segment display ?

If not, then post the manufacturer and part number of your display.
Also post a link to the website for the display.
nina



Joined: 20 Apr 2007
Posts: 111

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

nibble
PostPosted: Sun Jul 04, 2010 2:11 pm     Reply with quote

pcm programmer

Drive that I using to ds1307 is the one you post in this forum.
My question is...
As I read byte format from ds1307....how display at singles 7 segments display.

Ex.: 00001101 (13 decimal). How display at two different display 7 segments?

tks

nina
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Jul 04, 2010 2:15 pm     Reply with quote

Forgot to mention that the way I told you is valid for 0 to 99 unsigned integer only.
You do not need to compare, use the table that you posted of the segments array assigning the number
to be converted as the offset.
According to your example I assume that you need to represent only 2 digits, if not you need to use the way
proposed by PCM Programmer.

Code:


0b00111111, // 0  = 0x3F
0b00000110, // 1  = 0x06
0b01011011, // 2  = 0x5B
0b01001111, // 3  = 0x4F
0b01100110, // 4  = 0x66
0b01101101, // 5  = 0x6D
0b01111101, // 6  = 0x7D
0b00000111, // 7  = 0x07
0b01111111, // 8  = 0x7F
0b01100111  // 9  = 0x67

//         character               0    1    2    3    4    5    6    7    8    9
byte const Digit_segments[10] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x67};


Humberto
nina



Joined: 20 Apr 2007
Posts: 111

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

nibble
PostPosted: Sun Jul 04, 2010 3:49 pm     Reply with quote

humberto and pcm programmer

Sorry but I forgot to specify. When I said two 7-segments display, I want to say two single 7-segments display like:
http://www.cyberconductor.com/index.php/cPath/782_849?osCsid=06f790ccf32231487dd00b08f373f4f1

So I have two single 7-segments display. If I separate high and low nibble and compare with table posted, I'll have diffent number being displayed.

y = 0b00010011 number 1 and 3 in two nibbles

To be displayed 0b00010011 at two single display of 7-segments, don't I need something like?

first digit = 0b00000001
second digit = 0b00000011

If I compare with the table posted previously there is any 00000001 and 00000011.

tks

nina
nina



Joined: 20 Apr 2007
Posts: 111

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

nibble
PostPosted: Sun Jul 04, 2010 4:04 pm     Reply with quote

Another information is I am not using any decoder like 7445. 7 segments display are connected to pic.

tks

nina
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Sun Jul 04, 2010 4:33 pm     Reply with quote

Here LINK you'll get the idea how to connect 7 segment led displays.

And look at here: http://www.ccsinfo.com/forum/viewtopic.php?t=39731
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Jul 04, 2010 4:34 pm     Reply with quote

Quote:

To be displayed 0b00010011 at two single display of 7 segments, dont I need something like?

first digit = 0b00000001
second digit = 0b00000011

You have the following value in the varible y
y=0x0D // 00001101 (13 decimal)

Converted to BCD, you get this value
y =0x13 // 0b00010011 numbers 1 and 3 in two nibbles
That means that you have what you want: the full result in the same integer

All you need to do is:
Digit_DEC = y & 0xF0; // use the H nibble of y to shown the DECIMAL digit Digit_DEC=1
Digit_UNI = y & 0x0F; // use the L nibble of y to shown the UNITS digit Digit_UNI=3

Then use them directly to drive the 4 BCD lines inputs of the 7445, once each.

Humberto


Last edited by Humberto on Sun Jul 04, 2010 4:58 pm; edited 1 time in total
nina



Joined: 20 Apr 2007
Posts: 111

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

nibble
PostPosted: Sun Jul 04, 2010 4:58 pm     Reply with quote

tks humberto

what is the result of x/10 ?? where x = 00001101


y = (x / 10) << 4;

tks

nina
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Jul 04, 2010 5:13 pm     Reply with quote

Quote:

what is the result of x/10 ?? where x = 00001101

x=0x0D; // 00001101 (13 decimal)
y = (x / 10); // 13 divided by 10 equals 1 + a rest

y = (x / 10) << 4; // Perform division first, then make bit left shift 4 bit pos and leave the result in the same variable

I suggest to use MPLAB to practice with these stuff, you do not need any hardware, just compile and run
the simulation, it will be the best to learn and practice. You can download it from Microchip web site, it is free.

Do not forget to have at hand your best friend for this: Kernighan & Ritchie C Language (Second edition). Smile

Humberto
nina



Joined: 20 Apr 2007
Posts: 111

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

nibble
PostPosted: Sun Jul 04, 2010 8:58 pm     Reply with quote

Humberto

I am not using 7445. Display one and display two are conected directly to pic.
How can I display those numbers?

tks

nina
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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