Difference between revisions of "Atmel Mikrocontroller Kickstart/EinfacheBeispiele"

From C4 Wiki
Jump to: navigation, search
 
m (Subkategorie)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
= Einfache Beispiele =
 
= 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.
 
led-an.asm: Schaltet die erste LED an PortB, also an PB0 an.
  
Line 15: 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
Line 22: Line 24:
 
  loop:
 
  loop:
 
         rjmp loop          ; start main 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
 +
 +
[[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