No way to do this. In C++ you could overload operators and create functions to simulate it, but not in C.
You could write functions that simulate it, but again it's non-ideal.
#define S_PORT_A_MASK 0xAA // Stitched port bits 1, 3, 5, 6
#define S_PORT_B_MASK 0x55 // Stitched port bits 0, 2, 4, 6
void SetStitchedPortVal(uint8 val) {
uint8 val_a;
uint8 val_b;
val_a = val & S_PORT_A_MASK;
val_b = val & S_PORT_B_MASK;
setportA(val_a);
setportB(val_b);
}
It's just a lot messier in C.
doraemon, interesting way you have there of masking the untargeted bits.
No way to do this. In C++ you could overload operators and create functions to simulate it, but not in C. You could write functions that simulate it, but again it's non-ideal.
#define SPORT_A_MASK 0xAA // Bits 1, 3, 5, 7 of stitched port
#define SPORT_B_MASK 0x55 // Bits 0, 2, 4, 6 of stitched port
void SetStitchedPortVal(uint8 val) {
uint8 val_a;
uint8 val_b;
val_a = val & SPORT_A_MASK;
val_b = val * SPORT_B_MASK;
PortA &= ~SPORT_A_MASK;
PortA |= val_a;
PortB &= ~SPORT_B_MASK;
portB |= val_b;
}
Could you write it in your own clean way in C++? That would be useful for everybody.
Usually what is clean and what is messy is just a matter of taste.
SPort myporta;
// set my port to any value, e.g. 0xff:
myporta=0xff;
class SPort
{
public:
SPort()
{
pA=&PORTA;
pB=&PORTB;
}
SPort & operator=(const char &val)
{
*pA=val & 0x55;
*pB=val & 0xAA;
}
private:
char* pA;
char* pB;
};
your main code would end up looking like this, which is certainly cleaner:
Code:SPort myporta; // set my port to any value, e.g. 0xff: myporta=0xff;
SetStitchedPortVal(0xFF);
typedef struct MyStruct {
int mMember1;
char * mMember2;
void (*setMember1)(int m1);
void (*setMember2)(char * m2);
};
You can argue that using a class is "just a matter of taste", and others may argue it is not 'less messier',
oops! What was the problem? Let us concentrate on that
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 volatile unsigned char PORTZ ; volatile bit RZ0 @ ((unsigned)&PORTA*8)+1; volatile bit RZ1 @ ((unsigned)&PORTA*8)+3; volatile bit RZ2 @ ((unsigned)&PORTA*8)+5; volatile bit RZ3 @ ((unsigned)&PORTA*8)+7; volatile bit RZ4 @ ((unsigned)&PORTB*8)+0; volatile bit RZ5 @ ((unsigned)&PORTB*8)+2; volatile bit RZ6 @ ((unsigned)&PORTB*8)+4; volatile bit RZ7 @ ((unsigned)&PORTB*8)+6; volatile union { struct { unsigned RZ0 : 1; unsigned RZ1 : 1; unsigned RZ2 : 1; unsigned RZ3 : 1; unsigned RZ4 : 1; unsigned RZ5 : 1; unsigned RZ6 : 1; unsigned RZ7 : 1; }; } PORTZbits;
PIC I/O SFRs are byte registers and can't be accessed by bit addresses as your code apparently assumes. All accesses to individual pins or pin groups have to rely on bit masks. All high level methods will reflect this somehow.I wonder, if the following code might work.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 //orginal PORT B declaration PORTB equ 0006h #define RB0 BANKMASK(PORTB), 0 #define RB1 BANKMASK(PORTB), 1 #define RB2 BANKMASK(PORTB), 2 #define RB3 BANKMASK(PORTB), 3 #define RB4 BANKMASK(PORTB), 4 #define RB5 BANKMASK(PORTB), 5 #define RB6 BANKMASK(PORTB), 6 #define RB7 BANKMASK(PORTB), 7 #ifndef _LIB_BUILD #endif //new declaration PORTB equ 0006h #define RZ3 BANKMASK(PORTB), 0 //new RZ3 #define RB1 BANKMASK(PORTB), 1 #define RZ2 BANKMASK(PORTB), 2 //new RZ2 #define RB3 BANKMASK(PORTB), 3 #define RZ1 BANKMASK(PORTB), 4 //new RZ1 #define RB5 BANKMASK(PORTB), 5 #define RZ0 BANKMASK(PORTB), 6 //new RZ0 #define RB7 BANKMASK(PORTB), 7 #ifndef _LIB_BUILD #endif
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?