PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Rückkehr aus Funktionen / inline? - Problem



Aldi WE
03.06.2005, 08:11
Hallo Leute,

ich habe ein kleines Problem. Gestern abend habe ich eine kleine Schaltung gebaut, die eine 5x7 LED-Dot-Matrix betreiben soll. Prinzipiell funktioniert sie auch schon sehr gut, jedoch habe ich aus der Not heraus alle Fkt. inline deklariert. Das ist aber weder die feine Art, noch sehr gut für den kleinen Speicher des ATmega8, denn der ist mit dem unterem Programm jetzt voll, doch das Programm kann bis jetzt noch so gut wie nichts.



/*
LED dot matrix segment test driver, v 0.01 (brute force)

Christoph Meissner
meissne1@uni-weimar.de
(c) Bauhausuniversity Weimar, faculty of media, virtual reality

ROADMAP:
########
- function return / no inline funct.!!
- serial interface
- interrupt on serial (matrix) data input from max msp jitter
- latch controlling routine for more segments and clustered display
*/

/*
vers' History
#############
JUN 2, 2005 - 9 pm to JUN 3, 2005 - 3 am:
brute force display driver
hard coded alphanumeric symbols
some test routines for led matrix
*/

//#include <stdint.h>
#include <avr/io.h>

#define DOT_LUMINANCE_DURATION 40
#define FRAME_DURATION 400

//this is the frame, display_segment_frame() will print on LED matrix
//("frame buffer")
unsigned char segment_frame[5];

//delays avr for value of ticks cycles
inline void delay(const long ticks)
{
long i;
for(i=0; i<=ticks; i++){
PORTD = 64;
}
PORTD = 0;
}

//brute force display driver
inline void display_segment_frame(void)
{
PORTD = 128;
unsigned char i, row;
for(row=0; row<=4; row++){
PORTC = (1 << row);
for(i=0; i<=DOT_LUMINANCE_DURATION; i++) PORTB = 255-segment_frame[row];
PORTB = 255;
}
PORTD = 0;
}

//rewrite segment_frame display frame buffer
inline void set_segment_frame(const unsigned char line0, const unsigned char line1, const unsigned char line2, const unsigned char line3, const unsigned char line4)
{
//red LED on, while re-riting frame "buffer"
PORTD = 64;
segment_frame[0] = line0;
segment_frame[1] = line1;
segment_frame[2] = line2;
segment_frame[3] = line3;
segment_frame[4] = line4;
}


inline void set_capital_letter_to_segment_frame(const char code)
{

switch (code) {
//capital letters
case 1: set_segment_frame( 48, 72, 120, 72, 72); break; //A
case 2: set_segment_frame( 112, 72, 112, 72, 112); break; //B
case 3: set_segment_frame( 56, 64, 64, 64, 56); break; //C
case 4: set_segment_frame( 112, 72, 72, 72, 112); break; //D
case 5: set_segment_frame( 120, 64, 112, 64, 120); break; //E
// ...und so weiter, hab ich mal weggelassen, wäre n bisschen lang
}
}

inline void set_small_letter_to_segment_frame(const char code)
{
//small letters
switch (code) {
case 1: set_segment_frame( 0, 48, 80, 80, 104); break; //a
case 2: set_segment_frame( 64, 64, 112, 80, 112); break; //b
case 3: set_segment_frame( 0, 0, 112, 64, 112); break; //c
case 4: set_segment_frame( 16, 16, 112, 80, 112); break; //d
case 5: set_segment_frame( 0, 112, 80, 96, 112); break; //e
// ...und so weiter, hab ich mal weggelassen, wäre n bisschen lang
}
}

inline void set_number_to_segment_frame(const char code)
{
//numbers
switch (code) {
case 0: set_segment_frame( 48, 72, 72, 72, 48); break; //0
case 1: set_segment_frame( 16, 48, 80, 16, 120); break; //1
case 2: set_segment_frame( 48, 72, 16, 32, 120); break; //2
// ...und so weiter
case 10: set_segment_frame( 127, 127, 127, 127, 127); break; //all dots on
case 11: set_segment_frame( 0, 0, 0, 0, 0); break; //all dots off
}
}

inline void clear(void)
{
//clear display (set all dots off)
PORTB=0xFF;
PORTC=0x00;
}

inline void display_single_dot(const char row, const char line)
{
clear();
PORTC = (1 << row);
PORTB = ~(1 << line);
//delay(0);
}

inline void display_full_row(const char row)
{
clear();
PORTB = 0;
PORTC = (1 << row);
//delay(0);
}

inline void display_full_line(const char line)
{
clear();
PORTC = 255;
PORTB = ~(1 << line);
//delay(0);
}

inline void segment_test(void)
{
PORTD = 128;
char r, l;
for(l=0; l<=6; l++) {
for(r=0; r<=4; r++) {
display_single_dot(r,l);
delay(3000);
}
}
/* for(l=0; l<=6; l++) {
for(r=0; r<=4; r++) {
display_single_dot(4-r,6-l);
delay(3000);
}
}*/
for(r=0; r<=4; r++) {
for(l=0; l<=6; l++) {
display_single_dot(r,l);
delay(3000);
}
}
/* for(r=0; r<=4; r++) {
for(l=0; l<=6; l++) {
display_single_dot(4-r,6-l);
delay(3000);
}
}*/
for(r=0; r<=4; r++) {
display_full_row(r);
delay(6000);
}
/* for(r=0; r<=4; r++) {
display_full_row(4-r);
delay(6000);
}*/
for(l=0; l<=6; l++) {
display_full_line(l);
delay(6000);
}
/* for(l=0; l<=6; l++) {
display_full_line(6-l);
delay(6000);
}*/
clear();
PORTD = 0;
}

inline void test_sequence(void)
{
uint32_t i, j;
segment_test();
for(j=0; j<=9; j++) {
set_number_to_segment_frame(j);
for(i=0; i<=FRAME_DURATION; i++) display_segment_frame();
}
for(j=1; j<=26; j++) {
set_capital_letter_to_segment_frame(j);
for(i=0; i<=FRAME_DURATION; i++) display_segment_frame();
}
for(j=1; j<=26; j++) {
set_small_letter_to_segment_frame(j);
for(i=0; i<=FRAME_DURATION; i++) display_segment_frame();
}
}

int main(void)
{
DDRB=0xFF; // Alle Pins an Port B als Ausgang (Output) einstellen
DDRC=0xFF;

PORTB=0xFF; //=255, d.h. alle hi, LEDs aus
PORTC=0x00;

DDRD=0xFF;

while(1) {
test_sequence();
}
}



Jetzt kommt's: Wenn ich die Fkt. nämlich nicht inline deklariere, findet er den Weg zurück nicht mehr und bleibt in den Fkt. hängen. Liegt das daran, dass der compiler den Funktionsaufruf nicht in einen Sprungbefehl (der klein genug ist) in Assambler auflösen kann?

Vielleicht liegts auch an den Compileroptionen (hier das makefile):



# -------------------------------------------------------------------------
# genric makefile for compiling, tranlating and downloading AVR programms
# using the avr-gcc, avr-objcopy and uisp
# by Christoph Meissner, christoph.meissner@medien.uni-weimar.de
# -------------------------------------------------------------------------


# what's the programs name (c-code file name w/o file ending (.c))
# -------------------------------------------------------------------------
FILENAME=ledtest2
# -------------------------------------------------------------------------


# select the AVR Type to be programmed by name or variant type
# (-mmcu=[avr-name|type] parameter)
# -------------------------------------------------------------------------
# supported MCU variant types:
# avr1 - AT90S1200, ATtiny1x, ATtiny28
# avr2 - AT90S2xxx, AT90S4xxx, AT90S8xxx, ATtiny22
# avr3 - ATmega103, ATmega603
# avr4 - ATmega83, ATmega85
# avr5 - ATmega161, ATmega163, ATmega32, AT94K
#
# supported MCU names:
# avr1 avr2 avr3 avr4 avr5 at90s1200 attiny10 attiny11 attiny12 attiny15
# attiny28 at90s2313 at90s2323 at90s2333 at90s2343 attiny22 attiny26
# at90s4433 at90s4414 at90s4434 at90s8515 at90s8535 at90c8534 at86rf401
# atmega603 atmega103 at43usb320 at43usb355 at76c711 atmega8 atmega83
# atmega85 atmega8515 atmega8535 atmega16 atmega161 atmega162 atmega163
# atmega169 atmega32 atmega323 atmega64 atmega128 at94k
# -------------------------------------------------------------------------
MCU=atmega32
# -------------------------------------------------------------------------


# select the compiler (default: avr-gcc)
# -------------------------------------------------------------------------
CC=avr-gcc
# -------------------------------------------------------------------------


# select the translater to create .hex file (default: avr-objcopy)
# -------------------------------------------------------------------------
OBJCOPY=avr-objcopy
# -------------------------------------------------------------------------


# DL adapters by uisp (-dprog parameter):
# -------------------------------------------------------------------------
# supported adapters:
#
# avr910 Standard Atmel Serial Programmer/Atmel Low Cost Programmer
#
# pavr http://www.avr1.org/pavr/pavr.html
#
# stk500 Atmel STK500
#
# dapa Direct AVR Parallel Access
#
# stk200 Parallel Starter Kit STK200, STK300
#
# abb Altera ByteBlasterMV Parallel Port Download Cable
#
# avrisp Atmel AVR ISP (?)
#
# bsd http://www.bsdhome.com/avrdude/ (parallel)
#
# fbprg http://ln.com.ua/~real/avreal/adapters.html (parallel)
#
# dt006 http://www.dontronics.com/dt006.html (parallel)
#
# maxi Investment Technologies Maxi (parallel)
#
# dasa serial (RESET=RTS SCK=DTR MOSI=TXD MISO=CTS)
#
# dasa2 serial (RESET=!TXD SCK=RTS MOSI=DTR MISO=CTS)
# -------------------------------------------------------------------------
DLADAPTER=stk200
# -------------------------------------------------------------------------

# select port, the dl adapter is plugged in
# -------------------------------------------------------------------------
PORT=/dev/parport0
# -------------------------------------------------------------------------


# verbose mode grade 0/4 [min/max]
# -------------------------------------------------------------------------
VERBOSEMODE=3
# -------------------------------------------------------------------------


# optimize package for size:
CFLAGS=-mmcu=$(MCU) -Wall -Wstrict-prototypes -Os -mcall-prologues -G --verbose

# default make target
all: $(FILENAME).hex makefile

$(FILENAME).hex : $(FILENAME).out
$(OBJCOPY) -R .eeprom -O ihex $(FILENAME).out $(FILENAME).hex

$(FILENAME).out : $(FILENAME).o
$(CC) $(CFLAGS) -o $(FILENAME).out -Wl,-Map,$(FILENAME).map $(FILENAME).o

$(FILENAME).o : $(FILENAME).c
$(CC) $(CFLAGS) -Os -c $(FILENAME).c

# you _may_ need to erase first before loading the program.
# load (program) the software into the eeprom:

load: clean $(FILENAME).hex
modprobe parport
modprobe parport_pc
modprobe ppdev
uisp -dlpt=$(PORT) --erase -dprog=$(DLADAPTER) -v=$(VERBOSEMODE)
uisp -dlpt=$(PORT) --erase -dprog=$(DLADAPTER) -v=$(VERBOSEMODE)
uisp -dlpt=$(PORT) --upload if=$(FILENAME).hex -dprog=$(DLADAPTER) -v=$(VERBOSEMODE)
uisp -dlpt=$(PORT) --verify if=$(FILENAME).hex -dprog=$(DLADAPTER) -v=$(VERBOSEMODE)

clean:
rm -f *.o *.map *.out *t.hex


Wer weiß Abhilfe?

Für Hilfe wäre ich sehr dankbar.

Chris[/scroll]

Aldi WE
03.06.2005, 08:12
Hm, hat sich erledigt. Hab die ganze Zeit für den ATmega 32 compiliert. Hab ich grade beim durchlesen meines eigenen Posts gemerkt.

Aber ich muss schon sagen, das Forum hier finde ich echt gut, vor allem die schnelle Hilfe *g*.

PicNick
03.06.2005, 10:22
Ist oft so. Durch das schriftliche Formulieren eines Problems lösen sich 67,3 Prozent der Probleme von selbst.