LPC812 MAX Experiment: 7-Segment Display
Experiment: 7-segment display
In this experiment you will learn how to control a 7-segment LED display. First, let’s have a look how a 7-segment display works. The name 7-segment refers to the seven main segments, labeled A to G. See picture below. Sometimes there is also an eighth LED, a dot that is typically labeled (R)DP. It is still called a 7-segment LED even though there are actually 8 LEDs.
With the 7 LEDs it is possible to create digits 0-9 and the six first characters in the alphabet. This makes it possible to display hexadecimal numbers.
There are other types of LED displays. See the picture below. The 7-segment display is the simplest. There are also 14- and 16-segment displays. With these it is possible to display all letters in the alphabet. There are also matrix displays in different sizes. The 5x7 formation is the smallest to get reasonable readable digits. The benefit with LED matrixes is that graphics can also be displayed.
Software
The I2C bus is explained in the I2C Experiment so for now a helper class is supplied to help you get started with the analog inputs without prior knowledge of how I2C works. The class is PCF8591:
Use the "Import Library" button to copy it into your project.
1) Hardware
In this lab you will need:
- 1x breadboard
- 1x 7-segment display
- 8x 330 ohm resistor
- cables
Mount the components on the breadboard and connect the breadboard to the LPC812 as show in the image below.
1) Description
In this first experiment with a 7-segment display the microcontroller will not be used. We will only use the LPC812 MAX board to get the +3.3V supply (to drive the LED segments). Verify that you can turn on each segment of the display, by connecting each of them to ground. The picture above illustrates the first breadboard setup with the display. Note which pin controls which segment.
2) Hardware
In this lab you will need:
- 1x breadboard
- 1x 7-segment display
- 10x 330 ohm resistor
- 1x trimming potentiometer
- 1x push-button
- cables
Mount the components on the breadboard and connect the breadboard to the LPC812 as show in the image below.
The pin(s) are specified in the mbed library with the actual pin names as well as some useful aliases:
Schematic Name | mbed Pin Name | Arduino Shield Alias | Description |
---|---|---|---|
AIN0_XPIO0 (SJ5 in 1-2 pos) | N/A | A0 | Trimming potentiometer |
PIO0_0 | P0_0 | D0 | Push-button |
PIO0_9-MBEDIF_nWAKE | P0_9 | D4 | Segment A |
PIO0_7 | P0_7 | D7 | Segment B |
PIO0_17 | P0_17 | D8 | Segment C |
PIO0_16 | P0_16 | D9 | Segment DP |
PIO0_13 | P0_13 | D10 | Segment D |
PIO0_14 | P0_14 | D11 | Segment E |
PIO0_15 | P0_15 | D12 | Segment F |
PIO0_12 | P0_12 | D13 | Segment G |
2) Description
In this experiment you shall control the 7-segment LED display with the microcontroller. We will use eight outputs to directly control each segment of the display. As we have done before, the breadboard setup is prepared for the next experiments also. We will for example not use the trimming potentiometer in this experiment.
Create a program that increment a digit, 0-9 each second. It shall roll-over to 0 when 9 is reached. Let the dot LED light for 100 ms after an increment.
A suitable program structure is to create a subroutine that takes a number (0-9) as input and sets the appropriate segment outputs for each input value.
As a variation to above, modify the code so that every time you press the push-button the number is incremented.
Another variation is to create a program that creates a “running one” segment in a circular structure (segment A->B->C->D->E->F->A, etc.).
3) Hardware
In this lab you will need:
- 1x breadboard
- 1x 7-segment display
- 9x 330 ohm resistor
- 1x 74HC595 shift register
- cables
Mount the components on the breadboard and connect the breadboard to the LPC812 as show in the image below.
The pin(s) are specified in the mbed library with the actual pin names as well as some useful aliases:
Schematic Name | mbed Pin Name | Arduino Shield Alias | Description |
---|---|---|---|
PIO0_13 | P0_13 | D10 | SPI SSEL |
PIO0_14 | P0_14 | D11 | SPI MOSI |
PIO0_12 | P0_12 | D13 | SPI SCK |
3) Description
In this experiment we shall use a shift register to control the LED segments. The idea is to use a serial bus (called SPI) but in this experiment we will not use this bus. That is for a later experiment. Instead you shall emulate the serial bus with GPIO operations. Three signals shall be controlled, called SSEL, MOSI and SCK. These are connected to D10, D11 and D13, respectively. The image below illustrates the timing of the signals. It is the signal MOSI that outputs the different segment values. The SCK signal clocks in the value of the MOSI signal on its rising edge. Signal SSEL shall be low during the clock-in process. When SSEL goes high, the value on the shift register is transferred to the outputs of the shift register. Check the datasheet of the shift register, 74HC595 for details about the shift register operation. Note the order of the bits on the MOSI signals. First the DP bit shall be output, and then segment G, etc. A zero will turn the segment on and a one will turn it off.
Create a subroutine for updating the shift register. Let the subroutine take an 8-bit variable as input, where bit 0 represents segment A, bit 1 segment B, etc. The suggested structure of the subroutine is presented in the code block below.
void updateShiftReg( uint8_t segments ) { uint8_t bitCnt; //Pull SCK and MOSI low, pull SSEL low ... //wait 1us ... //Loop through all eight bits for (bitCnt = 0; bitCnt < 8; bitCnt++) { //output MOSI value (bit 7 of “segments”) ... //wait 1us ... //pull SCK high ... //wait 1us ... //pull SCK low ... //shift “segments” segments = segments << 1; } //Pull SSEL high ... }
The suggested delay values are quite small (1us). They can be smaller according to the 74HC595 datasheet, but for simplicity you can use 1us.
Finally create a look-up table for getting the segment values given a number between 0 and 9.
Solution(s)
Import programlpc812_exp_solution_7-segment
Solutions for the 7-Segment Display experiments for LPC812 MAX
Import programlpc812_exp_solution_7-segment-shift
Solutions for the 7-Segment Display experiments for LPC812 MAX
1 comment on LPC812 MAX Experiment: 7-Segment Display:
Please log in to post comments.
the hex value of the contents of the bus should be displayed on the seven segment display ??I want verilog codes for this