Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
How can I manage the high value of bits ?
eg :
if portc.f1 is high for 3minitues it should clear and go to low
can u give the code for spliting the Port into individual bits ?
typedef union
{
volatile unsigned char value;
struct
{
volatile unsigned char pin0 : 1,
pin1 : 1,
pin2 : 1,
pin3 : 1,
pin4 : 1,
pin5 : 1,
pin6 : 1,
pin7 : 1;
};
} _PORT;
#define _PORTA (*(_PORT *) &PORTA)
_PORTA.value = 0xFF; //set all portA pins
_PORTA.pin0 = 0; //clear pin A0
_PORTA.pin5 = 1; //set pin A5
There are a few ways. The following one involves port declaring as well, otherwise you would need more defines for all ports.varunme said:can we access this inside a loop ?
#define _SET_PIN(port,bit) _PORT##port##.value|=(1<<bit)
#define _CLR_PIN(port,bit) _PORT##port##.value&=~(1<<bit)
#define _TOG_PIN(port,bit) _PORT##port##.value^=(1<<bit)
_PORTA.value = 0;
for(int i = 0; i < 8; i++)
{
_SET_PIN(A,i);
_CLR_PIN(A,i);
_TOG_PIN(A,i);
_TOG_PIN(A,i);
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // add this defines #define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT)) #define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT)) #define FLIPBIT(ADDRESS,BIT) (ADDRESS ^= (1<<BIT)) #define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT)) #define WRITEBIT(RADDRESS,RBIT,WADDRESS,WBIT) (CHECKBIT(RADDRESS,RBIT) ? SETBIT(WADDRESS,WBIT) : CLEARBIT(WADDRESS,WBIT)) // and then you can use SETBIT(PORTX,2); // set bit2 of portx (set to 1) SETBIT(PORTY,0); // set bit0 of porty CLEARBIT(PORTX,5); // clear bit5 of portx (set to 0) FLIPBIT(PORTX,2); // invert bit2 of portX, if it was 1 it becomes 0, and if 0 becomes 1 // example for portx 0x10101010 the result is 0x10101110 if (CHECKBIT(PORTX,4)) {} else {} // result is true if bit4 of portx is 1, false if it is 0 if (!CHECKBIT(PORTX,4)) {} else {} // result is true if bit4 of portx is 0, false if it is 1 WRITEBIT(PORTX,0,PORTY,2); // copy the bit0 of portx to bit2 of porty