Jump to content
Sign in to follow this  
Joan

PIC12F629

Recommended Posts

Hi

 

Normaly you can

 

set_bit( porta, 0 ) to hight ( pin 0 PORTA )

clear_bit( portc, 5 ) to low ( pin 5 PORTC )

 

Bye

Daniel

Share this post


Link to post
Share on other sites

Hi Daniel & CO;

Working with 12F629 and using instructions like

 

[.../...]

 

set_bit( gpio , 0 );

delay_s(1);

clear_bit ( gpio , 0 );

delay_s(1);

 

[.../...]

 

works fine, but what about read only a pin ?. I've tryed with a mask but I don't know what I'm doing wrong. Do you know how can I do it?. Perhaps is a obiously answer for this simple question but I don't have any idea ( It is possible that I don't know enought C programation ).

 

Regards;

 

Joan :)

Share this post


Link to post
Share on other sites
Guest Pavel
...but what about read only a pin ?...

Do you really want just read a pin or do something based on its value? Usually the latter is the case:

 

if( gpio & 1 )
{
   /* Bit #0 is set, do something...*/
}
else
{
   /* Bit #0 is clear, do something else...*/
}

 

A while ago I also put a small article how to use bit flags. It can be found here.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

// Example to see how to work with gpio bits

// In this example we will see how to set & clear only a pin

// and how to read only one pin of gpio

 

#include "system.h"

 

#define bitmask_0 0x01      // bitmask_0 = 00000001b

#define bitmask_1 0x02      // bitmask_1 = 00000010b

#define bitmask_2 0x04      // bitmask_2 = 00000100b

#define bitmask_3 0x08      // bitmask_3 = 00001000b

#define bitmask_4 0x10      // bitmask_4 = 00010000b

#define bitmask_5 0x20      // bitmask_5 = 00100000b

#define bitmask_6 0x40      // bitmask_6 = 01000000b

#define bitmask_7 0x80      // bitmask_7 = 10000000b

 

char GPV;

 

main()

{

trisio = 000101000b; // ( Output=0;Input=1; XXX,XXX,XXX,GP5,GP4,GP3,GP2,GP1,GP0)

cmcon = 7;     // GP0,GP1,GP2,GP4 are Outputs

gpio = 0x00; // GP3,GP5 are Inputs (GP3 is ONLY INPUT ever)

// XXX are not used bits because GPIO only have 6 I/O pins

 

while (1)

{

GPV = gpio; // GPV is not necessary

 

if (GPV&bitmask_3) // We can do -->  if (gpio&bitmask_3)

{

set_bit(gpio,0);

}

else

{

set_bit(gpio,0);

}

 

if (GPV&bitmask_5) // We can do --> if (gpio&bitmask_5)

{

set_bit(gpio,4);

}

else

{

clear_bit(gpio,4);

}

}

}

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...