Are PORTB.F0 , PORTB.F1, PORTB.F3 addresses of individual pins within a port?
Is there any other way to address the input pins on the port, either one at a time or as a group?
What if I want to write an IF statement that becomes true when specific pins of the port are pulled high?
Do I need to address every pin in that statement as PORTB.F0, PORTB.F1, PORTB.F3 ... ?
I will deal with a PIC16 that has 80 pins very soon.
What is the most right way to address pins when I am writing a program for the microcontroller to respond to a button being pressed?
Can a button trigger an interrupt?
Thank you.
Buttons pulling PIC pins up for input. How to do that?
- janko.kaljevic
- Posts: 3565
- Joined: 16 Jun 2011 13:48
Re: Buttons pulling PIC pins up for input. How to do that?
Hi, tarakan
Only ports have addresses, individual pins don't, so you have to address them as PORTB.B1 , PORTB.B2
Only ports have addresses, individual pins don't, so you have to address them as PORTB.B1 , PORTB.B2
Re: Buttons pulling PIC pins up for input. How to do that?
It is hard to formulate my question, but is there a more compact way to check if the input signal on the pins is 0 or 1?
There is a compact way to set some pins high and some pins low within a port...
There is a compact way to set some pins high and some pins low within a port...
Re: Buttons pulling PIC pins up for input. How to do that?
I know they don't.
But when the port is set to output you can tell pins to go high or to stay low by setting PORTA = 0b00001...
from the input pins?
So when the hardware switch pulls a pin high, it becomes a 1 and when it doesn't it stays 0.
That would be very handy so I can just write a code If (PORTB==0b00001001) { something and something...
Is there something similar to what I am describing in MikroC?
But when the port is set to output you can tell pins to go high or to stay low by setting PORTA = 0b00001...
from the input pins?
So when the hardware switch pulls a pin high, it becomes a 1 and when it doesn't it stays 0.
That would be very handy so I can just write a code If (PORTB==0b00001001) { something and something...
Is there something similar to what I am describing in MikroC?
Re: Buttons pulling PIC pins up for input. How to do that?
Code: Select all
while(1)
{ if(porta.b1==1 && porta.b3==1) // only porta.b1 and porta.b3=1 do the following *pull down these two pins
{portc=0xff;}
else
{portc=0;}
}
}
Re: Buttons pulling PIC pins up for input. How to do that?
Ok.
Thank you.
If this is the only way, fine.
Does it matter if I use .F1, .F2, .F3 or I can use .b1, .b2, .b3 , .F1 , .F2 and .a1, .a2, interchangebly as long as I stay consistent?
Thank you.
If this is the only way, fine.
Does it matter if I use .F1, .F2, .F3 or I can use .b1, .b2, .b3 , .F1 , .F2 and .a1, .a2, interchangebly as long as I stay consistent?
Re: Buttons pulling PIC pins up for input. How to do that?
I usually use
porta.b1==1
or
porta.f1==1
They are of the same to me.
porta.b1==1
or
porta.f1==1
They are of the same to me.
Re: Buttons pulling PIC pins up for input. How to do that?
thank you
looks like they are
looks like they are
Re: Buttons pulling PIC pins up for input. How to do that?
There is also another approach which works in mikroPascal, though, personally not tested on mikroC. It is closely related to single PIC ASM instructions BTFSC and BTFSS.
Please notice this is only for approach description, code is not tested.
Code: Select all
...
char i;
for (i=0; i<7; ++i) {
if portb.i == 1...
Re: Buttons pulling PIC pins up for input. How to do that?
Maybe this will work.
I didn't test.
I avoid using the >> and<< operators. I am not used to them in Basic type languages.
I didn't test.
I avoid using the >> and<< operators. I am not used to them in Basic type languages.