Addressing individual pins

General discussion on mikroC.
Post Reply
Author
Message
madhunm
Posts: 35
Joined: 18 Feb 2005 23:24

Addressing individual pins

#1 Post by madhunm » 02 Jun 2005 01:24

Hi..

Can someone please tell me how to address individual pins?? is there something like PICBasic Pro ( <Port Name.Pin Number> ) ??

Can someone tell me if this code will compile?

Code: Select all


int i = 0;

while(true)
{
  if(portd) //assuming portd is input
  {
    i++;
    portb.i; //assuming portb is output and i being the pin number
   }
}
thanks in advance...

anton
Posts: 807
Joined: 23 Sep 2004 09:16
Location: South-Africa
Contact:

#2 Post by anton » 02 Jun 2005 07:02

Code: Select all

int i = 0;

while(true)
{
  if(portd.1 == 1) //assuming portd is input
  {
    portb.i = 1;     //assuming portb is output and i being the pin number
    delay_ms(1000);
    portb.i = 0;
    i++;
    if(i == 8) i = 0;
   }
}
Another proud user of LV 24-33A Development System and mikroPascal PRO for dsPIC :)
PortA not working? Add CMCON := 7; PortD not working? Add ADCON1 := 6;
To paste code on the forum, please use the [b] Code [/b] button !! ;)

pizon
mikroElektronika team
Posts: 823
Joined: 11 Oct 2004 08:53

#3 Post by pizon » 02 Jun 2005 09:30

No, I'm afraid it won't work; you will have to make the 'set' and 'clear' masks by yourself:

Code: Select all

unsigned short bitmask_set[] = {0b00000001, 0b00000010, 0b00000100, 0b00001000,
                                0b00010000, 0b00100000, 0b01000000, 0b10000000};
unsigned short bitmask_clr[] = {0b11111110, 0b11111101, 0b11111011, 0b11110111,
                                0b11101111, 0b11011111, 0b10111111, 0b01111111};

void main() {
  int i = 0;

  while(1) {
    if(PORTD.f1 == 1)            // you can do this for constant pin No.
    {
//      PORTB.i = 1;
      PORTB |= bitmask_set[i];   // ...but for the variable pin No, you must
      Delay_ms(1000);            //    do this to set it...
//      PORTB.i = 0;
      PORTB &= bitmask_clr[i];   // ...and this to clear the pin.
      i++;
//      if(i == 8) i = 0;
      i &= 0x07;                 // this is cheaper than if..then
     }
  }
}//~!
pizon

madhunm
Posts: 35
Joined: 18 Feb 2005 23:24

alternate workaround

#4 Post by madhunm » 02 Jun 2005 14:43

Hi all,

thanks for the replies...

anyways, i was fiddling around and this is what i came up with :

Code: Select all

while(1)
{
  if(portb == 1)
  {
    portd == 0b00000001;
   }
}
and this works perfectly. hmm... what pzion posted has neat applications...

thanks,

Madhu.

P.S. mE team, any news about my easypic2 shippment?

Post Reply

Return to “mikroC General”