Skip to content
Snippets Groups Projects
Commit 8cfa70ec authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Vorbereitung 28.11.2024

parent 43cc5a6d
Branches
No related tags found
No related merge requests found
Showing with 316 additions and 1 deletion
%.elf: %.c
avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@
%.hex: %.elf
avr-objcopy -O ihex $< $@
download:
./download.sh
a = 0011 0100
^-------- möchte ich auf 1 setzen
0011 0100
| 0000 0010 <---- bitweises Oder mit "Maske"
---------
0011 0110
Maske herstellen: Die Zahl 1 nach links schieben
0000 0001 <---- "Bit 0 gesetzt"
<< 1 <---- um 1 nach links schieben
---------
0000 0010 <---- "Bit 1 gesetzt"
In C: a |= 1 << 1;
a = 0011 0100
^--------- möchte ich auf 0 setzen
0011 0100
& 1111 1011 <---- bitweises Und mit "Maske"
---------
0011 0000
Maske herstellen: Die Zahl 1 nach links schieben, danach die Bits invertieren
0000 0001 <---- "Bit 0 gesetzt"
<< 2 <---- um 2 nach links schieben
---------
0000 0100 <---- "Bit 2 gesetzt"
~ ---------
1111 1011
In C: a &= ~(1 << 2);
a = 0011 0100
^------------ möchte ich invertieren (umklappen)
0011 0100
^ 0001 0000 <---- bitweises Exklusiv-Oder mit "Maske"
---------
0010 0100
Maske herstellen: Die Zahl 1 nach links schieben
0000 0001 <---- "Bit 0 gesetzt"
<< 4 <---- um 4 nach links schieben
---------
0001 0000 <---- "Bit 4 gesetzt"
In C: a ^= 1 << 4;
#include <avr/io.h>
int main (void)
{
DDRD = 0x40; /* binär: 0100 0000 */
PORTD = 0x40; /* binär: 0100 0000 */
while (1);
return 0;
}
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C9444000C940000F1
:0C00800080E48AB98BB9FFCFF894FFCF61
:00000001FF
#include <avr/io.h>
int main (void)
{
DDRD = 0x40; /* binär: 0100 0000 */
PORTD = 0x40; /* binär: 0100 0000 */
while (1);
return 0;
}
cassini/home/peter/bo/2024ws/hp/20241121> gcc -Wall -O3 blink-0.c -o blink-0
blink-0.c:1:10: fatal error: avr/io.h: Datei oder Verzeichnis nicht gefunden
1 | #include <avr/io.h>
| ^~~~~~~~~~
compilation terminated.
cassini/home/peter/bo/2024ws/hp/20241121> locate avr/io.h
/home/peter/bo/2012ws/es/ausarbeitungen/platz/ethersex-lightbarrier/core/host/avr/io.h
/home/peter/src/arduino-1.8.2/hardware/tools/avr/avr/include/avr/io.h
/usr/lib/avr/include/avr/io.h
cassini/home/peter/bo/2024ws/hp/20241121> gcc -I /usr/lib/avr/include/avr -Wall -O3 blink-0.c -o blink-0
blink-0.c:1:10: fatal error: avr/io.h: Datei oder Verzeichnis nicht gefunden
1 | #include <avr/io.h>
| ^~~~~~~~~~
compilation terminated.
cassini/home/peter/bo/2024ws/hp/20241121> gcc -I /usr/lib/avr/include -Wall -O3 blink-0.c -o blink-0
In file included from blink-0.c:1:
/usr/lib/avr/include/avr/io.h:623:6: warning: #warning "device type not defined" [-Wcpp]
623 | # warning "device type not defined"
| ^~~~~~~
blink-0.c: In function ‘main’:
blink-0.c:5:3: error: ‘DDRD’ undeclared (first use in this function)
5 | DDRD = 0x40; /* binär: 0100 0000 */
| ^~~~
blink-0.c:5:3: note: each undeclared identifier is reported only once for each function it appears in
blink-0.c:6:3: error: ‘PORTD’ undeclared (first use in this function); did you mean ‘PORT0’?
6 | PORTD = 0x40; /* binär: 0100 0000 */
| ^~~~~
| PORT0
cassini/home/peter/bo/2024ws/hp/20241121>
cassini/home/peter/bo/2024ws/hp/20241121> avr-gcc -Wall -Os -mmcu=atmega328p blink-0.c -o blink-0
cassini/home/peter/bo/2024ws/hp/20241121> ./blink-0
bash: ./blink-0: Kann die Binärdatei nicht ausführen: Fehler im Format der Programmdatei
cassini/home/peter/bo/2024ws/hp/20241121> ls -l blink-0
-rwxr-xr-x 1 peter peter 6440 21. Nov 13:00 blink-0
cassini/home/peter/bo/2024ws/hp/20241121>
cassini/home/peter/bo/2024ws/hp/20241121> avr-objcopy -O ihex blink-0 blink-0.hex
cassini/home/peter/bo/2024ws/hp/20241121> ls -l blink-0.hex
-rw-r--r-- 1 peter peter 410 21. Nov 13:02 blink-0.hex
cassini/home/peter/bo/2024ws/hp/20241121> cat blink-0.hex
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C9444000C940000F1
:0C00800080E48AB98BB9FFCFF894FFCF61
:00000001FF
cassini/home/peter/bo/2024ws/hp/20241121>
cassini/home/peter/bo/2024ws/hp/20241121> avrdude -P /dev/ttyACM0 -c arduino -p m328p -U flash:w:blink-0.hex
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e950f (probably m328p)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file blink-0.hex for flash
with 140 bytes in 1 section within [0, 0x8b]
using 2 pages and 116 pad bytes
avrdude: writing 140 bytes flash ...
Writing | ################################################## | 100% 0.06 s
avrdude: 140 bytes of flash written
avrdude: verifying flash memory against blink-0.hex
Reading | ################################################## | 100% 0.03 s
avrdude: 140 bytes of flash verified
avrdude done. Thank you.
cassini/home/peter/bo/2024ws/hp/20241121>
#include <avr/io.h>
#define F_CPU 16000000l
#include <util/delay.h>
int main (void)
{
DDRD = 0x01;
PORTD |= 0x01;
while (1)
{
_delay_ms (500);
PORTD &= ~0x01;
_delay_ms (500);
PORTD |= 0x01;
}
return 0;
}
cassini/home/peter/bo/2024ws/hp/20241121> avr-gcc -Wall -Os -mmcu=atmega328p blink-1.c -o blink-1
cassini/home/peter/bo/2024ws/hp/20241121> avr-objcopy -O ihex blink-1 blink-1.hex
cassini/home/peter/bo/2024ws/hp/20241121> avrdude -P /dev/ttyACM0 -c arduino -p m328p -U flash:w:blink-1.hex
avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e950f (probably m328p)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file blink-1.hex for flash
with 178 bytes in 1 section within [0, 0xb1]
using 2 pages and 78 pad bytes
avrdude: writing 178 bytes flash ...
Writing | ################################################## | 100% 0.06 s
avrdude: 178 bytes of flash written
avrdude: verifying flash memory against blink-1.hex
Reading | ################################################## | 100% 0.03 s
avrdude: 178 bytes of flash verified
avrdude done. Thank you.
cassini/home/peter/bo/2024ws/hp/20241121>
#include <avr/io.h>
#define F_CPU 16000000l
#include <util/delay.h>
int main (void)
{
DDRD = 0x01;
PORTD |= 0x01;
while (1)
{
_delay_ms (500);
PORTD &= ~0x01;
_delay_ms (500);
PORTD |= 0x01;
}
return 0;
}
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C9457000C940000DE
:1000800081E08AB9589A2FEF89E698E121508040A3
:100090009040E1F700C0000058982FEF89E698E102
:1000A000215080409040E1F700C00000EBCFF89471
:0200B000FFCF80
:00000001FF
port=$(ls -rt /dev/ttyACM* | tail -1)
echo avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1)
avrdude -P $port -c arduino -p m328p -U flash:w:$(ls -rt *.hex | tail -1) 2>/dev/null
......@@ -20,7 +20,7 @@
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Bibliotheken einbinden und verwenden, Callbacks, make
% README: Bibliotheken einbinden; Hardwarenahe Programmierung: I/O-Ports
\documentclass[10pt,t]{beamer}
......
%.elf: %.c
avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@
%.hex: %.elf
avr-objcopy -O ihex $< $@
download:
./download.sh
philosophy: philosophy.o answer.o
gcc philosophy.o answer.o -o philosophy
answer.o: answer.c answer.h
gcc -Wall -O answer.c -c
philosophy.o: philosophy.c answer.h
gcc -Wall -O philosophy.c -c
TARGET = philosophy
OBJECTS = philosophy.o answer.o
HEADERS = answer.h
CFLAGS = -Wall -O
$(TARGET): $(OBJECTS)
gcc $(OBJECTS) -o $(TARGET)
answer.o: answer.c $(HEADERS)
gcc $(CFLAGS) answer.c -c
philosophy.o: philosophy.c $(HEADERS)
gcc $(CFLAGS) philosophy.c -c
clean:
rm -f $(OBJECTS) $(TARGET)
TARGET = philosophy
OBJECTS = philosophy.o answer.o
HEADERS = answer.h
CFLAGS = -Wall -O
$(TARGET): $(OBJECTS)
gcc $(OBJECTS) -o $(TARGET)
%.o: %.c $(HEADERS)
gcc $(CFLAGS) $< -c
clean:
rm -f $(OBJECTS) $(TARGET)
#include "answer.h"
int answer (void)
{
return 23;
}
extern int answer (void);
#include <string.h>
int fun_1 (char *s)
{
int x = 0;
for (int i = 0; i < strlen (s); i++)
x += s[i];
return x;
}
int fun_2 (char *s)
{
int i = 0, x = 0;
int len = strlen (s);
while (i < len)
x += s[i++];
return x;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment