beginner: Port set

  • 1
  • 2
  • Page 2 of 2
aladin
 
Avatar
 
Subject:

Re: beginner: Port set

 · 
Posted: 27.06.2010 - 17:51  ·  #9
I agree with you, Andrej.
It was from me only small joke.
And new for me is pasCal ;-)
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1373
Registered: 03 / 2005
Subject:

Re: beginner: Port set

 · 
Posted: 28.06.2010 - 10:08  ·  #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
Gender:
Location: Belgrade, Serbia
Age: 53
Homepage: rs.linkedin.com/in…
Posts: 653
Registered: 07 / 2002
Subject:

Re: beginner: Port set

 · 
Posted: 28.06.2010 - 15:31  ·  #11
  • 1
  • 2
  • Page 2 of 2
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 10 · Cache Hits: 14   61   75 · Page-Gen-Time: 0.017191s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI