Displaying ADC value on 7 Segment ?

Go To Last Post
27 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys,

I have :

d = ntc_get_temp(adcresistance, (double)0.947070725e-3, (double)2.500662058e-4, (double)1.859992838e-7);
	   sprintf(tempCelcius,"%.2f",d);

how can I display it on seven segment ?
the function :

DigitTo7SegEncoder(unsigned char digit, unsigned char common)

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DigitTo7SegEncoder(tempCelcius,0)

?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Are we supposed to guess what the two parameters to the function are?

Is it something you wrote or something you retrieved from the internet? If the latter did it not come with user manual?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, the internet then:

http://www.avr-tutorials.com/projects/atmega16-based-digital-clock

So, two things about that page. One is that there's a pretty good description of the routine at the point of implementation:

/*
* Function Description:
* Encode a Decimal Digit 0-9 to its Seven Segment Equivalent.
*
* Function Arguments:
* digit - Decimal Digit to be Encoded
* common - Common Anode (0), Common Cathode(1)
* SegVal - Encoded Seven Segment Value
*
* Connections:
* Encoded SegVal is return in the other G-F-E-D-C-B-A that is A is the least
* significant bit (bit 0) and G bit 6.
*/

and two, there are even sample invocations:

  SegDataPort = DigitTo7SegEncoder(seconds%10,1);
SegCntrlPort = ~0x01;
SegDataPort = DigitTo7SegEncoder(seconds/10,1);
SegCntrlPort = ~0x02;

I simply fail to see how you are unable to work out how to use the function given those things?!?

I do sometimes wonder if you are a deliberate troll as no one could surely be so clueless?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What I don't understand, is how can I separate the first digit and the second one ??
For example I want to display 20 C?
tempCelcius value is 20 and seven segment 2 and 0, how to separate them ??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oh for goodness sake! Are you blind? Do you not see the "% 10" and "/ 10" in their example invocations there? What do you think they are doing exactly?

There is a potential optimisation you could do as the C library has div() and ldiv() in <stdlib.h>:

http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga748...
http://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html#ga5b6...

That gives both the division and the remainder in one operation. The return is div_t or ldiv_t:

http://www.nongnu.org/avr-libc/user-manual/structdiv__t.html
http://www.nongnu.org/avr-libc/user-manual/structldiv__t.html

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Am I right this way ?

 sprintf(tempCelcius,"%.0f",d);
//display the value to seven segment
SegDataPort = DigitTo7SegEncoder(tempCelcius[0],0);
SegCntrlPort = ~0x02;
_delay_ms(1);
SegDataPort = DigitTo7SegEncoder(tempCelcius[1],0);
SegCntrlPort = ~0x01;
_delay_ms(1);

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The sprintf() delivers ASCII digits. You need a binary index (0..9). To convert '0'..'9' to 0..9 you subtract '0'.

But you don't seem to have handling for the decimal point? If you subtract '0' from '.' and use that to index segment data you are likely to get a very odd result!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

do you mean :

sprintf(tempCelcius,"%.0f",d); 

suppose to be

sprintf(tempCelcius,"%.2f",d);

?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You tell me. You know how you want this display to look, not me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tested with

     usart_pstr("temperature: \n");
usart_transmit(tempCelcius[0]);
usart_pstr("\n");
usart_transmit(tempCelcius[1]);
usart_pstr("\n");

I got on terminal:

temperature:
3
0

but when I displayed to 7 segment I got "88"

code :

 SegDataPort = DigitTo7SegEncoder(tempCelcius[0],0);
SegCntrlPort = ~0x02;
_delay_ms(10);
SegDataPort = DigitTo7SegEncoder(tempCelcius[1],0);
SegCntrlPort = ~0x01;
_delay_ms(10);

Anything missing here ? thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are missing an ASCII chart.... Get one, print it and place it in your field of view. You will be surprised at how often you will use it.

Try and understand the difference between the binary value that is used to represent a human-readable character and the representation of a decimal value in binary.
for exmaple., the decimal value 123 can be represented in at least the following forms ;
- binary byte 01111011
- ASCII-encoded human-readable binary bytes 00110001 00110010 00110011

Learn how to use the various standard library routines such as atoi(), itoa(), sprintf(), etc etc etc etc, to convert from one form to another.

But first, read any documentation/comments/examples that comes with whatever routine you manage to find.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got
tempCelcius[1] = 0x33 Hex
tempCelcius[0] = 0x32 Hex

How can I convert then to 3 and 2 on 'char' ?

I tried :
temp1 = atoi(tempCelcius[0]);
temp2 = atoi(tempCelcius[1]);

