Interfacing 7 segment display using 8051/89c51
Sample code for how to interface a 7 segment display using 8051/AT89c51 is here. For interfacing a 7 segment you must have some idea about 7 segment display.7 segment display is of two types:-
1. Common Cathode
2. Common anode
In Common cathode type of display its common pin should be connected to ground (0 level) so that we can ON its rest of LED’s by putting high value (1 level or +5V) on its pin.
In Common anode type of display its common pin should be connected to Logic High (1 level or +5V) so that we can ON its rest of LED’s by putting Low value (0 level or ground) on its pin.
Here I have write the program using Common cathode 7 segment display. You can see the connection diagram in image below:-
In the above connection diagram I have connected the P2 to 7 segment display. For details description you can see the below table:-
Controller Pin
|
7 segment PIN
|
P2.0
|
a
|
P2.1
|
b
|
P2.2
|
c
|
P2.3
|
d
|
P2.4
|
e
|
P2.5
|
f
|
P2.6
|
g
|
P2.7
|
Common
|
So if you wants to ON Led “a” then you can send high signal to PIN P2.0.In this program display show digit from 0 to 9 repeatedly with 1 sec delay. Now you can see the main program in image below:-
In main code firstly I have put zero on PORT2 to off 7 segment display. Then after when I enter in infinite loop I have called a function “display_digit()” to display digit from 0 to 9 on 7 segment display. Because the value of variable i is a zero so digit 0 is delay first on 7 segment then after I have give 1 sec delay and incremented variable i to display 1. In this manner digit gets incremented after every 1 second and displayed. But when value of i becomes greater than 9 then its again become zero because of if condition.
Explanation of “display_digit()” function for displaying digit from 0 to 9 is given in below image:-
In above image you can see the complete “display_digit()” function which I have used to display digit from 0 to 9. I am explaining how I have display digit 0. To display digit zero I have send the 0x3f value to PORT2 to ON Led a,b,c,d,e and f but LED g is off. So you can see in very first image of 7-segment display if LED a,b,c,d,e,f will ON then digit zero will display. This is how you can see the other values also to display digit from 1 to 9.
Download Links
For downloading complete code of 7-segment display you can click here. You can also download supported datasheets from Download tab.
No comments:
Post a Comment