Description
Guys today we are going to interface seven segment display with our LPC2148. First we will go into some basic information about seven segment.
It’s so called because it have seven blocks. Each block have a led and different pin to control the block as seen in the figure below
Here I am using a common cathode display which means that the ground pin is common to all the segments and to turn on a segment/led, we have to give high to the respective pin.
In case the display is common anode, which means that Vcc is common to all the segments, and to turn on a segment/led, we have to give low to the respective pin.
Now let’s say I want to display ‘1‘, so I can do that by turning on segments ‘b’ and ‘c’ (you can also turn segments ‘f’ and ‘e’ on). To display ‘5‘, I have to turn on ‘a’, ‘f’, ‘g’, ‘c’ and ‘d’ and so on.
That’s all you need to know for seven segment display. It’s very simple and used widely.
Some Insight into the code-
We are going to do only basic operations here.
1 2 3 |
IODIR0 |= 0xff; // setting Port0.0 to Port0.7 as output IOSET0 |= 0x06; // to set segments 'b' and 'c' as high to display 1. and so on. |
I’ll use timer0 to use delay of 500ms between two corresponding digits.
CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <lpc214x.h> #include "pll.h" #include "timer0.h" char display[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7c,0x07,0x7f,0x67}; int main () { PINSEL0 = 0; // setting pinsel for normal io operations IODIR0 |= 0xff; // setting Port0.0 to Port0.6 as output pll_init (); // initialising pll VPBDIV = 0x00; // setting pclk = 15 MHz timer0_init (15000); // initialsing timer at 1ms as base while (1) { for (int i=0;i<10;i++) { IOSET0 |= display[i]; // display digits 0 to 9 timer0_delay (500); // delay of 500 ms IOCLR0 |= display[i]; // clear pins } } } |
4 Comments. Leave new
Well the code works perfectly. But can u show how to interface 14 segment display.
こんにちわ。今回の記事も参考になりました。私は公的融資からの運転資金の申請方法についての記事を書きました。誰もが知りたい国民生活金融公庫から運転資金の融資を受ける際の審査基準、について情報をまとめています。これからもブログ楽しみにしています。
Hey I know this is off topic but I was wondering if you knew of any
widgets I could add to my blog that automatically
tweet my newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was
hoping maybe you would have some experience with something like this.
Please let me know if you run into anything.
I truly enjoy reading your blog and I look forward to
your new updates.
I think the admin of this website is really working hard for his web site, since here every stuff
is quality based data.