From 734580cabab838ef4142e4cb9bfbacdd51aae9fc Mon Sep 17 00:00:00 2001 From: Peter Gerwinski <peter.gerwinski@hs-bochum.de> Date: Sun, 21 Nov 2021 21:24:11 +0100 Subject: [PATCH] Weitere Beispiele 15.11.2021 --- 20211115/blink-0a.c | 9 +++++++++ 20211115/blink-2.c | 2 +- 20211115/blink-2a.c | 16 ++++++++++++++++ 20211115/blink-2b.c | 16 ++++++++++++++++ 20211115/blink-4.c | 8 ++++---- 20211115/int-types-1.c | 9 +++++++++ 20211115/int-types-2.c | 9 +++++++++ 20211115/int-types-3.c | 9 +++++++++ 20211115/int-types-4.c | 9 +++++++++ 20211115/int-types-5.c | 11 +++++++++++ 20211115/int-types-6.c | 10 ++++++++++ 20211115/int-types-7.c | 8 ++++++++ 20211115/int-types-7.txt | 15 +++++++++++++++ 20211115/int-types-8.c | 10 ++++++++++ 20211115/int-types-9.c | 10 ++++++++++ 15 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 20211115/blink-0a.c create mode 100644 20211115/blink-2a.c create mode 100644 20211115/blink-2b.c create mode 100644 20211115/int-types-1.c create mode 100644 20211115/int-types-2.c create mode 100644 20211115/int-types-3.c create mode 100644 20211115/int-types-4.c create mode 100644 20211115/int-types-5.c create mode 100644 20211115/int-types-6.c create mode 100644 20211115/int-types-7.c create mode 100644 20211115/int-types-7.txt create mode 100644 20211115/int-types-8.c create mode 100644 20211115/int-types-9.c diff --git a/20211115/blink-0a.c b/20211115/blink-0a.c new file mode 100644 index 0000000..45e90fe --- /dev/null +++ b/20211115/blink-0a.c @@ -0,0 +1,9 @@ +#include <avr/io.h> + +int main (void) +{ + DDRD = 0xff; /* binär: 1111 1111 */ + PORTD = 0x40; /* binär: 0100 0000 */ + while (1); + return 0; +} diff --git a/20211115/blink-2.c b/20211115/blink-2.c index b00eaf5..9389b19 100644 --- a/20211115/blink-2.c +++ b/20211115/blink-2.c @@ -5,7 +5,7 @@ int main (void) { - DDRD = 0x02; + DDRD = 0x02; /* binär: 0000 0010 */ PORTD = 0x02; while (1) { diff --git a/20211115/blink-2a.c b/20211115/blink-2a.c new file mode 100644 index 0000000..a226654 --- /dev/null +++ b/20211115/blink-2a.c @@ -0,0 +1,16 @@ +#include <avr/io.h> + +#define F_CPU 16000000l +#include <util/delay.h> + +int main (void) +{ + DDRD = 0x02; /* binär: 0000 0010 */ + PORTD = 0x02; + while (1) + { + _delay_ms (500); + PORTD = PORTD ^ 0x02; + } + return 0; +} diff --git a/20211115/blink-2b.c b/20211115/blink-2b.c new file mode 100644 index 0000000..90ed36c --- /dev/null +++ b/20211115/blink-2b.c @@ -0,0 +1,16 @@ +#include <avr/io.h> + +#define F_CPU 16000000l +#include <util/delay.h> + +int main (void) +{ + DDRB = 1 << 5; + PORTB = 1 << 5; + while (1) + { + _delay_ms (500); + PORTB ^= 1 << 5; + } + return 0; +} diff --git a/20211115/blink-4.c b/20211115/blink-4.c index 7344aa7..ceafab6 100644 --- a/20211115/blink-4.c +++ b/20211115/blink-4.c @@ -5,11 +5,11 @@ int main (void) { - DDRD = 0x01; - PORTD = 0x01; - while (1) + DDRD = 0x01; /* binär: 0000 0001 */ + PORTD = 0x01; /* ^ Ouptut */ + while (1) /* ^ Input */ { - while ((PIND & 0x02) == 0) + while ((PIND & 0x02) == 0) /* binär: 0000 0010 */ ; /* just wait */ PORTD ^= 0x01; _delay_ms (200); diff --git a/20211115/int-types-1.c b/20211115/int-types-1.c new file mode 100644 index 0000000..832e6c5 --- /dev/null +++ b/20211115/int-types-1.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint64_t x = 42; + printf ("Die Antwort lautet: %d\n", x); + return 0; +} diff --git a/20211115/int-types-2.c b/20211115/int-types-2.c new file mode 100644 index 0000000..0f1cef1 --- /dev/null +++ b/20211115/int-types-2.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint64_t x = 42000000000; + printf ("Die Antwort lautet: %d\n", x); + return 0; +} diff --git a/20211115/int-types-3.c b/20211115/int-types-3.c new file mode 100644 index 0000000..caa5883 --- /dev/null +++ b/20211115/int-types-3.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint64_t x = 42000000000; + printf ("Die Antwort lautet: %ld\n", x); + return 0; +} diff --git a/20211115/int-types-4.c b/20211115/int-types-4.c new file mode 100644 index 0000000..572dba1 --- /dev/null +++ b/20211115/int-types-4.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint64_t x = 42000000000; + printf ("Die Antwort lautet: %lld\n", x); + return 0; +} diff --git a/20211115/int-types-5.c b/20211115/int-types-5.c new file mode 100644 index 0000000..1d41e53 --- /dev/null +++ b/20211115/int-types-5.c @@ -0,0 +1,11 @@ +#include <stdio.h> +#include <stdint.h> + +int main (void) +{ + uint64_t x = 42000000000; + printf ("Die Antwort lautet: %" + "ld" + "\n", x); + return 0; +} diff --git a/20211115/int-types-6.c b/20211115/int-types-6.c new file mode 100644 index 0000000..dd04eaa --- /dev/null +++ b/20211115/int-types-6.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int main (void) +{ + uint64_t x = 42000000000; + printf ("Die Antwort lautet: %" PRIu64 "\n", x); + return 0; +} diff --git a/20211115/int-types-7.c b/20211115/int-types-7.c new file mode 100644 index 0000000..42acfc3 --- /dev/null +++ b/20211115/int-types-7.c @@ -0,0 +1,8 @@ +#include <stdio.h> +#include <inttypes.h> + +int main (void) +{ + printf ("Die Formatspezifikation lautet: %s\n", PRIu64); + return 0; +} diff --git a/20211115/int-types-7.txt b/20211115/int-types-7.txt new file mode 100644 index 0000000..15df839 --- /dev/null +++ b/20211115/int-types-7.txt @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <inttypes.h> + +int main (void) +{ + printf ("Die Formatspezifikation lautet: %s\n", PRIu64); + return 0; +} +cassini/home/peter/bo/2021ws/hp/20211115> gcc -m32 -Wall -O int-types-7.c -o int-types-7 +cassini/home/peter/bo/2021ws/hp/20211115> ./int-types-7 +Die Formatspezifikation lautet: llu +cassini/home/peter/bo/2021ws/hp/20211115> gcc -Wall -O int-types-7.c -o int-types-7 +cassini/home/peter/bo/2021ws/hp/20211115> ./int-types-7 +Die Formatspezifikation lautet: lu +cassini/home/peter/bo/2021ws/hp/20211115> diff --git a/20211115/int-types-8.c b/20211115/int-types-8.c new file mode 100644 index 0000000..0bd4ad7 --- /dev/null +++ b/20211115/int-types-8.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int main (void) +{ + uint64_t x = 42000000000; + printf ("Die Antwort lautet: %" PRIx64 "\n", x); + return 0; +} diff --git a/20211115/int-types-9.c b/20211115/int-types-9.c new file mode 100644 index 0000000..bb987ef --- /dev/null +++ b/20211115/int-types-9.c @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdint.h> +#include <inttypes.h> + +int main (void) +{ + uint64_t x = 42000000000; + printf ("Die Antwort lautet: %016" PRIx64 "\n", x); + return 0; +} -- GitLab