The AVR ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. The throughput of AVR ATmega16 is about 1 MIPS per MHz using single clock per instruction allowing the system designed to optimize power consumption versus processing speed.The AVR has 32 general purpose working registers and rich instruction set. They are directly connected to the ALU, and allow two independent registers to be accessed in one single instruction executed in one clock cycle.Getting started with avr microcontroller tutorial helps you to understand real time examples. Atmel studio 6 is used for writing c code and generating hexa file.
ATmega16 Microcontroller Features
The AVR ATmega16 provides the following features:
We used Atmega16 because of the following features:
- It has low power CMOS 8-bit controller with AVR RISC
- Its throughput is up to 16MIPS per
- It has 32 General purpose registers directly connected to
- 16 Kbytes In-System programmable flash
- 512 bytes of EEPROM, 1k byte SRAM, JTAG
- Three timer/counter for comparison
- Internal and external interrupts
- Serial programmable USART+I2C protocol
ATmega16 Microcontroller Pin Descriptions
VCC Digital supply voltage
Port A (PA7-PA0) It is used for analog inputs of A / D. But if A/D converter is not enabled it also serves as a self in 8-bit bi-directional port for input and output. Port pins can provide internal pull-up resistors (selected for each bit).
Port B (PB7-PB0) Port B is used as input/output 8-bit bi-directional port having internal pull- up resistors. The output buffers of Port B are of symmetrical drive characteristics having high sink and source capability. When acting as input pins, Port B pins; if pulled externally low; will source current if the pull-up resistors are activated.
Port C (PC7-PC0) Port C’s special feature is JTAG interface. If the JTAG interface is enabled, the pull-up resistors on pins PC5 (TDI), PC3 (TMS) and PC2 (TCK) will be activated even if a reset occurs. Along with this Port C can also be used as input/output 8-bit bi-directional port having internal pull-up resistors.
Port D (PD7-PD0) Port D serves the functions of various special features of the ATmega16 like interrupts input, timer/counter output and UART. In addition to this Port D is used as input/output 8-bit bi-directional port having internal pull-up resistors.
ATmega16 Microcontroller CLOCK SOURCES
ATmega16 has the following clock source options, selectable by Flash Fuse bits as shown below. The clock from the selected source is input to the AVR clock generator, and routed to the appropriate modules. In device clocking option for External Crystal or Ceramic Resonator combination for bits is 1111 or 1010. For External Low-frequency Crystal it is 1001 and for External RC Oscillator 1000 or 0101. Calibrated Internal RC Oscillator 0100 or 0001 and for External Clock it is 0000. Bit “1” means un-programmed while “0” means programmed.
ATmega16 Microcontroller USART
Main feature used from microcontroller is USART used for serial communication between controller and GSM modem. The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a highly supple serial communication device.General Baud rates supported are 1200, 1800, 2400, 4800, 7200, 9600, 14400, 19200, 38400,57600, 115200. In our project we are using 9600. Serial USART Hardware Elements include:
- USART Clock Generator to provide clock source and set baud rate using UBRR
- USART Transmitter to send a character through TxD pin and handle start/stop bit framing, parity bit, shift
- USART Receiver to receive a character through RxD pin and performs the reverse operation of the
- USART Registers to configure control and monitor the serial
USART Baud Rate Registers comprises of two registers, UBRRH and UBRRL, i.e. in total 16 bits. The UBRRH Register shares the same I/O location as the UCSRC Register. To cater this bit 15 (URSEL) i.e. Register Select is used. This bit selects between accessing the UBRRH or the UCSRC Register. It is read as zero when reading UBRRH. The URSEL must be zero when writing the UBRRH. Bit 14:12 are reserved bits for future use. For compatibility with future devices, these bits must be written to zero when UBRRH is written. Bits 11-0 contain the USART baud rate. The UBRRH contains the four most significant bits, and the UBRRL contains the 8 least significant bits of the USART baud rate. Ongoing transmissions by the transmitter and receiver will be corrupted if the baud rate is changed. Writing UBRRL will trigger an immediate update of the baud rate prescaler.
USART Control & Status Registers comprises of three registers; UCSRA, UCSRB and UCSRC; and hold flags and control bits for USART. UCSRA contains following flags: RXC (USART Receive Complete), TXC (USART Transmit Complete), UDRE (USART Data Register Empty), FE (Frame Error), DOR (Data Over Run), PE (Parity Error), MPCM (Multi-processor Communication Mode) and control bit U2X (Double the USART Transmission Speed). UCSRB contains following control bits: RXCIE (RX Complete Interrupt Enable), TXCIE (TX Complete Interrupt Enable), UDRIE (USART Data Register Empty Interrupt Enable), RXEN (Receiver Enable), TXEN (Transmitter Enable), UCSZ2 (Character Size), RXB8 (Receive Data Bit 8) and TXB8 (Transmit Data Bit 8). UCSRC contains following control bits: URSEL (Register Select), UPM1:0 (Parity Mode), USBS (Stop Bit Select), UCSZ1:0 (Character Size) and UCPOL (Clock Polarity).
USART Data Register is the buffer for characters sent or received through the serial port. To start sending a character, write it to UDR. Then to check a received character, read it from UDR.Serial USART main tasks are initializing the serial port, sending a character, receiving a character and sending/receiving formatted strings. Initializing serial port includes setting USART communication parameter (data bit, stop bit, and parity bit), enable transmitter and receiver, setting USART for asynchronous mode and setting baud rate. For sending a character UDRE flag has been set to 1 and then write the character to register UDR for transmission. For receiving a character RXC flag has been set to 1 and then read the received character from register UDR.