View previous topic :: View next topic |
Author |
Message |
nina
Joined: 20 Apr 2007 Posts: 111
|
high and low nibble |
Posted: Sun Jul 04, 2010 9:09 am |
|
|
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
|
|
Posted: Sun Jul 04, 2010 11:49 am |
|
|
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
|
high and low nibble |
Posted: Sun Jul 04, 2010 1:07 pm |
|
|
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
|
|
Posted: Sun Jul 04, 2010 1:31 pm |
|
|
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
|
nibble |
Posted: Sun Jul 04, 2010 1:48 pm |
|
|
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
|
|
Posted: Sun Jul 04, 2010 1:53 pm |
|
|
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
|
nibble |
Posted: Sun Jul 04, 2010 2:11 pm |
|
|
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
|
|
Posted: Sun Jul 04, 2010 2:15 pm |
|
|
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
|
nibble |
Posted: Sun Jul 04, 2010 3:49 pm |
|
|
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
|
nibble |
Posted: Sun Jul 04, 2010 4:04 pm |
|
|
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
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sun Jul 04, 2010 4:34 pm |
|
|
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
|
nibble |
Posted: Sun Jul 04, 2010 4:58 pm |
|
|
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
|
|
Posted: Sun Jul 04, 2010 5:13 pm |
|
|
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).
Humberto |
|
|
nina
Joined: 20 Apr 2007 Posts: 111
|
nibble |
Posted: Sun Jul 04, 2010 8:58 pm |
|
|
Humberto
I am not using 7445. Display one and display two are conected directly to pic.
How can I display those numbers?
tks
nina |
|
|
|