[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] multiplexed display question
From: |
Radu Ciurlea |
Subject: |
[avr-gcc-list] multiplexed display question |
Date: |
Sun, 08 May 2005 22:35:03 +0300 |
User-agent: |
Mozilla Thunderbird 1.0.2 (Windows/20050317) |
Hello everybody. I'm just starting out with AVR microcontrollers and I'm
trying to figure out how to use multiplexed LED displays. I am using an
ATmega8 with a 8 Mhz crystal, and two LED digit displays. The displays
are connected to a CD4511 decoder which is in turn connected to PC0-PC3.
The displays are activated by transistors that are connected to PC4 and PC5.
I wrote the following program to test the whole thing:
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/delay.h>
#define F_CPU 8000000UL // 8 MHz clock
#define MAXCOUNT 100
uint8_t count,div;
uint8_t active_pin;
INTERRUPT(SIG_OVERFLOW0)
{
// comment out this if{} for version 2
if (!div++) {
if (count++ == MAXCOUNT) count = 0;
}
PORTC = 0;
if (active_pin == 4) {
active_pin = 5;
PORTC = _BV(active_pin) | (count / 10);
}
else {
active_pin = 4;
PORTC = _BV(active_pin) | (count % 10);
}
}
void main (void)
{
// uncomment following for version 2
// uint8_t i;
// set PORTC pins 0-5 as outputs
DDRC |= _BV(DDC0) | _BV(DDC1) | _BV(DDC2) | _BV(DDC3) | _BV(DDC4) |
_BV(DDC5);
count = 0;
div = 0;
active_pin = 4;
TCCR0 |= _BV(CS01) | _BV(CS00);
// use CLK/64 from prescaler
timer_enable_int(_BV(TOIE0));
// enable timer0 overflow interrupt
sei();
// enable interrupts
while(1) {
// uncomment for version 2
/* for (i = 0; i < 200; i++)
_delay_ms(10);
if (count++ == MAXCOUNT) count = 0;*/
}
}
It is supposed to count from 0 to 99 and display the numbers on the two
displays. I used timer0 to do the display updates. The interrupt handler
also increments the div variable. When div overflows count is
incremented, so count gets incremented only every 256 interrupt. This
all works nicely, and the displays happily count from 0 to 99.
I tried to update count from main() and it doesn't seem to work. The
commented parts in the code are the non-working version. If i compile
version 2 and run it the displays always show 0, as if the while loop
doesn't update count. I ran the program in the AVR Studio simulator and
it behaves the same way? What's wrong with updating count in main()? As
far as I know updating global variables from any function should be
okay. What am I doing wrong?
--
Radu Ciurlea
radu at ploiesti dot roedu dot net
http://cnmv.ploiesti.roedu.net/~radu/
- [avr-gcc-list] multiplexed display question,
Radu Ciurlea <=