NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » 4 Digit 7 Segment LED Display

September 10, 2013
by Affarram
Affarram's Avatar

Hello All,

 I am new to the world of programming with a Nerdkit therefor I have a lot to learn. I have run into a road block on my latest project and although I have made some progress in the right direction I feel as though I am at a lose with where to go next. To give you a brief description of my project, I simply would like to display time on a 4 digit LED Display. I did a test run and I was able to display a two digit number on two different 7 Segmented LEDs. I run into my problem when I try to use a 4 digit display. After a little bit of research I found out that I am to use the SPI Bus. I tried to mimic what was done in the multi-LED array project with no success. I wanted to know if anyone can guide me in the right direction with what to do?

I found two different data sheets for this display. Here is one for the chip that drives the display http://gtbtech.com/wp-content/uploads/2013/02/PT6961.pdf

and this is all I could find on the display itself http://gtbtech.com/?p=528

This is as far as I have gotten in my code.

    //
    //  FourDigitDisplay.c
    //  
    //
    //  Created by Sean on 9/7/13.
    //
    //

    #define F_CPU 14745600

    #include <stdio.h>

    #include <avr/io.h>
    #include <avr/interrupt.h>
    #include <avr/pgmspace.h>
    #include <inttypes.h>

    #include "../libnerdkits/delay.h"
    #include "../libnerdkits/uart.h"

    // PIN DEFINITIONS:
    // Red Rail     Pin 1 on Display
    // PB5 - SCK    Pin 3 on Display
    // PB4 - MISO   Pin 5 on Display
    // PB3 - MOSI   Pin 4 on Display
    // PB1 - SS     Pin 2 on Display
    // Blue Rail    Pin 6 on Display

    void master_init(){

        //set MOSI,SCK,SS as output
        DDRB |= (1<<PB3) | (1<<PB5) | (1<<PB2);
        //initiate the SPI module in master mode, data rate clk/16
        SPCR |= (1<<SPE) | (1<<MSTR) | (1<<SPR0);

        //set the SS pins logic high (slave not active)
        PORTB |= (1<<PB1);

        //set up timer, when this fires all the slave panels are updated
        //timer set to clk/1024 - aprox 56Hz
        TCCR0B |= (1<<CS02) | (1<<CS00);
        TIMSK0 |= (1<<TOIE0);

        //Pull the slave line to low to activate it
        PORTB &= ~(1<<PB1);

    }

    int main() {
        //ledarray_init();
        master_init();
        // activate interrupts
        sei();
        // init serial port
        uart_init();
        FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
        stdin = stdout = &uart_stream;

        while(1) {
            //this loop never executes, scrolling display should loop forever in this mode of operation
            //everythign exciting happens in the interrupt handler, and in do_scrolling display
        }
        return 0;
    }

I tried experimenting with sending info to the display but im really not sure how to do it. If I could be pointed in the direction of how to light up even one segment Im sure I could figure out the rest.

thanks Sean

September 10, 2013
by rajabalu21
rajabalu21's Avatar

Hi Affarram,

I have used this type of display as part of one of my projects. You can take a look at this and this. The code is for Energia but it should be compatible with Arduino/AVR.

-Raja Balu

September 11, 2013
by pcbolt
pcbolt's Avatar

Hi Sean -

From a quick look through the data sheet, that's an interesting driver chip. Seems to be overkill for your application but if it came with the LED module I guess it can do some of the work for you. The wiring should be fairly straightforward, common and 5v are obvious, DIN (from your second link above) should go to MCU pin 18, CLK to MCU pin 19, and CS to MCU pin 16. If we assume the PT 6961 chip is wired correctly to the LEDs the first step would be to initialize the 6961 chip. I'm pretty sure the CS pin in the LED picture is actually the strobe pin on the actual 6961 chip so you can use the terms as the same so we can call it STB from now on. If you're at the stage where you can control the 2-segment LED, you'll know how to make the STB/MCU pin 16 high in your initialize routine and to make it low before each command or data sent to the 6961 (and high afterward). SPI is very easy to use, first set the byte you want to send in the SPDR register and wait. The whole sequence is here...

PORTB &= ~(1<<PB2);            // pull the STB line low
SPDR = data_to_send;           // upload data
while (!(SPSR & (1<<SPIF)));   // wait for data to be transferred
PORTB |= 1<<PB2;               // set STB line high

Once you are sure that works, follow the flow chart on page 13 of your first link to send commands and data to the 6961 chip.

Hope this helps, be sure to update your progress/road blocks.

Post a Reply

Please log in to post a reply.

Did you know that LEDs (light emitting diodes) only conduct current in one direction, like normal diodes? Learn more...