Buttons pulling PIC pins up for input. How to do that?

General discussion on mikroC.
Post Reply
Author
Message
tarakan
Posts: 95
Joined: 25 Jun 2011 23:35

Buttons pulling PIC pins up for input. How to do that?

#1 Post by tarakan » 26 Jun 2011 05:08

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.

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Buttons pulling PIC pins up for input. How to do that?

#2 Post by janko.kaljevic » 27 Jun 2011 17:02

Hi, tarakan

Only ports have addresses, individual pins don't, so you have to address them as PORTB.B1 , PORTB.B2

tarakan
Posts: 95
Joined: 25 Jun 2011 23:35

Re: Buttons pulling PIC pins up for input. How to do that?

#3 Post by tarakan » 27 Jun 2011 19:29

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...

tarakan
Posts: 95
Joined: 25 Jun 2011 23:35

Re: Buttons pulling PIC pins up for input. How to do that?

#4 Post by tarakan » 28 Jun 2011 00:50

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?

abcdefgg
Posts: 146
Joined: 19 Apr 2011 11:54
Location: Toko Japan

Re: Buttons pulling PIC pins up for input. How to do that?

#5 Post by abcdefgg » 29 Jun 2011 07:53

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;}
}
}
Is this what you want?

tarakan
Posts: 95
Joined: 25 Jun 2011 23:35

Re: Buttons pulling PIC pins up for input. How to do that?

#6 Post by tarakan » 29 Jun 2011 18:28

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?

abcdefgg
Posts: 146
Joined: 19 Apr 2011 11:54
Location: Toko Japan

Re: Buttons pulling PIC pins up for input. How to do that?

#7 Post by abcdefgg » 30 Jun 2011 14:05

I usually use


porta.b1==1

or

porta.f1==1

They are of the same to me.

tarakan
Posts: 95
Joined: 25 Jun 2011 23:35

Re: Buttons pulling PIC pins up for input. How to do that?

#8 Post by tarakan » 12 Sep 2011 21:30

thank you
looks like they are

sasa72
Posts: 89
Joined: 21 Apr 2011 05:21

Re: Buttons pulling PIC pins up for input. How to do that?

#9 Post by sasa72 » 13 Sep 2011 14:31

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.

Code: Select all

...
   char i;

   for (i=0; i<7; ++i) {
    if portb.i == 1...

Please notice this is only for approach description, code is not tested.

tarakan
Posts: 95
Joined: 25 Jun 2011 23:35

Re: Buttons pulling PIC pins up for input. How to do that?

#10 Post by tarakan » 16 Sep 2011 05:40

Maybe this will work.
I didn't test.
I avoid using the >> and<< operators. I am not used to them in Basic type languages.

Post Reply

Return to “mikroC General”