Atmel Mikrocontroller Kickstart/EinfacheBeispiele

From C4 Wiki
< Atmel Mikrocontroller Kickstart
Revision as of 14:34, 28 May 2007 by Pylon (talk | contribs) (Subkategorie)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Einfache Beispiele

Alle folgenden Beispiele lassen sich mit dem Fnordlicht ausprobieren.

LED einschalten

led-an.asm: Schaltet die erste LED an PortB, also an PB0 an.

.include "m8def.inc"
.ORG 0x0                    ; reset vector
        rjmp reset


.ORG 0x13
reset:                      ; reset subprocedure
                            ; executed after a reset (poweron)

        ldi r16, 0xff       ; configure PORTB as output
        out DDRB, r16

        ldi r16, 0x01       ; light first LED on PORTB
        com r16
        out PORTB, r16

loop:
        rjmp loop           ; start main loop

LED blinken lassen

blinken-einfach.asm: Lässt eine LED ganz schnell blinken, so dass diese gedimmt erscheint.

.include "m8def.inc"
.ORG 0x0                    ; reset vector
        rjmp reset


.ORG 0x13
reset:                      ; reset subprocedure
                            ; executed after a reset (poweron)

        ldi r16, 0xff       ; configure PORTB as output
        out DDRB, r16

        ldi r16, 0x01       ; light first LED on PORTB
        com r16
        out PORTB, r16

        com r16

loop:
        in r17, PORTB
        eor r17, r16
        out PORTB, r17

        rjmp loop           ; start main loop

LED richtig blinken lassen

blinken-besser: Lässt LED durch eine Warteschleife verzögert richtig blinken.

.include "m8def.inc"
.ORG 0x0                    ; reset vector
        rjmp reset


.ORG 0x13
reset:                      ; reset subprocedure
                            ; executed after a reset (poweron)

        ldi r16, 0xff       ; configure PORTB as output
        out DDRB, r16

        ldi r16, 0x01       ; light first LED on PORTB
        com r16
        out PORTB, r16

        com r16

loop:
        in r17, PORTB
        eor r17, r16
        out PORTB, r17

        ldi r17, 0xff
outer_wait:
        ldi r18, 0xff
inner_wait:
        dec r18
        brne inner_wait
        dec r17
        brne outer_wait
       
        rjmp loop           ; start main loop