Instructions
310Libraries
© 2013 Conrad Electronic
5.18.12 Port Example (AVR32Bit)
All three program examples will light LED1 as long as button T1 is pressed. The examples differ in
addressing the port name. If the button is not pressed, a "1" will be read from the port because each
switch on the Applicationboard is connected to a pull-up resistor.
// Example with Function Name defines
void main(void)
{
Port_Attribute(PORT_LED1, PORT_ATTR_OUTPUT | PORT_ATTR_INIT_LOW);
Port_Attribute(PORT_T1, PORT_ATTR_INPUT);
while(true) // endless loop
{
if(Port_ReadBit(PORT_T1))
{
Port_WriteBit(PORT_LED1, PORT_OFF);
}
else
{
Port_WriteBit(PORT_LED1, PORT_ON);
}
}
}
// LED1 will be lit as long as button T1 is pressed
// Example with Unit Name defines
void main(void)
{
Port_Attribute(P48, PORT_ATTR_OUTPUT | PORT_ATTR_INIT_LOW);
Port_Attribute(P41, PORT_ATTR_INPUT);
while(true) // Endlosschleife
{
if(Port_ReadBit(P41))
{
Port_WriteBit(P48, PORT_OFF);
}
else
{
Port_WriteBit(P48, PORT_ON);
}
}
}
// LED1 will be lit as long as button T1 is pressed
// Example with AVR32 Port Name defines