Jump to content

Assinging A Variable To Port Pin


Recommended Posts

I've been trying to assing a variable to a pin on the GPIO port of a 12f683. I cant seem to get the syntax right, do I need to use pragma and define the variable name at the right address of that port in memory?

 

My code is

#pragma bit load @ 5.0 ; // variable (load) is being assigned to the pin 0

 

Any help?

Thanks.

Link to post
Share on other sites
My code is

#pragma bit load @ 5.0 ; // variable (load) is being assigned to the pin 0

Just drop the #pragma i.e.

 

bit load @ 5.0 ; // variable (load) is being assigned to the pin 0

 

Check the reference manual for more info.

 

Regards

 

davidb

Link to post
Share on other sites
My code is

#pragma bit load @ 5.0 ; // variable (load) is being assigned to the pin 0

Just drop the #pragma i.e.

 

bit load @ 5.0 ; // variable (load) is being assigned to the pin 0

 

Check the reference manual for more info.

 

Regards

 

davidb

 

Thanks david but it didnt work. There's nothing in the manual about this that I can see.

Link to post
Share on other sites

o.p.,

 

It works on 16F & 18F but I must admit I haven't tried it on the PIC12F683.

 

'bit' is documented in the the BoostC manual V1.53 on page 45.

 

Don't forget to set the port direction for the bit or bits you are trying to set to output i.e. trisio.5 = 0;

 

Regards

 

davidb

Link to post
Share on other sites
o.p.,

 

It works on 16F & 18F but I must admit I haven't tried it on the PIC12F683.

 

'bit' is documented in the the BoostC manual V1.53 on page 45.

 

Don't forget to set the port direction for the bit or bits you are trying to set to output i.e. trisio.5 = 0;

 

Regards

 

davidb

Link to post
Share on other sites

Disregard my quote post, slip of the finger.

 

I tried:

 

bit load @ 5.0 ;

 

The compiler seems to be ok with it.

Alternatively I could create a GPIO char that acesses to the GPIO register and access each individual bit?

 

ie

char GPIO 5 ;

GPIO.0 = 0;

 

Although I dont think it likes variables to be the same name as registers, but not a big problem. :rolleyes:

 

~o.p.

Link to post
Share on other sites
...Although I dont think it likes variables to be the same name as registers, but not a big problem. :rolleyes:...

 

That's because the identifiers you call "register names" are in fact defines located in system header files (try to comment out system.h include and this line will compile just fine). When you declare a variable like:

 

char GPIO @ 5 ;

 

C preprocessor will transform it into:

 

char 0x0005 @ 5 ;

 

and when this transformed line gets to the compiler it will report an error because it doesn't make sense from C language point of view.

 

The convention used in BoostC system headers is: variable names in small and defines in capital letters. This is just a convention that could have been done differently but because most of C and C++ programmers outside of PIC world use it we decided to use it as well when we were creating system headers for BoostC.

 

Regards,

Pavel

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...
×
×
  • Create New...