Programing for LED7Seg4

Forum for problems or queries regarding other Flowcode Components. Eg LEDs, Switches, LCD, Gfx LCD etc

Moderators: Benj, Mods

Kumaran
Posts: 73
Joined: Tue Apr 08, 2008 5:23 pm
Been thanked: 1 time
Contact:

Programing for LED7Seg4

Postby Kumaran » Tue Apr 08, 2008 5:36 pm

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.
Attachments
ADC_Read.fcf
(4.5 KiB) Downloaded 371 times

User avatar
Benj
Matrix Staff
Posts: 13989
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4253 times
Been thanked: 4008 times
Contact:

Re: Programing for LED7Seg4

Postby Benj » Wed Apr 09, 2008 9:54 am

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
These users thanked the author Benj for the post:
choy (Tue Dec 27, 2011 11:05 am)
Rating: 5.88%
 

Kumaran
Posts: 73
Joined: Tue Apr 08, 2008 5:23 pm
Been thanked: 1 time
Contact:

Re: Programing for LED7Seg4

Postby Kumaran » Wed Apr 09, 2008 3:54 pm

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

choy
Posts: 15
Joined: Mon Dec 26, 2011 7:59 pm
Has thanked: 5 times
Contact:

Re: Programing for LED7Seg4

Postby choy » Mon Dec 26, 2011 8:13 pm

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:

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
adc-reader.fcf
please help with the configuration
(8 KiB) Downloaded 216 times

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8236
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2359 times
Been thanked: 3347 times
Contact:

Re: Programing for LED7Seg4

Postby medelec35 » Mon Dec 26, 2011 10:07 pm

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
These users thanked the author medelec35 for the post:
choy (Tue Dec 27, 2011 9:27 am)
Rating: 5.88%
 
Martin

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

choy
Posts: 15
Joined: Mon Dec 26, 2011 7:59 pm
Has thanked: 5 times
Contact:

Re: Programing for LED7Seg4

Postby choy » Tue Dec 27, 2011 9:26 am

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!

choy
Posts: 15
Joined: Mon Dec 26, 2011 7:59 pm
Has thanked: 5 times
Contact:

Re: Programing for LED7Seg4

Postby choy » Tue Dec 27, 2011 11:04 am

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! :D

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8236
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2359 times
Been thanked: 3347 times
Contact:

Re: Programing for LED7Seg4

Postby medelec35 » Tue Dec 27, 2011 11:17 am

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.
Attachments
adc-reader V2.fcf
(9 KiB) Downloaded 240 times
These users thanked the author medelec35 for the post:
choy (Tue Dec 27, 2011 5:28 pm)
Rating: 5.88%
 
Martin

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

choy
Posts: 15
Joined: Mon Dec 26, 2011 7:59 pm
Has thanked: 5 times
Contact:

Re: Programing for LED7Seg4

Postby choy » Tue Dec 27, 2011 5:25 pm

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!! :D

User avatar
medelec35
Valued Contributor
Valued Contributor
Posts: 8236
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2359 times
Been thanked: 3347 times
Contact:

Re: Programing for LED7Seg4

Postby medelec35 » Tue Dec 27, 2011 5:59 pm

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!! :D

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 256 times
These users thanked the author medelec35 for the post:
Benj (Wed Jan 04, 2012 11:54 am)
Rating: 5.88%
 
Martin

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