Monday, 19 June 2017

Interfacing seven segment display with LPC2148

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.

Insight into the code-
We are going to do only basic operations here.
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-
 #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
}
}
}


That's it guys. I hope you understood seven segment display. We will cover 14 segment display in coming tutorials. 
Subscribe for more tutorials.
IMP- I have created a youtube channel for the tutorials. To watch the programming of a microcontroller in real time, subscribe to controllers tech.
For full working code with simulation, click here.

Servo motor with STM32

I have already covered a tutorial about Pulse Width Modulation in STM32  HERE  and in this tutorial i am going to cover one of its applicat...