Difference between revisions of "Atmel Mikrocontroller Kickstart/EinfacheBeispiele"

From C4 Wiki
Jump to: navigation, search
 
(Neue Beispiele)
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 21: Line 24:
 
   
 
   
 
  loop:
 
  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
 
         rjmp loop          ; start main loop

Revision as of 18:27, 11 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, 0b00000001
        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