now I got 0 0 on seven segment...should I convert again integer to char ?

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried :

d = ntc_get_temp(adcresistance, (double)0.947070725e-3, (double)2.500662058e-4, (double)1.859992838e-7);
sprintf(tempCelcius,"%.2c",d);

I got 80 on seven segment now...??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See posts #4 and #6

If you don't know what the format codes in sprintf() actually do then don't randomly try things in the hope that something will work, because that is a bad way to learn anything.

The display routine you found will take a byte and display the binary value of that byte.
Look at the actual code of that routine., if the value you give it is not in the range of 0 to 9 then it will return rubbish.
(I will let you figure out why it returns rubbish in that scenario)

Anyway..., you need to give it a value in the range of binary 0 and binary 9 inclusive., and post #6 gives you two methods.

Learn what the '/' and '%' operators do. Those operators (and their equivalents in other languages) are absolutely fundamental to any programming that you will ever do.

div(,] is a way of doing the '/' and '%' in one statement., for the moment just use the '/' and '%' operators.

Sit down with pen and paper, do the process and see what you get when you do 24 / 10 and 24 % 10

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think it will be :

sprintf(tempCelcius,"%.2f",d);

temp1 = atoi(tempCelcius)/10;
temp2 = atoi(tempCelcius)%10;

//display the value to seven segment
SegDataPort = DigitTo7SegEncoder(temp1,0);
SegCntrlPort = ~0x02;
_delay_ms(1);
SegDataPort = DigitTo7SegEncoder(temp2,0);
SegCntrlPort = ~0x01;
_delay_ms(1);

isn't it ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

it works already, thanks guys

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to display Perth....but got only the last 'h'...
if I put in never ending loop it works...

Quote:
while(1)
{
display_perth();

}


I don't want to use never ending loop,
how can I get that ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

isn't it ?

WILL YOU EVER GET IT?!?: Tested it? How? Result?

Quote:

I do sometimes wonder if you are a deliberate troll as no one could surely be so clueless?

Sometimes? Lucky you..

Dear bianchi77: You are step by step losing the trust of the residents here at AVRfreaks. You need to shape up or you will eventually be abandoned completely. If you have some kind of impairment that causes your lack of focus, inability to read, failing memory and absent empathy etc then please tell us about it. We really are a tolerant and understanding bunch, and given an explanation we will understand any difficulties. Lacking an explanatiomn there will at some point be a limit to your strange behaviour.

Please react and respond. It will determine my future involvement in your threads. Lacking a response I will default to not participating.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Johan, you said it much nicer than i would have. Mr bianchi burned me a while ago, thus my limited responses.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@bianchi77:

Does this [url]https://www.google.de/maps/@-31.9688837,115.9313409,9z[/url] work for you?

For me, it displays Perth well enough...

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As can be seen in my previous reply, for some posters here i abandoned "helpful mode" long ago. In my mind, it always takes two to obey to a given protocol to make communication work...

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's just a question, if you don't want to answer, you don't have to...and don't have to be angry or upset...take it easy mate...;)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Then you have no respect for our time and effort. You suck our life force. Do you like it when people screw you around?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I saw that movie. The pod people were grown in giant pea pods with a bunch of sticky goop all over them. After a while there weren't anymore normal people left. Like the embedded c world.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Although unrelated, the ISR could be made a bit more efficient by using:


ISR(TIMER1_COMPA_vect){
if(++seconds == 60){
seconds = 0;
if(++minutes == 60){
minutes = 0;
if(++hours == 24)
hours = 0;
}
}
}

Rather than:


ISR(TIMER1_COMPA_vect)
{
seconds++;

if(seconds == 60)
{
seconds = 0;
minutes++;
}
if(minutes == 60)
{
minutes = 0;
hours++;
}
if(hours > 23)
hours = 0;
}

So most of the time we only have 1 increment and 1 logic check per interrupt. But for this application it wont change anything.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

bianchi77 wrote:
It's just a question, if you don't want to answer, you don't have to...and don't have to be angry or upset...take it easy mate...;)

You don't get it! Your naive universe is full of freaks sitting around waiting to spend their time on resolving your issues, and your wrong assumption is that those freaks' involvement just starts when they hit the keyboard the first time for an answer for you. That's WRONG! Our involvement with your problems actually starts when READing the first line you have written. And when i decide not to answer (for whatever reason), i already did spend some time! So, no matter if you get an answer from me, the quality of your question already has made a difference to my situation, and no matter how easy i will take it, it does hurt to see that combined efforts of many guys here, much more experienced than i am, did try to improve your working attitude without success.

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."