Showing posts with label ports. Show all posts
Showing posts with label ports. Show all posts

XMEGA tutorial: ports (04)

|

Port is the fundamental peripheral, which enables connection between microcontroller and other devices. In well known and appreciated processors: ATtiny & ATmega each port used to have three registers: PIN, PORT and DDR. However in XMEGA microcontrollers there are 21 registers for each port... but don't worry! Using the XMEGA ports is even easier than in ATmega!

All ports have unique name: PORTA, PORTB, PORTC... and so on until the end of alphabet! Within each port there are several registers and some of the most important are listed below:
  • DIR – this one register decides which of the pins is supposed to be an input or output. Typing 1 will configure the pin as an output and 0 as input. For example, the instruction below sets pins 3 and 6 as outputs, therefore the other pins will be inputs:
    
    PORTA.DIR = PIN3_bm | PIN6_bm;
     
  • OUT - this is the output register. Typing 1 will cause the appearance of high state of appropriate "leg" of port, while 0 means low state.
  • IN – is the input register, used for reading current pin state. Here is the example of conditional statement (branch control structure) which checks if the state on the pin E5 is high:
    
    if(PORTE.IN & PIN5_bm)