PIC16F19176 use same function to check 2 input pins

16 views
Skip to first unread message

flyway38

unread,
Jan 12, 2023, 6:07:45 AM1/12/23
to jallib
Hello,

Need help to use same function wich cheks for an input pin as a buttn.
But now need to implement new input pin as another button.
How to pass to that function which pin to read?
Can I use "byte in device" in its input parameters?
Thank you very much.

Kind regards,
Filipe Santos

Rob CJ

unread,
Jan 12, 2023, 1:06:35 PM1/12/23
to jal...@googlegroups.com
Hi Filipe,

I never tried this but here is a thought.

The pin on a specific port can be found in the LATx register, example below for portc this is LATC.

You find this in your device file for e.g. pin_C2
var volatile bit    LATC_LATC2                at LATC : 2
var volatile bit    pin_C2                    at PORTC : 2

So if you have for example your buttons on port C you could pass a 'mask' as parameter to the procedure. Example below (not compiled):

function pin_active(byte in pin_mask) return bit
   return (LATC & pin_mask)
end function

So if you want to if test pin C1 is active (HIGH) or pin C7 is active (HIGH) you do:

    if  pin_active(0b0000_0010) then
       -- Do something for bin C1
   end if 
   if pin_active(0b1000_0000) then
      --  Do something for pin C7
    end if 

Kind regards,

Rob


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens flyway38 <fsfo...@gmail.com>
Verzonden: donderdag 12 januari 2023 12:07
Aan: jallib <jal...@googlegroups.com>
Onderwerp: [jallib] PIC16F19176 use same function to check 2 input pins
 
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/f5fa42aa-c132-49d8-b5ae-5b141a9d927fn%40googlegroups.com.

flyway38

unread,
Jan 12, 2023, 1:11:42 PM1/12/23
to jallib
Hi Rob,

WOW, nice trick.
Will check if works.
Thank you very much.

Cheers,
FS

Rob CJ

unread,
Jan 12, 2023, 1:28:13 PM1/12/23
to jal...@googlegroups.com
Hi Filipe,

One correction. The return statement should be something like.
       return (LATC & pin_mask) != 0

Let me know if it works, I never tried it myself.

Kind regards,

Rob


Verzonden: donderdag 12 januari 2023 19:11
Aan: jallib <jal...@googlegroups.com>
Onderwerp: Re: [jallib] PIC16F19176 use same function to check 2 input pins
 

Oliver Seitz

unread,
Jan 12, 2023, 1:29:57 PM1/12/23
to jal...@googlegroups.com
Sorry, Rob, little mistake:

You need to check the PORTC register. The LATC register contains the output pattern, not the input state of the port pins.

Otherwise a good idea :-)

Greets,
Kiste

Am Donnerstag, 12. Januar 2023 um 19:11:43 MEZ hat flyway38 <fsfo...@gmail.com> Folgendes geschrieben:


Rob CJ

unread,
Jan 12, 2023, 2:39:29 PM1/12/23
to jal...@googlegroups.com
Hi Oliver,

Thanks for the feedback. I was not sure indeed.

Kind regards,

Rob


Van: 'Oliver Seitz' via jallib <jal...@googlegroups.com>
Verzonden: donderdag 12 januari 2023 19:29
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
Onderwerp: Re: [jallib] PIC16F19176 use same function to check 2 input pins
 
Reply all
Reply to author
Forward
0 new messages