Sending PORT bits to subroutine or function?

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
User avatar
Blue Bill
Posts: 10
Joined: Thu Sep 27, 2012 3:37 pm
Location: Toronto

Sending PORT bits to subroutine or function?

Post by Blue Bill » Tue May 28, 2013 3:01 pm

Questions,
1. This code doesn't work, I'm not sure how to pass a bit (it's a port) to a subroutine or function.
2. Can the RelayDown variable be used to manipulate the public variable that called it or do I have to make this a function?

Code: Select all

sub Relay(PortBit as boolean, RelayDown as byte)
		If RelayDown=0 Then
			Low(PortBit)            ' relay off
		Else
			High(PortBit)           ' fire relay
			If RelayDown<255 Then		' 255 = relay on else decrement till 0
					Dec(RelayDown)
			EndIf 
		EndIf
Blue Bill (aka BlueRoomElectronics)

bitfogav
Registered User
Registered User
Posts: 169
Joined: Sat Oct 09, 2010 1:39 pm
Location: United Kingdom

Post by bitfogav » Tue May 28, 2013 5:49 pm

Maybe this will help you?.. code below was found here http://www.sfcompiler.co.uk/forum/viewt ... g+port+bit

For your second question you might want to look in the Swordfish help file Parameters (byRef and byVal)

Code: Select all

// blink an LED, PORT bit is passed by 
// reference to the subroutine... 
Sub Blink(ByRef pBit As Bit, pDelay As Byte = 200) 
   High (pBit) 
   DelayMS (pDelay) 
   Low (pBit) 
   DelayMS (pDelay) 
End Sub 

// loop counters... 
Dim Index As Byte 

// main program... 
While true 
   For Index = 0 To Bound(PORTD.Bits) - 4 
      Blink(PORTD.Bits(Index)) 
   Next 
Wend 

User avatar
Blue Bill
Posts: 10
Joined: Thu Sep 27, 2012 3:37 pm
Location: Toronto

Post by Blue Bill » Tue May 28, 2013 11:11 pm

Wow, thank you. Swordfish BASIC is just full of surprises.
Blue Bill (aka BlueRoomElectronics)

Post Reply