Difference between revisions of "AVR Embedded Tutorial - Simple GPIO on and off output/de"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{Translate}} ==Erster Blink-Beispiel== Dieses Beispiel zeigt, wie man mit einem ATtiy2313 programmiert. Dazu werden 2 LEDs an Pin 0 und 1 von PortD angeschlossen. ==Beispie...")
 
Line 5: Line 5:
 
Dazu werden 2 LEDs an Pin 0 und 1 von PortD angeschlossen.
 
Dazu werden 2 LEDs an Pin 0 und 1 von PortD angeschlossen.
  
==Beispiel-Code-ATtiny2313==
+
==Beispiel ATtiny2313==
 
<syntaxhighlight lang="pascal">program Project1;
 
<syntaxhighlight lang="pascal">program Project1;
 
const
 
const

Revision as of 19:10, 3 November 2017

Template:Translate

Erster Blink-Beispiel

Dieses Beispiel zeigt, wie man mit einem ATtiy2313 programmiert. Dazu werden 2 LEDs an Pin 0 und 1 von PortD angeschlossen.

Beispiel ATtiny2313

program Project1;
const
  DP0 = 0;      // Pin0 PortD
  DP1 = 1;      // Pin1 PortD
  sl = 150000;  // Verzögerung

  procedure mysleep(t: int32); // Ein einfaches Delay.
  var
    i: Int32;
  begin
    for i := 0 to t do begin
      asm
               NOP;
      end;
    end;
  end;

begin
  // Pin 0 und 1 von PortD auf Ausgabe.
  DDRD := DDRD  or (1 shl DP0) or (1 shl DP1);

  repeat
    // LED wechseln
    PORTD := PORTD or (1 shl DP0);      // Pin0 ein
    PORTD := PORTD and not (1 shl DP1); // Pin1 aus
    mysleep(sl);                        // Pause

    // LED wechseln
    PORTD := PORTD or (1 shl DP1);      // Pin1 ein
    PORTD := PORTD and not (1 shl DP0); // Pin0 aus
    mysleep(sl);                        // Pause
  until 1 = 2;
end.

sowie