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

Vortragsfolien und Beispiele 6.6.2023

parent f330b931
Branches
No related tags found
No related merge requests found
Showing
with 670 additions and 0 deletions
%.elf: %.c
avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@
%.hex: %.elf
avr-objcopy -O ihex $< $@
download:
./download.sh
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRB = 0xff; // alle 8 Ausgänge als Outputs verwenden ("pinMode" für alle 8)
PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
while (1)
{
_delay_ms (250);
PORTB = 0x00; /* Hexadezimalzahl. Binär: 0000 0000 */
_delay_ms (250);
PORTB = 0x20; /* Hexadezimalzahl. Binär: 0010 0000 */
} /* Bits zählen: ^ ^ ^------ Bit 0 */
return 0; /* rechts anfangen | `-------- Bit 2 */
} /* mit 0 anfangen `------------ Bit 5 */
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
while (1)
{
if (PINB & 0x01)
{
_delay_ms (250);
PORTB = 0x00;
_delay_ms (250);
PORTB = 0x20;
}
}
return 0;
}
.file "blink-02.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
ldi r24,lo8(-2)
out 0x4,r24
ldi r24,lo8(32) ; #include <avr/io.h>
.L6: ;
out 0x5,r24 ; #define F_CPU 16000000
.L2: ; #include <util/delay.h>
sbis 0x3,0 ;
rjmp .L2 ; int main (void)
ldi r18,lo8(799999) ; {
ldi r19,hi8(799999) ; DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
ldi r25,hlo8(799999) ; PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
1: subi r18,1 ; while (1)
sbci r19,0 ; {
sbci r25,0 ; if (PINB & 0x01)
brne 1b ; {
rjmp . ; _delay_ms (250);
nop ; PORTB = 0x00;
out 0x5,__zero_reg__ ; _delay_ms (250);
ldi r18,lo8(799999) ; PORTB = 0x20;
ldi r19,hi8(799999) ; }
ldi r25,hlo8(799999) ; }
1: subi r18,1 ; return 0;
sbci r19,0 ; }
sbci r25,0
brne 1b
rjmp .
nop
rjmp .L6
.size main, .-main
.ident "GCC: (GNU) 5.4.0"
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
while (1)
{
while ((PINB & 0x01) == 0)
; /* just wait */
_delay_ms (250);
PORTB = 0x00;
_delay_ms (250);
PORTB = 0x20;
}
return 0;
}
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
while (1)
{
_delay_ms (250);
PORTB ^= 0x20;
}
return 0;
}
.file "blink-04.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
ldi r24,lo8(-2)
out 0x4,r24
ldi r24,lo8(32)
out 0x5,r24
ldi r25,lo8(32)
.L2:
ldi r18,lo8(799999)
ldi r19,hi8(799999)
ldi r24,hlo8(799999)
1: subi r18,1
sbci r19,0
sbci r24,0
brne 1b
rjmp .
nop
in r24,0x5
eor r24,r25
out 0x5,r24
rjmp .L2
.size main, .-main
.ident "GCC: (GNU) 5.4.0"
#include <avr/io.h>
#include <avr/interrupt.h>
ISR (TIMER0_COMPB_vect)
{
PORTB ^= 0x20;
}
int main (void)
{
cli ();
TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
sei ();
DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
while (1)
; /* do very imporant stuff */
return 0;
}
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
ISR (TIMER0_COMPB_vect)
{
static uint8_t counter = 0;
if (counter++ == 0)
PORTB ^= 0x20;
}
int main (void)
{
cli ();
TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
sei ();
DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
while (1)
; /* do very imporant stuff */
return 0;
}
.file "blink-06.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.global __vector_15
.type __vector_15, @function
__vector_15:
push r1
push r0
in r0,__SREG__
push r0
clr __zero_reg__
push r24
push r25
/* prologue: Signal */
/* frame size = 0 */
/* stack size = 5 */
.L__stack_usage = 5
lds r24,counter.1606
ldi r25,lo8(1)
add r25,r24
sts counter.1606,r25
cpse r24,__zero_reg__
rjmp .L1
in r25,0x5
ldi r24,lo8(32)
eor r24,r25
out 0x5,r24
.L1:
/* epilogue start */
pop r25
pop r24
pop r0
out __SREG__,r0
pop r0
pop r1
reti
.size __vector_15, .-__vector_15
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
/* #APP */
; 14 "blink-06.c" 1
cli
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(3)
out 0x25,r24
ldi r24,lo8(4)
sts 110,r24
/* #APP */
; 17 "blink-06.c" 1
sei
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(-2)
out 0x4,r24
ldi r24,lo8(32)
out 0x5,r24
.L5:
rjmp .L5
.size main, .-main
.local counter.1606
.comm counter.1606,1,1
.ident "GCC: (GNU) 5.4.0"
.global __do_clear_bss
.file "blink-06.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.global __vector_15
.type __vector_15, @function
__vector_15:
push r1
push r0
in r0,__SREG__
push r0 ; #include <avr/io.h>
clr __zero_reg__ ; #include <avr/interrupt.h>
push r24 ; #include <stdint.h>
push r25 ;
/* prologue: Signal */ ; ISR (TIMER0_COMPB_vect)
/* frame size = 0 */ ; {
/* stack size = 5 */ ; static uint8_t counter = 0;
.L__stack_usage = 5 ; if (counter++ == 0)
lds r24,counter.1606 ; PORTB ^= 0x20;
subi r25, lo8(-1) ; ldi r25,lo8(1) ; }
; add r25,r24 ;
sts counter.1606,r24 ; sts counter.1606,r25 ; int main (void)
cpse r24,__zero_reg__ ; {
rjmp .L1 ; cli ();
in r25,0x5 ; TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
ldi r24,lo8(32) ; TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
eor r24,r25 ; sei ();
out 0x5,r24 ; DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
.L1: ; PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
/* epilogue start */ ; while (1)
pop r25 ; ; /* do very imporant stuff */
pop r24 ; return 0;
pop r0 ; }
out __SREG__,r0
pop r0
pop r1
reti
.size __vector_15, .-__vector_15
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
/* #APP */
; 14 "blink-06.c" 1
cli
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(3)
out 0x25,r24
ldi r24,lo8(4)
sts 110,r24
/* #APP */
; 17 "blink-06.c" 1
sei
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(-2)
out 0x4,r24
ldi r24,lo8(32)
out 0x5,r24
.L5:
rjmp .L5
.size main, .-main
.local counter.1606
.comm counter.1606,1,1
.ident "GCC: (GNU) 5.4.0"
.global __do_clear_bss
.file "blink-06.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.global __vector_15
.type __vector_15, @function
__vector_15:
push r1
push r0
in r0,__SREG__
push r0 ; #include <avr/io.h>
clr __zero_reg__ ; #include <avr/interrupt.h>
push r24 ; #include <stdint.h>
push r25 ;
/* prologue: Signal */ ; ISR (TIMER0_COMPB_vect)
/* frame size = 0 */ ; {
/* stack size = 5 */ ; static uint8_t counter = 0;
.L__stack_usage = 5 ; if (++counter == 0) ; if (counter++ == 0)
lds r24,counter.1606 ; PORTB ^= 0x20;
subi r24, lo8(-1) ; ldi r25,lo8(1) ; }
; add r25,r24 ;
sts counter.1606,r24 ; sts counter.1606,r25 ; int main (void)
cpse r24,__zero_reg__ ; {
rjmp .L1 ; cli ();
in r25,0x5 ; TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
ldi r24,lo8(32) ; TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
eor r24,r25 ; sei ();
out 0x5,r24 ; DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
.L1: ; PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
/* epilogue start */ ; while (1)
pop r25 ; ; /* do very imporant stuff */
pop r24 ; return 0;
pop r0 ; }
out __SREG__,r0
pop r0
pop r1
reti
.size __vector_15, .-__vector_15
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0
/* #APP */
; 14 "blink-06.c" 1
cli
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(3)
out 0x25,r24
ldi r24,lo8(4)
sts 110,r24
/* #APP */
; 17 "blink-06.c" 1
sei
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(-2)
out 0x4,r24
ldi r24,lo8(32)
out 0x5,r24
.L5:
rjmp .L5
.size main, .-main
.local counter.1606
.comm counter.1606,1,1
.ident "GCC: (GNU) 5.4.0"
.global __do_clear_bss
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
uint8_t flag = 0;
ISR (TIMER0_COMPB_vect)
{
static uint8_t counter = 0;
if (counter++ == 0)
flag = 1;
}
int main (void)
{
cli ();
TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
sei ();
DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
while (1)
{
if (flag)
{
PORTB ^= 0x20;
flag = 0;
}
}
return 0;
}
.file "blink-07.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.global __vector_15
.type __vector_15, @function
__vector_15:
push r1
push r0
in r0,__SREG__
push r0
clr __zero_reg__ ; #include <avr/io.h>
push r24 ; #include <avr/interrupt.h>
push r25 ; #include <stdint.h>
/* prologue: Signal */ ;
/* frame size = 0 */ ; uint8_t flag = 0;
/* stack size = 5 */ ;
.L__stack_usage = 5 ; ISR (TIMER0_COMPB_vect)
lds r24,counter.1607 ; {
ldi r25,lo8(1) ; static uint8_t counter = 0;
add r25,r24 ; if (counter++ == 0)
sts counter.1607,r25 ; flag = 1;
cpse r24,__zero_reg__ ; }
rjmp .L1 ;
ldi r24,lo8(1) ; int main (void)
sts flag,r24 ; {
.L1: ; cli ();
/* epilogue start */ ; TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
pop r25 ; TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
pop r24 ; sei ();
pop r0 ; DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
out __SREG__,r0 ; PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
pop r0 ; while (1)
pop r1 ; {
reti ; if (flag)
.size __vector_15, .-__vector_15 ; {
.section .text.startup,"ax",@progbits ; PORTB ^= 0x20;
.global main ; flag = 0;
.type main, @function ; }
main: ; }
/* prologue: function */ ; return 0;
/* frame size = 0 */ ; }
/* stack size = 0 */
.L__stack_usage = 0
/* #APP */
; 16 "blink-07.c" 1
cli
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(3)
out 0x25,r24
ldi r24,lo8(4)
sts 110,r24
/* #APP */
; 19 "blink-07.c" 1
sei
; 0 "" 2
/* #NOAPP */
ldi r24,lo8(-2)
out 0x4,r24
ldi r24,lo8(32)
out 0x5,r24
ldi r25,lo8(32)
.L6:
lds r24,flag ; if (flag)
cpse r24,__zero_reg__ ; { ... }
rjmp .L9 ; else
.L8: ; while (1);
rjmp .L8
.L9:
in r24,0x5
eor r24,r25
out 0x5,r24
sts flag,__zero_reg__
rjmp .L6
.size main, .-main
.local counter.1607
.comm counter.1607,1,1
.global flag
.section .bss
.type flag, @object
.size flag, 1
flag:
.zero 1
.ident "GCC: (GNU) 5.4.0"
.global __do_clear_bss
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
volatile uint8_t flag = 0;
ISR (TIMER0_COMPB_vect)
{
static uint8_t counter = 0;
if (counter++ == 0)
flag = 1;
}
int main (void)
{
cli ();
TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
sei ();
DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
while (1)
{
if (flag)
{
PORTB ^= 0x20;
flag = 0;
}
}
return 0;
}
.file "blink-08.c"
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__SREG__ = 0x3f
__tmp_reg__ = 0
__zero_reg__ = 1
.text
.global __vector_15
.type __vector_15, @function
__vector_15:
push r1
push r0
in r0,__SREG__
push r0
clr __zero_reg__
push r24
push r25
/* prologue: Signal */
/* frame size = 0 */
/* stack size = 5 */
.L__stack_usage = 5
lds r24,counter.1607
ldi r25,lo8(1)
add r25,r24
sts counter.1607,r25
cpse r24,__zero_reg__
rjmp .L1
ldi r24,lo8(1)
sts flag,r24
.L1:
/* epilogue start */
pop r25
pop r24
pop r0
out __SREG__,r0
pop r0
pop r1
reti
.size __vector_15, .-__vector_15
.section .text.startup,"ax",@progbits
.global main
.type main, @function
main:
/* prologue: function */
/* frame size = 0 */
/* stack size = 0 */
.L__stack_usage = 0 ; #include <avr/io.h>
/* #APP */ ; #include <avr/interrupt.h>
; 16 "blink-08.c" 1 ; #include <stdint.h>
cli ;
; 0 "" 2 ; volatile uint8_t flag = 0;
/* #NOAPP */ ;
ldi r24,lo8(3) ; ISR (TIMER0_COMPB_vect)
out 0x25,r24 ; {
ldi r24,lo8(4) ; static uint8_t counter = 0;
sts 110,r24 ; if (counter++ == 0)
/* #APP */ ; flag = 1;
; 19 "blink-08.c" 1 ; }
sei ;
; 0 "" 2 ; int main (void)
/* #NOAPP */ ; {
ldi r24,lo8(-2) ; cli ();
out 0x4,r24 ; TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
ldi r24,lo8(32) ; TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
out 0x5,r24 ; sei ();
ldi r25,lo8(32) ; DDRB = 0xfe; // Bit Nr. 0 als Input nutzen
.L5: ; PORTB = 0x20; // Bit Nr. 5 auf 1 setzen, alle anderen auf 0 ("digitalWrite" für alle 8)
lds r24,flag ; while (1)
tst r24 ; {
breq .L5 ; if (flag)
in r24,0x5 ; {
eor r24,r25 ; PORTB ^= 0x20;
out 0x5,r24 ; flag = 0;
sts flag,__zero_reg__ ; }
rjmp .L5 ; }
.size main, .-main ; return 0;
.local counter.1607 ; }
.comm counter.1607,1,1
.global flag
.section .bss
.type flag, @object
.size flag, 1
flag:
.zero 1
.ident "GCC: (GNU) 5.4.0"
.global __do_clear_bss
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
../common/io-ports-and-interrupts.pdf
\ No newline at end of file
../common/logo-hochschule-bochum-cvh-text-v2.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment