This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C1231H6PM: 7-Segment problem

Part Number: TM4C1231H6PM

1. I want to use two 7-seg to count perasecond, but I can't turn on the 7-seg now, please help me check my code, maybe I lose something.

2. I have two 7-segment, how can I control them separately?

#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_uart.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/interrupt.h"
#include "driverlib/timer.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/gpio.h"
#include "driverlib/gpio.c"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/sysctl.c"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "driverlib/uart.c"
#include "driverlib/adc.h"

int
main(void)
{
    MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_16MHZ);

    //
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    
    //
    MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
    MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
    
    //
    HWREG(GPIO_PORTF_BASE + 0x520) = 0x4C4F434B;
    HWREG(GPIO_PORTF_BASE + 0x524) = 0x00FF;
    HWREG(GPIO_PORTF_BASE + 0x420) = 0x0000;
    HWREG(GPIO_PORTF_BASE + 0x51C) = 0x001F;
    
    //
    MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    
    // 7-Seg_A : PB1 | 7-Seg_B : PD6 | 7-Seg_C : PF0
    // 7-Seg_D : PF1 | 7-Seg_E : PF2 | 7-Seg_F : PB0
    // 7-Seg_G : PD5    
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_6);
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);

    //
    MAP_UARTConfigSetExpClk(UART0_BASE, MAP_SysCtlClockGet(), 115200,
                        (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                         UART_CONFIG_PAR_NONE));

    while(1)
    {
        MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_1, GPIO_PIN_1);      //a
        MAP_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, GPIO_PIN_1);      //b
        MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);      //c
        MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);      //d
        MAP_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);      //e
        MAP_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_0, GPIO_PIN_0);      //f
        MAP_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_5, GPIO_PIN_5);      //g
    }
}

  • Hello Yang

    1. What type of LED segment it is (Common Anode or Common Cathode)?
    2. Does the code run on the microcontroller as expected? No bus fault or IO's not reaching the high level
  • Hi Amit,
    1. I just solved the problem that I forgot to set the Vcc pin high. It's Common Cathode.
    2. Yes, the only problem is the second 7-seg didn't turn on. What I want to know is how to let two 7-seg turn on at the same time in different number like "7""F", "3""5". They have different Vcc port PD4 and PF3, but same LED port abcdefg.
  • If you have (just) a single MCU Port to provide LED 7-Segment drive to TWO "bussed segment" displays - then you "cannot" display individually (upon one 7 Segment Display) at a time unless you employ, "Multiplexing."  

    Multiplexing "trades" reduced hardware for software complexity and potentially, "Higher Current Drive for each 7 Segment device" - as each are on LESS than 100% of the time.  

    Here's the basic scheme to multiplex such a display:

    • Insure each (there are 2) Common Cathode display pins are floating.  (Not switched to ground.)
    • Present data to the most significant digit (msd)
    • Now drive the msd cathode to ground  (it is likely that you'll need a transistor to supply the current for all 7 segments - a single GPIO turns the transistor off/on)
    • Leave the display in this condition for ~20mS
    • Remove the drive from the msd, cathode-drive transistor (~1mS - this is a blanking time to insure that there is no "image bleed" between each digit)
    • Present data to the least significant digit (lsd)
    • Now drive the lsd cathode to ground  (as you did w/msd cathode)
    • Leave the display in this condition for ~20mS
    • Remove the drive from the lsd, cathode-drive transistor (~1mS)
    • Now loop.

    As the number of LED digits increases - the "On time" for each 7 segment display decreases.   To maintain display brightness - you must increase display drive current proportionally.

    It is important that your SCAN of this "multiplexed" display does NOT HALT as this may leave one digit in an "over-current" condition - which may prove destructive...

  • Thanks for reply !
    It works !
  • Yang Edison said:
    Thanks for reply !
    It works !

    We would hope so (having designed, built, shipped thousands...)

    Thank you - pleased to have assisted.

    It is "Normal & Customary" to reward correct responses (especially so clearly detailed) ones - via your tick of the, "Verified Answer" box - found w/in the Answering Post.

  • And - again my turn to thank you.

    In time - we suspect that you'll add digits to your 7 Segment LED Array. In each case - you'll need one transistor for each digit. Should you create a "4 Digit" display you'll require 4 GPIO (one for each digit) plus 7 for the individual segments. (8 if you use the Decimal Point)

    Should you move "beyond" 4 digits - you should consider a "mux chip" such as HC138. (which enables (just) 3 GPIO to control 8 digits)
    Beware - that as you add digits - the Segment Drive Current for each segment must increase. This may force you into inserting a "current boosting" chip between your MCU's segment driver pins and the LED segments.
  • Thanks for telling me that !
    I only used 2 digits, but I learned a lot, thanks.