Pages

Monday 16 March 2015

Programming With AVR Microcontroller: Chapter-1

OVERVIEW:
ATmega16 is an 8-bit high performance microcontroller of Atmel’s Mega AVR family with low power consumption. Atmega16 is based on enhanced RISC architecture with 131 powerful instructions. Most of the instructions execute in one machine cycle. Atmega16 can work on a maximum frequency of 16MHz.

PORTS:
There are 32 I/O (Input/Output) pins grouped as A, B, C & D with 8 pins in each group. This group is called as PORT.
PA0 - PA7 (PORTA)
PB0 - PB7 (PORTB)
PC0 - PC7 (PORTC)
PD0 - PD7 (PORTD)


These are additional function that pin can perform other than I/O. Some of them are.
  • ADC (ADC0 - ADC7 on PORTA)
  • UART (Rx,Tx on PORTD)
  • TIMERS (OC0 - OC2)
  • SPI (MISO, MOSI, SCK on PORTB)
  • External Interrupts (INT0 - INT2)


PIN DESCRIPTION:
  • VCC: Digital supply voltage. (+5V)
  • GND: Ground. (0 V) Note there are 2 ground Pins.

  • Port A (PA7 - PA0)

Port A serves as the analog inputs to the A/D Converter. Port A also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. When pins PA0 to PA7 are used as inputs and are externally pulled low, they will source current if the internal pull-up resistors are activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock is not running.
 



  • Port B (PB7 - PB0)
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). Port B also serves the functions of various special features of the ATmega16 as listed on page 58 of datasheet.
  • Port C (PC7 - PC0)
Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). Port C also serves the functions of the JTAG interface and other special features of the ATmega16 as listed on page 61 of datasheet. 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.
  • Port D (PD7 - PD0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). Port D also serves the functions of various special features of the ATmega16 as listed on page 63 of datasheet.
  • RESET: Reset Input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running.
  • XTAL1: External oscillator pin 1
  • XTAL2: External oscillator pin 2
  • AVCC: AVCC is the supply voltage pin for Port A and the A/D Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter.
  • AREF: AREF is the analog reference pin for the A/D Converter.
 WRITING THE CODE
  

  1.   AVR STUDIO 
Setup:
  1. open AVR studio 4
  2. click new project
  3. Select AVR GCC as we would be doing program in c and enter the project name.

4.Add your project name. Here I have given my project name as serial and it will automatically create your initial file name in .c format


 5.click on next 

6.Select AVR simulator in debug platform and in the Device select the Device your using as here I am using ATmega 16 i have selected that.(for Atmega 32 select Atmega 32).







 7.click on finish
8.This is the default window you will see after you click on finish and project name called serial will get open  
9.Now click on this to create a new file


10.Type the program and save it .To compile the files first you need to add files in your source for doing that right click on the source file and then 



click on add existing source file
11.Now inside that source file their will be your file saved here the file name I have used is urted
12.Now to build the file go to build and click on build
13.If your program has no errors  it will be successfully build and it will show the build window like this


TO BURN  THE  PROGRAM   IN  YOUR  MICROCONTROLLER  YOU  NEED  A BURNER  FOR BURNING  WE  USE AVR OPS-2