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);
}
}