Products > Programming

Noob: C port

(1/4) > >>

PerranOak:
In my PIC C programming course I've come across a command that is not explained:

static bit button @ (unsigned) &PORTA*8+1;

What I think I know is:
the code is to assign the name "button" to RA1, static means that the value of "button" is to be retained between functions, unsigned means that the value of "button" has no mathematical sign and PORTA is port A(!)

I don't understand what these are doing:
bit, @, & (though I believe this is "logical .AND."), *8, 1 (I guess this refers to bit 1 of PORTA).

I'm not necessarily looking for descriptions (though all help is welcome) but where do I look to understand these things? I have Kernighan & Ritchie but this is not really a reference.

Cheers.

ledtester:
The @-sign is a compiler extension which allows you to specify the address of a global variable:

https://stackoverflow.com/questions/15955856/sign-in-c-variable-declaration

In this case it looks like a bit-variable is being defined at a specific bit-address - hence the PORTA*8+1 expression.

sokoloff:
& is "address of"
(&& is "logical AND")

Read that as roughly:
Take the address of PORTA (&PORTA), multiply by 8 (*8), add 1 (+1) to get to the bit you want.

SiliconWizard:
Additionally, '&' has two forms, unary and binary. Reminds me of another thread...

PerranOak:
Cheers all.

So, why is it "*8"? Does each bit have an address?  :-//

Navigation

[0] Message Index

[#] Next page

There was an error while thanking
Thanking...
Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod