User manual
316Bibliotheken
© 2013 Conrad Electronic
5.18.11 Port Beispiel (Mega)
// Programm läßt abwechselnd die beiden LEDs auf dem
// Application Board im Sekunden Rhythmus blinken
// C-Control Pro Mega
void main(void)
{
Port_DataDirBit(PORT_LED1,PORT_OUT);
Port_DataDirBit(PORT_LED2,PORT_OUT);
while(true) // Endlosschleife
{
Port_WriteBit(PORT_LED1,PORT_ON);
Port_WriteBit(PORT_LED2,PORT_OFF);
AbsDelay(1000);
Port_WriteBit(PORT_LED1,PORT_OFF);
Port_WriteBit(PORT_LED2,PORT_ON);
AbsDelay(1000);
}
}
5.18.12 Port Beispiel (AVR32Bit)
Alle drei Programmbeispiele lassen LED1 leuchten solange Taster T1 gedrückt wird. Die Beispiele
unterscheiden sich in der Adressierung der Port Namen. Wenn der Taster nicht gedrückt wird, so
wird vom Port eine "1" gelesen, da auf dem Applicationboard jeder Taster mit einem Pull-Up Wider-
stand verbunden ist.
// Beispiel mit 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) // Endlosschleife
{
if(Port_ReadBit(PORT_T1))
{
Port_WriteBit(PORT_LED1, PORT_OFF);
}
else
{
Port_WriteBit(PORT_LED1, PORT_ON);
}
}
}