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.
char a;
PB0 = !!a; // first logical not converts to inverted bool, second un-inverts the value
PB0 = ~!a; // first logical not converts to inverted bool, bit not un-inverts
PB0 = a>0;
//Macro's
#define SetPin(Port, Bit) Port |= (1 << Bit)
#define ClearPin(Port, Bit) Port &= ~(1 << Bit)
//Allows you to do the following in code...
SetPin(PORTB, PB3); //Sets bit 3 on port B
ClearPin(PORTA, PA1); //Clears bit 1 on port A
if (Value)
SetPin(PORTA, PA1);
else
ClearPin(PORTA, PA1);
#define PinVal(Port, Bit, Val) Port = Val ? Port | (1 << Bit) : Port & ~(1 << Bit);
//Allows you to do the following in code
PinVal(PORTB, PB3, Value); //Will set bit 3 on port B if Value is nonzero, clear otherwise.
#ifndef cb
#define cb(reg, bit) reg &= ~(1<<bit) //clear bit
#endif
#ifndef sb
#define sb(reg, bit) reg |= (1<<bit) //set bit
#endif
#ifndef rb
#define rb(reg, bit) (reg & (1<<bit)) //read bit
#endif
int main(void)
{
sb(DDRB, 0); //port b 0 as output for led
while(1)
{
if( rb(PIND, 2) )
{
sb(PORTB, 0); //led on
}
else
{
cb(PORTB, 0); //led off
}
}
}