Difference between revisions of "Atmel Mikrocontroller Kickstart/EinfacheBeispiele"

From C4 Wiki
Jump to: navigation, search
m
m (Subkategorie)
 
Line 90: Line 90:
 
         rjmp loop          ; start main loop
 
         rjmp loop          ; start main loop
  
[[Category:U23]][[Category:Infos]][[Category:Code]]
+
[[Category:U23 2005]][[Category:Infos]][[Category:Code]]

Latest revision as of 14:34, 28 May 2007

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