Custom 7Segment display characters

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
prasha920
Posts: 30
Joined: Tue Apr 16, 2013 3:10 pm
Has thanked: 48 times
Been thanked: 9 times
Contact:

Custom 7Segment display characters

Post by prasha920 »

hi all,
searched through the forum and also checked the custom code for 7segment display component custom code but didnt understand that how custom chanracters like "P","L","n","o","U","A","d","b","E" can be used to display on 7segment display.. any suggesions would be greatly appreciated.. :D

Prashant

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Custom 7Segment display characters

Post by Spanish_dude »

Hi,

It's quite simple. Make a LUT (lookup table)/array and go through the table whenever you want to display a certain pattern on your 7 segment display.

Code: Select all

LUT_7SEG[] = {
0x3F, // 0
0x06, // 1
0x5B, // 2
0x4F, // 3
// ...
};
Checkout wikipedia for other hexcode:
http://en.wikipedia.org/wiki/Seven-segm ... ng_letters

Once you have your lookup table set. You can simply do something like:
PORTB = LUT_7SEG[X], X being a value between 0 and the highest index of the array.

That's pretty much it.

Here's a little example:

Code: Select all

// simple 7 segment counter on portb

char LUT_7SEG[16] = {
    // set 7 seg code for 0x0 to 0xF
}
char counter = 0;

// Set PORTB I/O to output

while (1)
{
    PORTB = LUT_7SEG[counter]; // Set PORTB output to LUT value
    delay_ms(250); // 250ms delay;
    counter = counter + 1; // increase counter by 1
}
PS: I always forget which bit value sets the I/O as output in a TRIS register.

EDIT:
Btw, you assign 1 pin of a port to each LED of the 7 segment display.
By setting or clearing a pin, depending on what model of display you have (C.A. or C.K.), you turn on or off one of the LEDs of your display.
It's that simple :).

prasha920
Posts: 30
Joined: Tue Apr 16, 2013 3:10 pm
Has thanked: 48 times
Been thanked: 9 times
Contact:

Re: Custom 7Segment display characters

Post by prasha920 »

hi Dude,
thanks for such a quick reply.
btw i am not very much familiar with some functions of C language.
i went through the flocode 7 segment Display component Code and changed Array values to my custom characters values, and i got what i wanted.. was much happier seeing the result.
when i saw your reply, i understood the original code of 7segment display component.
still i want to know that in FC component macro custom code, that array was having values like %c, %d,%e.... where these values came from?
%c = code of "0" dec code is 192,
%d = code of "1" 249 ...
how this %c became 192 and so on?

appreciate your quick and nice reply which took me to next step of my project.. :D :)
thanks

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Custom 7Segment display characters

Post by medelec35 »

Spanish_dude wrote:PS: I always forget which bit value sets the I/O as output in a TRIS register.
Nice easy way to remember:

I as in Input looks like a 1

O as in Output looks like a 0

So with TRIS register:
Use 1 for Input
Use 0 for Output

Martin
Martin

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Custom 7Segment display characters

Post by Spanish_dude »

:o ... I'll try to remember that Martin, thanks :D.

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

Re: Custom 7Segment display characters

Post by Benj »

I as in Input looks like a 1
O as in Output looks like a 0
That's how I remember it too :D

Unfortunately AVRs work the other way, 1 is output, 0 is input. Here I just remember that AVRs are backwards to what you would expect :wink:

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Custom 7Segment display characters

Post by medelec35 »

Benj wrote:Unfortunately AVRs work the other way, 1 is output, 0 is input. Here I just remember that AVRs are backwards to what you would expect :wink:
Thanks Ben,
I did not know that, so I need to remember that one!
Trust AVR to be so awkward!
Martin

prasha920
Posts: 30
Joined: Tue Apr 16, 2013 3:10 pm
Has thanked: 48 times
Been thanked: 9 times
Contact:

Re: Custom 7Segment display characters

Post by prasha920 »

thats really a cool way to remember
thanx for that, Martin :)

btw i understood the way to use custom characters for 7Segment displays, i have edited the component file of 7seg display accordingly and getting the expected output.. :D
i am thinking to upload the respected file along with LUT for all custom characters and their index nos, may i?


Prashant

beambase
Posts: 94
Joined: Wed Jul 29, 2009 5:15 pm
Has thanked: 6 times
Been thanked: 8 times
Contact:

Re: Custom 7Segment display characters

Post by beambase »

Hello,
I am looking to do the same thing. If you have a modified 7 segment LED component, can you please post the code?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Custom 7Segment display characters

Post by medelec35 »

prasha920 wrote:thats really a cool way to remember
thanx for that, Martin :)
Your welcome. :)
prasha920 wrote: i have edited the component file of 7seg display accordingly and getting the expected output.. :D
i am thinking to upload the respected file along with LUT for all custom characters and their index nos, may i?
Of course you can,
Forum users are more than welcome by everyone to post any projects, modified files, tips and tricks etc.

In fact what your asking to post will be really welcome in the Tips and Tricks section of the forums.


Martin
Martin

prasha920
Posts: 30
Joined: Tue Apr 16, 2013 3:10 pm
Has thanked: 48 times
Been thanked: 9 times
Contact:

Re: Custom 7Segment display characters

Post by prasha920 »

Hi Martin,

thanks a lot for clearing me where to post the files... :D
beambase wrote:Hello,
I am looking to do the same thing. If you have a modified 7 segment LED component, can you please post the code?
yes surely i am going to upload the corresponding files in my next post.. as mentioned by Martin, you will find those files in the Tips and Tricks sectin of the forum.



Prashant

Post Reply