Communication between a computer with other devices (scanners, pen-drives, printers etc.) is done through the ports like USB, serial etc. Likewise, the Microcontroller ATmega32 use its ports to communicate with other ICs. ATmega32 Microcontroller is low power CMOS 8-bit microcontroller which is based on the enhanced AVR RISC architecture. If the frequency cycle is 1 MHZ then 1 million instructions can be executed by AVR.
A port consists of 8 pins, at a time only 1-bit data is sent by each pin. A port (8 pins) can send at a time 8-bit data. Each pin can be set up individually. There are four ports in ATmega32 Microcontroller namely Port A, Port B, Port C, and Port D and most of them have a dual function.
PIN Descriptions:
Port A (PA7-PA0): This port serves as the analog inputs to A/D converter. If A/D converter is not used then its functions as the 8-bit bidirectional I/O port.
Port B (PB7-PB0) & Port D (PD7-PD0): These ports are 8-bit bidirectional I/O port. The output buffers of these ports have symmetrical drive characteristics with source capability and high sink. As inputs, if pull-up resistors are activated then these are pulled extremely low. They also serve several specific functions as a feature of ATmega32.
Port C (PC7-PC0): This port is also 8-bit bidirectional I/O port. The pull-up resistors on the pins PC2 (TCK), PC3 (TMS), and PC5 (TDI) will be activated, if the JTAG interface is enabled. JTAG is the Joint Test Action Group, a method to test board level connectors.
VCC: Digital voltage supplyInterfacing of JTAG using port C of ATmega32
GND: Ground pin
Reset: This pin is the input pin.
XTAL1: It serves as an input to the internal clock operating circuit and inverting oscillator amplifier.
XTAL2: This pin serves as an output from the inverting oscillator amplifier.
AVCC: this pin should be connected to VCC. It serves as a supply voltage pin for Port A and A/D converter.
AREF: This pin is the analog reference pin for the A/D converter.
Each I/O port can be configured as an output with the symmetrical drive characteristics. Driver in each pin is 20 mA, strong enough to directly drive the LED displays. With or without the pull-up resistors, all I/O port pins can be configured as the input. The pull-up resistors value may range from 20-50 K ohms. To protect the input circuit from ESD conditions and over or under-voltage, all I/O pins have clamping diodes.
Registers:
There are three registers which set Input Output functions at each port:
DDRX: It determines whether the pin is output or input at Port X.
PORTX: This register sets the output value of the Port X.
PINX: This register reads the value of Port X.
Let’s discuss them in detail.
DDRX (Data Direction Register):
To make any bit in the port as an output or input, this register is used. The bit value is set 0 to make the pin as input and to make the pin as an output, the corresponding bit value is set 1. For example, DDRA=0xFF (0x means Hexadecimal number system), writing this sets all the DDRA bits to 1 and all pins of the port A are now used as Output. In the same way, DDRA=0x00 sets all the DDRA bits to 0 and all pins of the Port A are set as an Input.
PORTX (PORTX Data Register)
PORTX register sets the value of the PORTX. Both cases are discussed below, i.e. when the pin is set as input and when it is set as output.
1. Output Pin:
To set the pin as an output, set the bit value 1, this will make the output High on that bit i.e. +5V and if the value if the bit value is set to zero, now the output is Low on that bit i.e. 0V.
2. Input Pin:
To set the pin as an input, then set its corresponding bit 0 in the PORTX register will make it Tri-Stated and by setting the corresponding bit as 1 will make it Pull Up. Tri-states means if no input voltage is applied on the pin, then the input will be on high impedance (no specific value) on that pin. In case of Pull Up, the input will go to +5V if there is no input voltage specified on that pin.
PINX (DATA READ REGISTER)
To read the port value PINX register is used. When the pin is set as an input then equivalent bit on the PIN register is,
· 0 for Low Input
· 1 for High Input
Let’s understand this with an example, consider a sensor is connected on PC4 and using DDR configured it as an input pin. To read the value PC4 just check the 4th bit of the PINC register whether it’s high or low. PINX register is used only to read bits; cannot be used to write as its purpose is to read the port value.
Comments
Post a Comment