Quote from: Buriedcode on Yesterday at 23:28:12
Also, you can set/clear multiple bits in a register, or rather set multiple bits, or clear them:
Code:
[Select]PSTR1CON |= (1<<bit1) | (1<<bit2) | (1<<bit3);
PSTR1CON &= ~((1<<bit1) | (1<<bit2) | (1<<bit3)); // note the extra parenthesis
Well yeah and the names of bit1, bit2, etc? That´s my point you see... In AVR GCC you have this, with the PIC not so much.
Quote from: Buriedcode on Yesterday at 23:28:12And yes, setting the bits one by one explicitly isn't particularly efficient - but often registers only have to be set once at start up. Doing it one by one also means you can see exactly how each register is configured.
Well sometimes you can write to the complete register and it will do its thing. There was one time though, I can´t remember with which peripheral it was, using AVR, that the bits in the same register had
to be configured one at a time. And that was not clear at all in the datasheet, if even mentioned, but it´s been some time I got to see my older code to tell exactly where the problem was.
Quote from: Buriedcode on Yesterday at 23:28:12It would be nice if they made the free compilers less bloaty
Oh that´s the funny part really... XC8 is not based on an open source compiler but rather the old Hi-Tech C compiler.
And yet the AVR compiler manages to be cleaner on a lot of stuff, which is based on GCC.
BTW just for the laughs, as much as I praise the AVR GCC, the PIC peripherals although convoluted are very flexible. TWI on AVRs gave me f*****g cancer.
I was trying to code a real time system and had to use pointers to structures and I can´t even remember what else all cause they couldn´t include a transmission ready bit on the HW level.
Cancer, simply cancer and these are not things you would thing of on the designing phase. But I digress! Now I get the cancer from the PWM set up in PICs.
You spend more time designing how your functions want to be rather than implementing them... pff...
PS: Important Important! I´ve been doing some digging in the compiler files, so of course there is a "rather cancerous" way to do it the AVR way, of course few must know of this.
For my example it would be:Code:
[Select]PSTR1CON |= (1<<_PSTR1CON_STRA_POSN) | (1<<_PSTR1CON_STRB_POSN) | (1<<_PSTR1CON_STRC_POSN);
Cancer but it is exactly the same as in AVRs and this is well hidden! I had to look in the microcontroller header file, that´s a 46k line header file, although repetitive you can miss what you are looking for!
Cheers,
Lefteris