port as a function parameter

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
serg1980
Posts: 44
Joined: 19 Mar 2014 05:58

port as a function parameter

#1 Post by serg1980 » 25 Mar 2022 06:46

Hello everyone!
There is a function for reading data from the sensor

Code: Select all

function DHT11_GetData():word;
var DHT_Status,i,CRC,temp1,temp2,temp3,temp4:byte;
begin
 result:=0;
 DHT_Status:=0;
 CRC:=0;
 DDD0_bit:=1;
 PORTD0_bit:=0;
 Delay_ms(18);
 PORTD0_bit:=1;
 DDD0_bit:=0;
 .........
 
The port is explicitly set in this function. How to make it so that the port can be specified in the parameters of the function itself?
For example

Code: Select all

function DHT11_GetData(port, pin: byte):word;

Thomas.Pahl@t-online.de
Posts: 158
Joined: 24 May 2008 15:55
Location: Germany

Re: port as a function parameter

#2 Post by Thomas.Pahl@t-online.de » 25 Mar 2022 14:54

perhaps as an idea: (in basic :D )

Code: Select all

sub procedure setpin(dim port as ^byte, dim pin as byte)
    port^.pin = 1
end sub

main:
setpin(@ddrD, 5)         ' setting the pin direction
setpin(@portD, 5)        ' setting the pin

serg1980
Posts: 44
Joined: 19 Mar 2014 05:58

Re: port as a function parameter

#3 Post by serg1980 » 28 Mar 2022 06:13

Thank you Thomas!

Post Reply

Return to “mikroPascal PRO for AVR General”