Guten Abend,
Mein Programmers Notepad treibt mich gerade in den Wahnsinn.
Ich habe mir vor einiger Zeit ein Programm mit UART unterstützung
geschrieben.
Wenn ich dieses Programm (also die .hex File) in den Controller lade
funktioniert alles suppa.
Wenn ich die .c Datei des Programms ins Programmers Notepad(PN) lade und
compile,
funktioniert es immernoch und die .hex file ist genau so groß wie
vorher. (Hab ja auch nix verändert).
Wenn ich jetzt aber im PN z.B. ein a tippe, dieses dann wieder lösche
und dann compile wird die .hex Datei 4kb groß und wenn ich sie in den
Controller lade, funktioniert nix.
Das Gleich passiert auch wenn ich erst MAKE CLEAN und dann MAKE FILE
ausführe...
Angemerkt sei, das ich die ganze Zeit die selbe Makefile datei benutze.
Weiß jemand woran das liegen kann?
MfG,
Andi
#error Systematischer Fehler der Baudrate grösser 1% und damit zu hoch!
22
#endif
23
24
25
voidlong_delay(intms){
26
27
for(;ms>0;ms--)_delay_ms(1);
28
}
29
30
31
32
33
intuart_putc(unsignedcharc)
34
{
35
while(!(UCSRA&(1<<UDRE)))//warten bis frei is
36
{
37
long_delay(1);
38
}
39
40
UDR=c;/* sende Zeichen */
41
return0;
42
}
43
44
45
voiduart_puts(char*s)
46
{
47
while(*s)
48
{/* so lange *s != '\0' also ungleich dem "String-Endezeichen" */
49
uart_putc(*s);
50
s++;
51
}
52
}
53
54
55
voidsendInt(inta){
56
chars[10];
57
itoa(a,s,10);// 10 fuer radix -> Dezimalsystem
58
uart_puts(s);
59
60
61
}
62
63
voidsendChar(unsignedchars){
64
uart_putc(s);
65
}
66
67
uint8_tuart_getc(void)
68
{
69
while(!(UCSRA&(1<<RXC)))// warten bis Zeichen verfuegbar
70
;
71
returnUDR;// Zeichen aus UDR an Aufrufer zurueckgeben
72
}
73
74
75
uint16_tReadChannel(uint8_tmux)
76
{
77
uint8_ti;
78
uint16_tresult;
79
80
81
ADMUX=mux;// Kanal waehlen
82
ADMUX&=~(1<<REFS1);
83
ADMUX&=~(1<<REFS0);
84
ADCSRA=(1<<ADEN)|(1<<ADPS1);
85
ADCSRA&=~(1<<ADPS0);
86
ADCSRA|=(1<<ADSC);// eine ADC-Wandlung
87
while(ADCSRA&(1<<ADSC)){
88
;// auf Abschluss der Konvertierung warten
89
}
90
result=ADCW;// ADCW muss einmal gelesen werden,
91
// sonst wird Ergebnis der nächsten Wandlung
92
// nicht übernommen.
93
94
/* Eigentliche Messung - Mittelwert aus 4 aufeinanderfolgenden Wandlungen */
95
result=0;
96
for(i=0;i<1;i++)
97
{
98
ADCSRA|=(1<<ADSC);// eine Wandlung "single conversion"
99
while(ADCSRA&(1<<ADSC)){
100
;// auf Abschluss der Konvertierung warten
101
}
102
result+=ADCW;// Wandlungsergebnisse aufaddieren
103
}
104
ADCSRA&=~(1<<ADEN);// ADC deaktivieren (2)
105
106
result/=1;
107
108
returnresult;
109
110
}
111
112
intgetMiddled(intchannel){
113
inttemp=0;
114
temp=temp+ReadChannel(channel);
115
temp=temp+ReadChannel(channel);
116
temp=temp+ReadChannel(channel);
117
temp=temp+ReadChannel(channel);
118
temp=temp+ReadChannel(channel);
119
temp=(int)(temp*1.0/5.0);
120
returntemp;
121
122
}
123
124
intmain(void)
125
{
126
127
128
UCSRB|=(1<<TXEN);// UART TX einschalten
129
UCSRC|=(1<<URSEL)|(3<<UCSZ0);
130
UCSRB|=(1<<RXEN);
131
132
133
UBRRH=UBRR_VAL>>8;
134
UBRRL=UBRR_VAL&0xFF;
135
136
DDRC=(1<<DDC5);
137
PORTC&=~(1<<PC5);
138
139
unsignedintx=0;
140
141
while(1){
142
143
144
PORTC|=(1<<PC5);
145
uart_getc();
146
while(x<800){
147
sendInt(getMiddled(0));
148
sendChar(';');
149
x++;
150
}
151
x=0;
152
153
154
155
156
157
158
159
}
160
161
162
163
}
Makefile:
# WinAVR Sample makefile written by Eric B. Weddington, Jörg Wunsch, et
al.
# Released to the Public Domain
# Please read the make user manual!
#
#
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or
VMLAB).
#
# make extcoff = Convert ELF to AVR Extended COFF (for use with AVR
Studio
# 4.07 or greater).
#
# make program = Download the hex file to the device, using avrdude.
Please
# customize the avrdude settings below first!
#
# make filename.s = Just compile filename.c into the assembler code only
#
# To rebuild project do "make clean" then "make all".
#
# MCU name
MCU = atmega8
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = main
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# List C source files here. (C dependencies are automatically
generated.)
SRC = $(TARGET).c
# You can also wrap lines by appending a backslash to the end of the
line:
#SRC += baz.c \
#xyzzy.c
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optional compiler flags.
# -g: generate debugging information (for GDB, or for COFF
conversion)
# -O*: optimization level
# -f...: tuning, see gcc manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create assembler listing
CFLAGS = -g -O$(OPT) \
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
-Wall -Wstrict-prototypes \
-Wa,-ahlms=$(<:.c=.lst)
# Optional assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlms: create listing
# -gstabs: have the assembler create line number information; note
that
# for use in COFF files, additional information about
filenames
# and function names needs to be present in the assembler
source
# files -- see avr-libc docs [FIXME: not yet described
there]
ASFLAGS = -Wa,-ahlms=$(<:.S=.lst),-gstabs
# Optional linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
# Additional libraries
#
# Minimalistic printf version
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
#
# Floating point printf version (requires -lm below)
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
#
# -lm = math library
LDFLAGS += -lm
#
------------------------------------------------------------------------
---
# Define directories, if needed.
DIRAVR = c:/winavr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = .
DIRLIB = $(DIRAVR)/avr/lib
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
REMOVE = rm -f
COPY = cp
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) -A $(TARGET).elf
FINISH = echo Errors: none
BEGIN = echo -------- begin --------
END = echo -------- end --------
# Define all object files.
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex
$(TARGET).eep \
$(TARGET).lss sizeafter finished end
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@$(BEGIN)
finished:
@$(FINISH)
end:
@$(END)
# Display size of file.
sizebefore:
@if [ -f $(TARGET).elf ]; then echo Size before:; $(ELFSIZE);fi
sizeafter:
@if [ -f $(TARGET).elf ]; then echo Size after:; $(ELFSIZE);fi
# Display compiler version information.
gccversion :
$(CC) --version
# Convert ELF to COFF for use in debugging / simulating in
# AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: $(TARGET).elf
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
%.eep: %.elf
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
%.lss: %.elf
$(OBJDUMP) -h -S $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
%.o : %.c
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
%.o : %.S
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list finished end
clean_list :
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).obj
$(REMOVE) $(TARGET).a90
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lnk
$(REMOVE) $(TARGET).lss
$(REMOVE) $(OBJ)
$(REMOVE) $(LST)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
# Automatically generate C source code dependencies.
# (Code originally taken from the GNU make user manual and modified
# (See README.txt Credits).)
#
# Note that this will work with sh (bash) and sed that is shipped with
WinAVR
# (see the SHELL variable defined above).
# This may not work with other shells or other seds.
#
%.d: %.c
set -e; $(CC) -MM $(ALL_CFLAGS) $< \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
[ -s $@ ] || rm -f $@
# Remove the '-' if you want to see the dependency files generated.
-include $(SRC:.c=.d)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion coff
extcoff \
clean clean_list program
Andi schrieb:
> Wenn ich dieses Programm (also die .hex File) in den Controller lade> funktioniert alles suppa.
Wunderbar.
> Wenn ich die .c Datei des Programms ins Programmers Notepad(PN) lade und> compile,> funktioniert es immernoch und die .hex file ist genau so groß wie> vorher. (Hab ja auch nix verändert).
Sicherlich hat er die .hex-Datei auch garnicht angefasst, sondern es ist
immer noch die alte. Schonmal die Dateizeit kontrolliert?
> Wenn ich jetzt aber im PN z.B. ein a tippe, dieses dann wieder lösche> und dann compile wird die .hex Datei 4kb groß und wenn ich sie in den> Controller lade, funktioniert nix.
Klar, solange alle Quelldateien älter als die Hex-Datei ist, wird Make
auch nichts machen. Bei einer Änderung (auch wenn es keine ist) ist die
Datei aber neuer und es wird übersetzt.
Vielleicht wird hier nicht das selbe Makefile verwendet. Oder ein ganz
anderer Quellcode übersetzt.
> Das Gleich passiert auch wenn ich erst MAKE CLEAN und dann MAKE FILE> ausführe...>> Angemerkt sei, das ich die ganze Zeit die selbe Makefile datei benutze.
Du vielleicht. Eventuell aber dein Rechner nicht.
Btw. Bei mir hat Die HEX-Datei mit deinen Dateien eine Größe von 3327
Bytes.
Welchen µC willst du programmieren? Im Makefile ist der Atmega8
eingestellt. Mach mal auf der Kommandozeile im entsprechenden Ordner ein
"make clean" und dann ein "make all" und poste von letzterem alle
Ausgaben. Das nächste mal bitte alles was mehr als 10 Zeilen hat als
Anhang hochladen und nicht im Post direkt einbinden.
stdlib.h einbinden, dann verschwindet die Warning.
Du hast noch immer nicht gesagt, ob du überhaupt den Atmega8
programmieren willst oder vielleicht doch einen anderen µC.
Andi schrieb:
> Die .hex file mit der es funktionierthat auch nur 3 kb.> Womit (Umgebung/Makefile) hast du sie compiled?
Betriebssystem: Linux (Fedora 12)
GCC 4.4.2
GNU Make 3.81
Dein Makefile, dein Quellcode. Warnungen einfach ignoriert.
Editor: Joe
Compiliert einfach mittels Eingabe von "make".
Natürlich musste ich das Makefile noch passend einrücken (Tabs
einbauen), da Copy&Paste hier nichts brachte.
Ok jetzt steh ich total aufm Schlauch....
Hab alles unter Windows 7 mit
GCC 4.4.2
GNU Make 3.81
Compiled und draufgeflascht nöx.
Das Programm an sich läuft (Led-Blinken zum test eingebaut)
aber bei uart_getc() kann er einfach nix empfangen, obwohl es
mit der alten hexfile funktioniert.
AHHHHHHHH
Hier auf Ubuntu 9.10 mit GCC 4.3.3.
Makefile richtig eingerückt und die Windows Pfade auskommentiert.
In main.c das long_delay beim UART senden entfernt (schwachsinnig) und
F_CPU vor den Headerfiles eingebaut, damit delay.h die richtige bekommt.
F_CPU wird jetzt wirklich auf 8 MHz eingestellt.
Stdlib.h noch eingebunden, damit die itoa Warning verschwindet.
Kanns nicht testen, hab keinen Atmega8 da.
Was du mit PC5 machst ist mir auch unklar. Setzt ihn zuerst beim
Initialisieren auf Output Low und gleich danach in der while-Schleife
ständig auf High. Wird jedoch nie Low gesetzt, wenn ich das richtig
überflogen habe. Zumindest gibts nur die 2 Vorkommnisse von PORTC.