News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Can I set pin direction with symbol

Started by RGV250, May 06, 2023, 11:17 AM

Previous topic - Next topic

RGV250

Hi,
I am trying to change the pin direction with a symbol.

I tried to use
    Symbol DOUT_PIN = LATB.1
    Symbol DOUT_PIN_IN TRISB.1 = 1

    DOUT_PIN_IN       ' Set the pin to input
    Result = DOUT_PIN ' Return the state of the pin.

I get an "Asignment operator "=" missing for DOUT_PIN_IN
so I tried
    Symbol DOUT_PIN_IN = TRISB.1 = 1
which compiles but still gave the same error.

Bob

RGV250

I tried using a procedure but get errors.

    Symbol DOUT_PIN = LATB.1
    Dim ReadyFlag As Bit

I get unrecognised, illegal or unresolvable characters found, ReadyFlag.
    HX711_Ready(DOUT_PIN),ReadyFlag

Proc HX711_Ready(pbit),pBit
    TRISB.1 = 1  ' Set the pin to input
    Result = pbit ' Return the state of the pin.
EndProc   

I am trying to do something like digitalRead in Arduino, later on I will need to write to the pin as well.

Bob

DaveS

Hi Bob

From the manual

Input (PinInput)
Syntax
Input Port, Port.Pin or Pin Number

Output (PinOutput)
Syntax
Output Port or Port.Pin or Pin Number

PinGet (GetPin)
Syntax
Variable = PinGet Pin Number
Overview
Read a pin of a port.

PinSet
Syntax
PinSet Pin Number
Overview
Sets a Port's pin high using a variable as the pin's number, but does not make it an output.

Dave

AlbertoFS

Maybe as simple as this.

Dim ResultBit As Bit

$define HX711_Ready(pPORT, pPin, pBitOut) '
    Input pPORT.pPin                      '
    pBitOut = pPORT.pPin

HX711_Ready(PORTC, 0, ResultBit)
73's de EA3AGV

AlbertoFS

Or better.

Dim ResultBit As Bit

$define HX711_Ready(pPORTPin, pBitOut) '
    Input pPORTPin                                       '
    pBitOut = pPORTPin

HX711_Ready(PORTC.0, ResultBit)
73's de EA3AGV

RGV250

Hi Dave, Alberto,
Just what I was trying to do.

Bob

top204

#6
There are many ways to create a new pseudo command, as has been shown above, but here is my play on it using the unique Pin variable type:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Demonstrate writing and reading a Port's pin using procedures
'
' Written for the Positron8 compiler by Les Johnson
'
    Device = 18F25K20                               ' Tell the compiler what device to compile for
    Declare Xtal = 16                               ' Tell the compiler what frequency the device will be operating at (in MHz)

    Symbol Dout_Pin = PORTB.1                       ' Or it can be: Symbol Dout_Pin = Pin_B1

    Dim tReadyFlag As Bit                           ' Holds the pin's state

'--------------------------------------------------------------------
' The main program starts here
'
    PinWrite(Dout_Pin, 1)                           ' Set the pin high
    tReadyFlag = PinRead(Dout_Pin)                  ' Read the pin's state

'--------------------------------------------------------------------
' Read the state of a pin after setting it as an input
' Input     : pPin holds the pin to read
' Output    : Returns the state of the pin
' Notes     : Sets the pin as an input before the read, in case it has been set as an output elsewhere in the program
'
Proc PinRead(pPin As Pin), Bit
    PinMode(pPin, Input)        ' Set the pin to input (just in case it is an output)
    Result = PinGet(pPin)       ' Return the state of the pin
EndProc 

'--------------------------------------------------------------------
' Change the state of a pin to high or low (1 or 0)
' Input     : pPin holds the pin to change
'           : pState holds the state of the pin 1 or 0
' Output    : None
' Notes     : Sets the pin as an output, in case it has been set as an input elsewhere
'
Proc PinWrite(pPin As Pin, pState As Bit)
    If pState = 0 Then
        PinLow pPin
    Else
        PinHigh pPin
    EndIf
EndProc