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

Vorbereitung 10.12.2018

parent 424b4711
No related branches found
No related tags found
No related merge requests found
Showing with 310 additions and 2 deletions
No preview for this file type
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
% Attribution-ShareAlike 3.0 Unported License along with this % Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>. % document. If not, see <http://creativecommons.org/licenses/>.
% README: Bit-Operationen, Programmierung von Mikrocontrollern, I/O-Ports, Interrupts, volatile-Variable % README: Bit-Operationen, Programmierung von Mikrocontrollern, I/O-Ports, Interrupts
\documentclass[10pt,t]{beamer} \documentclass[10pt,t]{beamer}
...@@ -583,6 +583,8 @@ ...@@ -583,6 +583,8 @@
\end{frame} \end{frame}
\iffalse
\subsection{volatile-Variable} \subsection{volatile-Variable}
\begin{frame}[fragile] \begin{frame}[fragile]
...@@ -699,6 +701,8 @@ ...@@ -699,6 +701,8 @@
\end{frame} \end{frame}
\fi
\nosectionnonumber{\inserttitle} \nosectionnonumber{\inserttitle}
\begin{frame} \begin{frame}
...@@ -717,8 +721,8 @@ ...@@ -717,8 +721,8 @@
\item[4.2] Programmierung von Mikrocontrollern \item[4.2] Programmierung von Mikrocontrollern
\item[4.3] I/O-Ports \item[4.3] I/O-Ports
\item[4.4] Interrupts \item[4.4] Interrupts
\item[4.5] volatile-Variable
\color{red} \color{red}
\item[4.5] volatile-Variable
\item[4.6] Byte-Reihenfolge -- Endianness \item[4.6] Byte-Reihenfolge -- Endianness
\item[4.7] Binärdarstellung von Zahlen \item[4.7] Binärdarstellung von Zahlen
\item[4.8] Speicherausrichtung -- Alignment \item[4.8] Speicherausrichtung -- Alignment
......
%.elf: %.c
avr-gcc -Wall -Os -mmcu=atmega328p $< -o $@
%.hex: %.elf
avr-objcopy -O ihex $< $@
download:
./download.sh
#include <stdio.h>
#include <stdint.h>
int main (void)
{
uint64_t x = 4262939000843297096;
char *s = &x;
printf ("%s\n", s);
return 0;
}
#include <avr/io.h>
int main (void)
{
DDRD = 0x40; /* binär: 0100 0000 */
PORTD = 0x40; /* binär: 0100 0000 */
while (1);
return 0;
}
#include <avr/io.h>
int main (void)
{
DDRD = 0x7f; /* binär: 0111 1111 */
PORTD = 0x40; /* binär: 0100 0000 */
while (1);
return 0;
}
#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;
}
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#define F_CPU 16000000l
#include <util/delay.h>
volatile uint8_t key_pressed = 0;
ISR (INT0_vect) /* PD2 */
{
key_pressed = 1;
}
int main (void)
{
cli ();
EICRA = 1 << ISC00 | 1 << ISC01; /* INT0: steigende Flanke */
EIMSK = 1 << INT0; /* INT0 einschalten */
sei ();
DDRD = 0xfb; /* binär: 1111 1011 */
PORTD = 0x40; /* binär: 0100 0000 */
while (1)
{
while (!key_pressed)
; /* just wait */
PORTD ^= 0x40;
key_pressed = 0;
}
return 0;
}
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdint.h>
#define F_CPU 16000000l
#include <util/delay.h>
volatile uint8_t key_pressed = 0;
ISR (INT0_vect) /* PD2 */
{
key_pressed = 1;
}
int main (void)
{
cli ();
EICRA = 1 << ISC00 | 1 << ISC01; /* INT0: steigende Flanke */
EIMSK = 1 << INT0; /* INT0 einschalten */
sei ();
DDRD = 0xfb; /* binär: 1111 1011 */
PORTD = 0x40; /* binär: 0100 0000 */
while (1)
{
while (!key_pressed)
; /* just wait */
_delay_ms (1);
PORTD ^= 0x40;
key_pressed = 0;
}
return 0;
}
#include <avr/io.h>
#define F_CPU 16000000l
#include <util/delay.h>
int main (void)
{
DDRD = 0x02;
PORTD = 0x02;
while (1)
{
_delay_ms (250);
PORTD ^= 0x02;
}
return 0;
}
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRD = 0x01;
PORTD = 0x01;
while (1)
{
while ((PIND & 0x02) == 0)
; /* just wait */
PORTD ^= 0x01;
}
return 0;
}
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRD = 0x11;
PORTD = 0x11;
while (1)
{
while ((PIND & 0x02) == 0)
; /* just wait */
_delay_ms (100);
PORTD ^= 0x01;
}
return 0;
}
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRD = 0x01;
PORTD = 0x01;
while (1)
{
while ((PIND & 0x02) == 0)
; /* just wait */
PORTD ^= 0x01;
_delay_ms (200);
}
return 0;
}
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRD = 0x01; /* 00000001 */
PORTD = 0x03; /* 00000011 */
while (1)
{
while ((PIND & 0x02) == 0)
; /* just wait */
PORTD ^= 0x01;
_delay_ms (200);
}
return 0;
}
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRD = 0x01; /* 00000001 */
PORTD = 0x03; /* 00000011 */
while (1)
; /* just wait */
return 0;
}
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>
int main (void)
{
DDRD = 0x01; /* 00000001 */
PORTD = 0x03; /* 00000011 */
while (1)
{
_delay_ms (500);
PORTD ^= 0x02;
}
return 0;
}
#include <avr/io.h>
#include <avr/interrupt.h>
ISR (TIMER0_COMPB_vect)
{
PORTD ^= 0x40;
}
int main (void)
{
cli ();
TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
sei ();
DDRD = 0xfd; /* binär: 1111 1101 */
PORTD = 0x40; /* binär: 0100 0000 */
while (1);
return 0;
}
#include <avr/io.h>
#include <avr/interrupt.h>
ISR (TIMER0_COMPB_vect)
{
PORTD ^= 0x40;
}
int main (void)
{
DDRD = 0xfd; /* binär: 1111 1101 */
PORTD = 0x40; /* binär: 0100 0000 */
while (1);
return 0;
}
#include <avr/io.h>
#include <avr/interrupt.h>
ISR (TIMER0_COMPB_vect)
{
PORTD ^= 0x40;
}
int main (void)
{
DDRD = 0xfd; /* binär: 1111 1101 */
PORTD = 0x00; /* binär: 0000 0000 */
while (1);
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)
PORTD ^= 0x40;
}
int main (void)
{
cli ();
TCCR0B = (1 << CS01) | (1 << CS00); /* Takt durch 64 dividieren */
TIMSK0 = 1 << OCIE0B; /* Interrupt einschalten */
sei ();
DDRD = 0xfd; /* binär: 1111 1101 */
PORTD = 0x40; /* binär: 0100 0000 */
while (1);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment