Difference between revisions of "Atmel Mikrocontroller Kickstart/EinfacheBeispiele"

From C4 Wiki
Jump to: navigation, search
(Neue Beispiele)
(LED einschalten)
Line 18: Line 18:
 
         out DDRB, r16
 
         out DDRB, r16
 
   
 
   
        ldi r16, 0b00000001
 
 
         ldi r16, 0x01      ; light first LED on PORTB
 
         ldi r16, 0x01      ; light first LED on PORTB
 
         com r16
 
         com r16

Revision as of 18:16, 13 October 2005

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