I want to read the ADC value and display it in the LED7Seg4. How to do it? when I tried, I could see full ADC value in LCD however in the LED7Seg4 only the last digit is displaying.
How to program LED7seg4 to display the entire value? Please find the attachment.
Programing for LED7Seg4
 Benj
 Matrix Staff
 Posts: 14073
 Joined: Mon Oct 16, 2006 10:48 am
 Location: Matrix TS Ltd
 Has thanked: 4297 times
 Been thanked: 4050 times
 Contact:
Re: Programing for LED7Seg4
Hello
Basically you want to do the following.
1) Read the ADC value into a INT variable
2) Create four byte variables for digit1, digit2 ... digit4
3) Calculation  digit4 = INT variable MOD 10
4) Calculation  INT variable = INT variable / 10
5) Calculation  digit3 = INT variable MOD 10
6) Calculation  INT variable = INT variable / 10
7) Calculation  digit2 = INT variable MOD 10
8 ) Calculation  INT variable = INT variable / 10
9) Calculation  digit1 = INT variable
10) Output the digit1 variable to 7seg1
11) Wait approx 5ms
12) Output the digit2 variable to 7seg2
13) Wait approx 5ms
14) Output the digit3 variable to 7seg3
15) Wait approx 5ms
16) Output the digit4 variable to 7seg4
17) Wait approx 5ms
Hope this helps
Basically you want to do the following.
1) Read the ADC value into a INT variable
2) Create four byte variables for digit1, digit2 ... digit4
3) Calculation  digit4 = INT variable MOD 10
4) Calculation  INT variable = INT variable / 10
5) Calculation  digit3 = INT variable MOD 10
6) Calculation  INT variable = INT variable / 10
7) Calculation  digit2 = INT variable MOD 10
8 ) Calculation  INT variable = INT variable / 10
9) Calculation  digit1 = INT variable
10) Output the digit1 variable to 7seg1
11) Wait approx 5ms
12) Output the digit2 variable to 7seg2
13) Wait approx 5ms
14) Output the digit3 variable to 7seg3
15) Wait approx 5ms
16) Output the digit4 variable to 7seg4
17) Wait approx 5ms
Hope this helps
 Rating: 5.56%

Regards Ben Rowland  MatrixTSL
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Flowcode Product Page  Flowcode Help Wiki  Flowcode Examples  Flowcode Blog  Flowcode Course  My YouTube Channel
Re: Programing for LED7Seg4
Thanks Mr. Benj, for your earliest reply.
Your method worked well. This is the first forum in which I got clear step by step functional instructions. I really appreciate your support.
Regards
Kumaran
Your method worked well. This is the first forum in which I got clear step by step functional instructions. I really appreciate your support.
Regards
Kumaran
Re: Programing for LED7Seg4
Hello,
I'm also trying to do the same thing. I'm able to display the ADC value with the LCD display but not with LED7Seg4. I followed your instructions on how to assign four byte variables and everything else. I'm not sure though what you exactly mean with INT variable MOD 10. If my byte variable for digit 4 is dig4 and the INT variable is adc, would the calculation be:
?
If so, then why is it not displaying correctly on my program? If it isn't, what is the correct code syntax(computation) for this? i apologize if my question sounds too dumb, i'm a total noob on this. i'm trying to complete this as a requirement in one of my subjects in school. please see the attachment.
thanks!
I'm also trying to do the same thing. I'm able to display the ADC value with the LCD display but not with LED7Seg4. I followed your instructions on how to assign four byte variables and everything else. I'm not sure though what you exactly mean with INT variable MOD 10. If my byte variable for digit 4 is dig4 and the INT variable is adc, would the calculation be:
Code: Select all
dig4 = adc/10 MOD 10
If so, then why is it not displaying correctly on my program? If it isn't, what is the correct code syntax(computation) for this? i apologize if my question sounds too dumb, i'm a total noob on this. i'm trying to complete this as a requirement in one of my subjects in school. please see the attachment.
thanks!
 Attachments

 adcreader.fcf
 please help with the configuration
 (8 KiB) Downloaded 217 times
 medelec35
 Valued Contributor
 Posts: 8285
 Joined: Sat May 05, 2007 2:27 pm
 Location: Northamptonshire, UK
 Has thanked: 2371 times
 Been thanked: 3378 times
 Contact:
Re: Programing for LED7Seg4
Hi choy,
You don't need to use mod function to display Value of ADC The mod function is only used to separate an int into single digits e.g if ADC 1023 then Dig3=1, Dig2=0 Dig1=2 & Dig0=0 etc.
In your case, you just use variable to read ADC , use cursor function, then use LCD to print Number. Finally I would print " "
Rather than modify your flowchart, since its for your school project, It would be better for you to access the learning centre here:
http://www.matrixmultimedia.com/lc_index.php?p=all
and select Flowcode for the keyword. You could also use LCD for Filter Text for example.
If you get stuck after, then there should be help for you
Martin
You don't need to use mod function to display Value of ADC The mod function is only used to separate an int into single digits e.g if ADC 1023 then Dig3=1, Dig2=0 Dig1=2 & Dig0=0 etc.
In your case, you just use variable to read ADC , use cursor function, then use LCD to print Number. Finally I would print " "
Rather than modify your flowchart, since its for your school project, It would be better for you to access the learning centre here:
http://www.matrixmultimedia.com/lc_index.php?p=all
and select Flowcode for the keyword. You could also use LCD for Filter Text for example.
If you get stuck after, then there should be help for you
Martin
 Rating: 5.56%

Martin
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.
Re: Programing for LED7Seg4
medelec35 wrote:Hi choy,
You don't need to use mod function to display Value of ADC The mod function is only used to separate an int into single digits e.g if ADC 1023 then Dig3=1, Dig2=0 Dig1=2 & Dig0=0 etc.
In your case, you just use variable to read ADC , use cursor function, then use LCD to print Number. Finally I would print " "
Rather than modify your flowchart, since its for your school project, It would be better for you to access the learning centre here:
http://www.matrixmultimedia.com/lc_index.php?p=all
and select Flowcode for the keyword. You could also use LCD for Filter Text for example.
If you get stuck after, then there should be help for you
Martin
Hello medelec35,
Thanks for the info. I don't have problems displaying the ADC reading with the LCD component. It works perfectly fine displaying the ADC value using the LCD. My problem is I cannot display the value using the LED7Seg4. Can you help me with this? What do I exactly have to do with my four byte variables digit4, digit3, digit2 and digit1 for them to display on the LED7Seg4. Thanks!
Re: Programing for LED7Seg4
hi again!
i've finally figured it out. it's working now and displays the correct ADC value with the LCD as well as the LED7Seg4. things i did:
(assuming adc is 1023)
created 4 byte variables digit4, digit3, digit2 and digit1.
for digit1 = adc MOD 10 (which is 3)
for digit2 = adc/10 MOD 10 (which is 2)
for digit3 = adc/100 MOD 10 (which is 0)
for digit4 = adc/1000 MOD 10 (which is 1)
thanks for the help! cheers!
i've finally figured it out. it's working now and displays the correct ADC value with the LCD as well as the LED7Seg4. things i did:
(assuming adc is 1023)
created 4 byte variables digit4, digit3, digit2 and digit1.
for digit1 = adc MOD 10 (which is 3)
for digit2 = adc/10 MOD 10 (which is 2)
for digit3 = adc/100 MOD 10 (which is 0)
for digit4 = adc/1000 MOD 10 (which is 1)
thanks for the help! cheers!
 medelec35
 Valued Contributor
 Posts: 8285
 Joined: Sat May 05, 2007 2:27 pm
 Location: Northamptonshire, UK
 Has thanked: 2371 times
 Been thanked: 3378 times
 Contact:
Re: Programing for LED7Seg4
Oh Im sorry, I miss read your post, and thought you did not want to use 7Seg just LCD.
In that case I have alter your Flowchart so 7seg4 LED's work as well
I have also added an extra routine so that no leading zeros are shown. e.g if ADC is 5 then instead of 0005, only 5 is shown.
To remove that function, just drag 7seg4 out of decisions loops.
Reson you had a problem with your flowchart is because:
1) One side of 7seg4's was not connected. Right click on the component (that's on the Panel) and select connections.
2) Pot connection is connected to the same pin as 7seg4 Anode0
3) Configuration settings for your target device are are wrong. See
viewtopic.php?f=26&t=6936
4) Calculations for segments are wrong.
you will need
dig4 = adc / 1000 MOD 10
dig3 = adc/100 MOD 10
dig2 = adc / 10 MOD 10
dig1 = adc MOD 10
On your flowchart you have repeated adc / 10 MOD 10
For this to work with EB006 LCD is connected to portB
7seg4 is connected to portsC and D
Pot is connected to portA 0
I have tested on hardware and is working.
Martin
Edit: We posted at the same time. But your simulation may work, but hardware will not unless you complete the above changes.
I'm glad you figured out the calculations.
In that case I have alter your Flowchart so 7seg4 LED's work as well
I have also added an extra routine so that no leading zeros are shown. e.g if ADC is 5 then instead of 0005, only 5 is shown.
To remove that function, just drag 7seg4 out of decisions loops.
Reson you had a problem with your flowchart is because:
1) One side of 7seg4's was not connected. Right click on the component (that's on the Panel) and select connections.
2) Pot connection is connected to the same pin as 7seg4 Anode0
3) Configuration settings for your target device are are wrong. See
viewtopic.php?f=26&t=6936
4) Calculations for segments are wrong.
you will need
dig4 = adc / 1000 MOD 10
dig3 = adc/100 MOD 10
dig2 = adc / 10 MOD 10
dig1 = adc MOD 10
On your flowchart you have repeated adc / 10 MOD 10
For this to work with EB006 LCD is connected to portB
7seg4 is connected to portsC and D
Pot is connected to portA 0
I have tested on hardware and is working.
Martin
Edit: We posted at the same time. But your simulation may work, but hardware will not unless you complete the above changes.
I'm glad you figured out the calculations.
 Attachments

 adcreader V2.fcf
 (9 KiB) Downloaded 242 times
 Rating: 5.56%

Martin
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.
Re: Programing for LED7Seg4
medelec35 wrote:Oh Im sorry, I miss read your post, and thought you did not want to use 7Seg just LCD.
In that case I have alter your Flowchart so 7seg4 LED's work as well
I have also added an extra routine so that no leading zeros are shown. e.g if ADC is 5 then instead of 0005, only 5 is shown.
To remove that function, just drag 7seg4 out of decisions loops.
Reson you had a problem with your flowchart is because:
1) One side of 7seg4's was not connected. Right click on the component (that's on the Panel) and select connections.
2) Pot connection is connected to the same pin as 7seg4 Anode0
3) Configuration settings for your target device are are wrong. See
viewtopic.php?f=26&t=6936
4) Calculations for segments are wrong.
you will need
dig4 = adc / 1000 MOD 10
dig3 = adc/100 MOD 10
dig2 = adc / 10 MOD 10
dig1 = adc MOD 10
On your flowchart you have repeated adc / 10 MOD 10
For this to work with EB006 LCD is connected to portB
7seg4 is connected to portsC and D
Pot is connected to portA 0
I have tested on hardware and is working.
Martin
Edit: We posted at the same time. But your simulation may work, but hardware will not unless you complete the above changes.
I'm glad you figured out the calculations.
hello medelec35!
thank you for this! a big big thanks to you man! that was one thing i was also able to figure out, i mean the connection of the LED7Seg4. i changed and corrected it, together with the correct calculations and to my surprise i got the program working. your modification of this program (ommitting zeros) is what i was thinking of to add in my program. great that you were also thinking about that! with your permission i'm going to use those codes so that no leading zeros are shown. pretty slick! i've one last question though. what do you mean by this? what (or which) Pot are you referring to?
Code: Select all
Pot is connected to portA 0
thanks a lot man! i really appreciate your help!!
 medelec35
 Valued Contributor
 Posts: 8285
 Joined: Sat May 05, 2007 2:27 pm
 Location: Northamptonshire, UK
 Has thanked: 2371 times
 Been thanked: 3378 times
 Contact:
Re: Programing for LED7Seg4
choy wrote: with your permission i'm going to use those codes so that no leading zeros are shown. pretty slick! i've one last question though. what do you mean by this? what (or which) Pot are you referring to?Code: Select all
Pot is connected to portA 0
thanks a lot man! i really appreciate your help!!
Your welcome. No problem with using code. Any flowchart I post, if they come in handy then they are for all to use.
Pot is short for potentiometer (variable resistor).
Its the input to the analogue pin AN0. On the control panel its the knob that is adjusted to alter the voltage going into AN0. One side of the pot is connected to +5V. the other side is connected to 0V. As you rotate knob clockwise, then the voltage on the centre that's connected to AN0 increases. If reading as integer then digital value produced will be in the range of 0 to 1023.
Since AN0 is same pin as RA0 (pins usually have more than one function) the 7seg4 LED connections and the ADC (Analogue to Digital Conversion) component was connected to the same pins on your flowchart.
So I changed the connections on 7seg4 component to ports C and D.
If you are interested in learning further, then you will find out that the more routines you place in main, the the longer it will take to read the 7seg4 LEDs, so their appearance will start flickering (especially if more delays are used). Therefore It may be a good idea to learn about interrupts, so 7seg4 LED's can be placed within the interrupt.
The effect is to always reach each 7seg4 LED at the same time, no matter how many extra delays, and routines are placed.
One such example is here:
viewtopic.php?f=29&t=8969&p=27840#p27845
I have attached flowchart from the above link and modified it for 16F877A
Hope I was clear enough to help.
Martin
 Attachments

 LED Voltmeter2 16F877A.fcf
 (9.5 KiB) Downloaded 260 times
 Rating: 5.56%

Martin
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.
If you read a post that is useful, please show appreciation by clicking on thumbs up Icon.