C for AVR Dual 7 Seg Display

For E-blocks user to discuss using E-blocks and programming for them.

Moderators: Benj, Mods

Post Reply
ChrisBTW
Posts: 9
Joined: Tue Jul 22, 2014 10:21 am
Has thanked: 2 times
Been thanked: 3 times
Contact:

C for AVR Dual 7 Seg Display

Post by ChrisBTW »

Hi, I have the EB008001 dual 7 segment display E-Block connected to ports C/D with the EB019-00-2 AVR board.

The sample code I have is given below. The problem is that segments 2 & 3 do not light up showing digits 3 & 4. I have used a scope to probe the enable pins (Q1, Q2, Q3, Q4) on the PCB and there is no enable signal as there is no input from the processor (PC2 & PC3). The enable pins PC0 & PC1 work fine and display the digits 1 & 2 on segments 0 & 1.

Has anyone done the C for AVR exercises without issue?

Any ideas or help?
Chris

Code: Select all

/*  EX 4.3 LED refresh                   */
/*  Rob Miles July 2005               */
/*  Uses 4 digit LED display             */
/*  connected to PORTC and PORTD         */

#include <avr/io.h>

void setup_hardware( void )
{
    DDRC=0xff;
    DDRD=0xff;
}

/*  performs a delay so we can hold the  */
/*  the display for us to read it        */

void delay ( unsigned char size ) 
{
    unsigned char  i ;
    for ( i=0 ; i < size ; i= i + 1 ) ;
}

/*  number of LEDs in our display  */

#define DISPLAY_SIZE 4

/* a value for each bit in PORTC. We can   */
/* feed in the number of the LED and it    */
/* it will give us the value to put into C */

const unsigned char enable [4] = { 1, 2, 4, 8 } ;

/* these are the patterns for the LEDs     */
/* which were worked out from the          */
/* datasheet. Note that to light a LED the */
/* bit on PORTD must be low                */
/* I can use this array to convert from a  */
/* digit to the 7 segments needed          */

const unsigned char patterns [10] = 
/*      0     1     2     3     4     5    */
    { 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x99, 
/*      6     7     8     9  */
      0x83, 0xf8, 0x80, 0x98 } ;
      
/*  segment patterns for our LEDs  */
unsigned char segments [DISPLAY_SIZE] ;

/*  counter used by our refresh    */
unsigned char led_counter = 0 ;

/*  each time refresh is called it */
/*  sets the display for a led and */
/*  moves on to the next           */

void refresh ( void ) 
{
    /* turn off all the LEDS       */
    PORTC = 0 ;
    /* set segments for the led    */
    PORTD =  segments [led_counter]  ;
    /* turn the led on             */
    PORTC =  enable [led_counter]  ;
    /* move on to the next led     */
    led_counter = led_counter + 1 ;
    /* see if we fell off the end  */
    if (led_counter == DISPLAY_SIZE) 
	{
        led_counter = 0 ;
    }
}

/* this function takes two parameters, the */
/* value to be displayed and the number    */
/* of the LED unit to use                  */

void display ( unsigned char digit, unsigned char pos ) 
{
    segments [pos] = patterns [digit] ;
}

void main(void)
{
    setup_hardware();
  
    display ( 1,0 );	//number 1 on segment 0
    display ( 2,1 );	//number 2 on segment 1
    display ( 3,2 );	//number 3 on segment 2
    display ( 4,3 );	//number 4 on segment 3
  
    while (1)
    {    
        refresh();
        delay(10);
    }
}

ChrisBTW
Posts: 9
Joined: Tue Jul 22, 2014 10:21 am
Has thanked: 2 times
Been thanked: 3 times
Contact:

Re: C for AVR Dual 7 Seg Display

Post by ChrisBTW »

OK, swapped the 7 segment module to ports A & B and it works fine!

Any ideas why port C bits 2 & 3 wont work?

Tried the LED module on port C and only bits 0, 1, 6, 7 light up, the other bits seem to be floating high? Tried PORTC = 0x00 to set them all low at the start but it still wont work.

Any ideas?
Chris

ChrisBTW
Posts: 9
Joined: Tue Jul 22, 2014 10:21 am
Has thanked: 2 times
Been thanked: 3 times
Contact:

Re: C for AVR Dual 7 Seg Display

Post by ChrisBTW »

Found the solution to this.

By default the JTAG fuse in enabled, which uses PORTC. In order to complete the exercise you need to disable the JTAG fuse.

Not sure why MATRIX Multimedia would sell a learning package with so many errors/problems? :(

Is there a thread on the forum for those who bought the C for AVR learning package?

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: C for AVR Dual 7 Seg Display

Post by dazz »

Hi Chris
The forum for c related stuff is the c and asm programming one, with c related questions it may take a bit longer to get an answer. Difficult to answer your question as im not sure if you set your own fuses as in flowcode or whether they are hard coded into the c file, as i havent got c for avr i cant answer, but for me the trickiest part of Avr programming are the fuses so well done for finding the issue and an extra thanks for sharing on the forum

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

Post Reply