>> Also, I'm wondering why you need such as array to assign to the port. As far as I see it, your purpose is to avoid nested ifs and use the port as a lookup table.
I think he need to use that array in a for loop. If so use that index method provided by neo.
as said , you could not create arrays of bits.
And your defines are wrong.
from the sdcc project includes in \device\non-free\include\pic14\pic16f84a.h include header file,
it defines like this.
Code: Select all
#define RA0 PORTAbits.RA0 /* bit 0 */
#define RA1 PORTAbits.RA1 /* bit 1 */
#define RA2 PORTAbits.RA2 /* bit 2 */
#define RA3 PORTAbits.RA3 /* bit 3 */
#define RA4 PORTAbits.RA4 /* bit 4 */
#define RB0 PORTBbits.RB0 /* bit 0 */
#define RB1 PORTBbits.RB1 /* bit 1 */
#define RB2 PORTBbits.RB2 /* bit 2 */
#define RB3 PORTBbits.RB3 /* bit 3 */
#define RB4 PORTBbits.RB4 /* bit 4 */
#define RB5 PORTBbits.RB5 /* bit 5 */
#define RB6 PORTBbits.RB6 /* bit 6 */
#define RB7 PORTBbits.RB7 /* bit 7 */
Don't worry to read the header files and if you don't understand what's it, then refer back to the manual of the
compiler and see what's that?
http://www.mikroe.com/download/eng/docu ... l_bits.htm
Every source code file was written by a man for another man first and compiler to the second.
In the case you don't understand what the bellow code ":" , it simply used to limit the number of bits used in
that datatype. So when you need a variable with 3-bits , you could define it inside a structure. Note that
this feature is only avaliable to be used inside 'structures' and classes.
Code: Select all
// ----- PORTB bits --------------------
typedef union {
struct {
unsigned char RB0:1;
unsigned char RB1:1;
unsigned char RB2:1;
unsigned char RB3:1;
unsigned char RB4:1;
unsigned char RB5:1;
unsigned char RB6:1;
unsigned char RB7:1;
};
} __PORTBbits_t;
extern volatile __PORTBbits_t __at(PORTB_ADDR) PORTBbits;
I think whole the code is clear to you now. Crystal clear? Then nice code reviewing.