Hello,
I was wondering if I could get a little help with a problem I have. I am trying to program a counter on an AVR microcontroller, and the code I have is below, but all I am getting out is zero's on the 4 seven segment displays.
I am pretty new to C programming, so if anyone can spot any errors, that would be great!
Code:
#include <avr/io.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <avr/interrupt.h>
void delay (unsigned int size)
{
unsigned int i;
for (i = 0; i < size; i = i + 1);
}
void setup_hardware (void)
{
DDRA = 0xFF;
DDRB = 0xFF;
TCCR0 = 0x03;
TIFR = 0x00;
TIMSK = 0x02;
//SREG = SREG | 0x80;
sei();
}
const unsigned char enable [4] = {0x10, 0x20, 0x40, 0x80};
const unsigned char pattern [10] =
{0x7E, 0x0C, 0xB6, 0xCC, 0xDA,
0xFA, 0xFE, 0xFE, 0xCE};
#define DISPLAY_SIZE 4
unsigned char my_display [DISPLAY_SIZE];
unsigned char led_counter = 0;
#define POSITION_0 0
#define POSITION_1 1
#define POSITION_2 2
#define POSITION_3 3
int main (void)
{
unsigned int count = 0;
setup_hardware ();
unsigned char mins_units = 0, mins_tens = 0,
hrs_units = 0, hrs_tens = 0;
//unsigned char hours = 0;
//unsigned int mins = 0;
mins_units = ((count%3600)/60)%10;
mins_tens = ((count%3600)/60)/10;
hrs_units = (count/3600)/10;
hrs_tens = (count/3600)%10;
my_display[POSITION_0] = pattern[hrs_tens];
my_display[POSITION_1] = pattern[hrs_units];
my_display[POSITION_2] = pattern[mins_tens];
my_display[POSITION_3] = pattern[mins_units];
while(1)
{
count = count + 1;
if (count == 43199)
{
count = 0;
}
// load_display (count);
delay(1000);
}
}
ISR(TIMER0_OVF_vect)
{
//clear interrup flag???...done by hardware
//refresh();
PORTB = 0x00; //Turns of all LEDs
PORTA = my_display [led_counter]; //Sets segments for the LED
PORTB = enable [led_counter]; //Turn the LED on
led_counter = led_counter + 1; //Move onto the next LED
if (led_counter == DISPLAY_SIZE)
{
led_counter = 0;
}
}
Thanks for any help pr advice.
Sean