beginner: Port set

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

beginner: Port set

 · 
Posted: 26.06.2010 - 16:50  ·  #1
Hello,

I have Mega8 and want to set pins on PortD as output .

How to do procedure as PinSet (PortD,pin(0..7),1..0 ) ?

I know to set only by PortD := %00001010

Please help me
Thanks
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: beginner: Port set

 · 
Posted: 26.06.2010 - 20:34  ·  #2
Hello,

if you want to set a port to output you have to use the DDRx register, port direction register.

rolf
aladin
 
Avatar
 
Subject:

Re: beginner: Port set

 · 
Posted: 26.06.2010 - 23:41  ·  #3
Danke, but ... How?

DDRD:= %00001111;

how to set only one bit ? simply please
nwrightson
Benutzer
Avatar
Gender:
Location: Newcastle
Age: 63
Homepage: nweha.homeserver.c…
Posts: 362
Registered: 08 / 2003
Subject:

Re: beginner: Port set

 · 
Posted: 27.06.2010 - 01:56  ·  #4
DDRD.3 := 1;
PortD.5 := 0;
aladin
 
Avatar
 
Subject:

Re: beginner: Port set

 · 
Posted: 27.06.2010 - 09:14  ·  #5
thank you very much, it works :-) .

I tested


DDRD := 255;
for x:=0 to 7 do
PortD.x := 1;
MDelay(100);
//DDRD.[x] := 1;
PortD.x := 0;
MDelay(100);
endfor;


but this doesn't work - error
Jest
 
Avatar
 
Subject:

Re: beginner: Port set

 · 
Posted: 27.06.2010 - 10:29  ·  #6
Try this:

Code
procedure test;
var x, y: byte;
begin
  DDRD := 255;
  y := %00000001;
  for x :=0 to 7 do
    PortD := y;
    mDelay(100);
    PortD := 0;
    mDelay(100);
    y := y shl 1;
  endfor;
end;


DDR, Port and Pin are constants.

Best regards,
Andrej
aladin
 
Avatar
 
Subject:

Re: beginner: Port set

 · 
Posted: 27.06.2010 - 13:40  ·  #7
Hvala Andrej, it works :-)
I don't know, why this simply information is not in Tutorial, as is for PicAxe - for small IC maybe 300pages with pictures...
I mean, that e-Lab is only for Professionals... but I don't like C :-/
Jest
 
Avatar
 
Subject:

Re: beginner: Port set

 · 
Posted: 27.06.2010 - 15:47  ·  #8
Well, I do not agree that AVRco is for professionals only. It is not simple and you have to read some fundamentals about Pascal and AVR specific parts in AVRco. And when you will, that C will be just 4th letter of word Pascal. 8-)

Best regards,
Andrej
  • 1
  • 2
  • Page 1 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: 15 · Cache Hits: 14   135   149 · Page-Gen-Time: 0.040162s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI