beginner: Port set

  • 1
  • 2
  • Seite 2 von 2
aladin
 
Avatar
 
Betreff:

Re: beginner: Port set

 · 
Gepostet: 27.06.2010 - 17:51 Uhr  ·  #9
I agree with you, Andrej.
It was from me only small joke.
And new for me is pasCal ;-)
Merlin
Administrator
Avatar
Geschlecht:
Alter: 26
Beiträge: 1480
Dabei seit: 03 / 2005
Betreff:

Re: beginner: Port set

 · 
Gepostet: 28.06.2010 - 10:08 Uhr  ·  #10
Hi Aladin

A little tutorial. ;-)

Your initial question was about toggling individual pins, but the second example solution provided by Andrej toggled all 8 bits at the same time. In this case it is the most elegant and fastest solution, but doesn't work if, say, you were only using 6 of the 8 port pins, because you would reset the other 2 pins that might be used for something else.

AVRCo Pascal a very rich and powerful language and there are solutions to most problems. Here is a solution based on your original code that will work on a smaller number of pins.

Code

DDRD := 255; 
for x:=0 to 7 do 
  incl( PortD,x ); // or, more slowly SetBit( PortD, x, 1 );  
  MDelay(100); 
  //Incl( DDRD,x ); 
  excl( PortD, x); // or more slowly (SetBit( PortD, x, 0 );
  MDelay(100);
endfor;


Some other things that might interest you - it is possible to give your port pins names, and so make your code more readble. Also, as well as using 1 and 0 you can treat them as boolean and use TRUE and FALSE. So, for example, you could do this

Code

var
  LED1 [@PortD, 0 ] : bit; 

begin
 
  incl( DDRD, 0);

  LED1 := TRUE;
  loop
    mdelay(100);
    LED1 := not LED1; // blink
  end_loop;
end;


Enjoy!

Merlin.
Avra
Schreiberling
Avatar
Geschlecht:
Herkunft: Belgrade, Serbia
Alter: 54
Homepage: rs.linkedin.com/in…
Beiträge: 653
Dabei seit: 07 / 2002
Betreff:

Re: beginner: Port set

 · 
Gepostet: 28.06.2010 - 15:31 Uhr  ·  #11
  • 1
  • 2
  • Seite 2 von 2
Gewählte Zitate für Mehrfachzitierung:   0

Registrierte in diesem Topic

Aktuell kein registrierter in diesem Bereich

Die Statistik zeigt, wer in den letzten 5 Minuten online war. Erneuerung alle 90 Sekunden.
MySQL Queries: 14 · Cache Hits: 14   60   74 · Page-Gen-Time: 0.018166s · Speichernutzung: 2 MB · GZIP: ein · Viewport: SMXL-HiDPI