You are on page 1of 8

Xc vnvcn vcnxdcvnxbcfhbxddsafcdsVFGSADGvbzfshfscxvbxbvxzSDsafgdshgf vnbvnvnvnb

Descripti on

Alternate Function

sfdfdgfbgf

4 5 6

(OC0/AIN 1) PB3 (SS) PB4 (MOSI) PB5 (MISO) PB6 (SCK) PB7 RESET Vcc GND XTAL2 XTAL1 (RXD) PD0 (TXD) PD1 (INT0) PD2 (INT1) PD3 (OC1B) PD4 (OC1A) PD5 (ICP) PD6 PD7 (OC2) I/O PORTB, Pin 5 I/O PORTB, Pin 6 I/O PORTB, Pin 7 Reset Pin, Active Low Reset Vcc = +5V GROUND Output to Inverting Oscillator Amplifier Input to Inverting Oscillator Amplifier I/O PORTD, USART Pin 0 Serial Communicati I/O on Interface PORTD, Pin 1 I/O External PORTD, Interrupt Pin 2 INT0 I/O External PORTD, Interrupt Pin 3 INT1 I/O PORTD, PWM Pin 4 Channel I/O Outputs PORTD, Pin 5 I/O Timer/Count PORTD, er1 Input Pin 6 Capture Pin Timer/Count I/O er2 Output PORTD, Compare Pin 7 Match

9 10 11 12 13 14

15

16

17

18

19

20

21

Output PC0 (SCL) PC1 (SDA) PC2 (TCK) PC3 (TMS) PC4 (TDO) PC5 (TDI) PC6 (TOSC1) PC7 (TOSC2) AVcc GND AREF PA7 (ADC7) PA6 (ADC6) PA5 (ADC5) PA4 (ADC4) PA3 (ADC3) PA2 (ADC2) PA1 (ADC1) PA0 (ADC0) I/O PORTC, Pin 0 TWI Interface I/O PORTC, Pin 1 I/O PORTC, Pin 2 I/O PORTC, Pin 3 JTAG Interface I/O PORTC, Pin 4 I/O PORTC, Pin 5 I/O Timer PORTC, Oscillator Pin Pin 6 1 I/O Timer PORTC, Oscillator Pin Pin 7 2 Voltage Supply = Vcc for ADC GROUND Analog Reference Pin for ADC I/O PORTA, Pin 7 I/O PORTA, Pin 6 I/O PORTA, Pin 5 I/O PORTA, Pin 4 I/O PORTA, Pin 3 I/O PORTA, Pin 2 I/O PORTA, Pin 1 I/O PORTA, Pin 0 ADC Channel 7 ADC Channel 6 ADC Channel 5 ADC Channel 4 ADC Channel 3 ADC Channel 2 ADC Channel 1 ADC Channel 0

22

23

24

25

26

27

28

29 30 31 32 33

34

35

36

37

38

39

40

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 otherspecial 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 lowpass filter. AREF: AREF is the analog reference pin for the A/D Converter
When an interrupt occurs, the normal flow of instructions is suspended by the microcontroller and the code corresponding to the interrupt, which has occurred, is executed. Once the code corresponding to the interrupt is executed completely the execution again begins from the same instruction where it was stopped.

Following is what happens when an interrupt occurs: 1. 2. Microcontroller normally completes the instruction which is being executed. The program control transfers to Interrupt Service Routine (ISR). Each interrupt have an

associated ISR which is a piece of code which tells the microcontroller what to do when an interrupt has occurred. 3. Execution of ISR is performed by loading the beginning address of the corresponding ISR into

program counter. 4. 5. Execution of ISR continues until the return from the interrupt instruction (RETI) is encountered. When ISR is complete, the microcontroller resumes processing where it left off before the

interrupt occurred, i.e., program control is reverted back to the main program. which is a piece of code which tells the microcontroller what to do when an interrupt has occurred. 3. Execution of ISR is performed by loading the beginning address of the corresponding ISR into

program counter. 4. 5. Execution of ISR continues until the return from the interrupt instruction (RETI) is encountered. When ISR is complete, the microcontroller resumes processing where it left off before the

interrupt occurred, i.e., program control is reverted back to the main program.

The whole process can be visualized by the following flow diagram:

Atmega16 Interrupts Number of available interrupts varies with different microcontrollers of AVR family. Atmega16 in total has twenty one (21) interrupts available. The available interrupts are categorized in two classes:

1.

External Interrupts- Out of the twenty one interrupts available, four interrupts are directly present

on controller pins to handle the interrupts generated by external sources, so they are called as external interrupts. The four available interrupts and their respective pins are shown in the figure below in their order of priority:cgjhghgfjg

Hghgjhhjkjkjjhgjjhjgh

2.

Internal Interrupts- The remaining seventeen (17) interrupts are available for internal use and

support the precise and efficient operation of various peripherals like ADC, Timers, and USARTs etc. The table below describes the available internal interrupts in the order of their priority:

S. No. 1 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17.

INTERRUPT TIMER2 COMP TIMER2 OVF TIMER1 CAPT TIMER COMPA TIMER COMPB TIMER1 OVF TIMER0 OVF SPI, STC USART,RXC USART, UDRE USART, TXC ADC EE_RDY ANA_COMP TWI TIMER0 COMP SPM_RDY

DEFINITION Timer/Counter2 Compare match interrupt Timer2 Overflow interrupt Timer/Counter1 Capture Event interrupt Timer/Counter1 Compare Match A interrupt Timer/Counter Compare Match B interrupt Timer/Counter1 Overflow interrupt Timer/Counter0 Overflow interrupt Serial Transfer Complete interrupt USART Receive Complete interrupt USART Data Register Empty interrupt USART Transmit Complete interrupt ADC Conversion Complete interrupt EEPROM Ready interrupt Analog Comparator interrupt Two-wire serial interface interrupt Timer/Countrt0 Compare Match interrupt Store Program Memory Read interrupt

The internal interrupts will be discussed with their respective peripherals. The external interrupts are mainly focused in this article.

External Interrupts Configuration Registers: To configure an external interrupt INT0, INT1 or INT2,it is required to initialize the respective interrupt by doing appropriate bit settings of following 4 registers. The scope of this document is limited to the explanation of the bits corresponding to to 1. By default all the interrupts are disabled. Above mentioned three registers have to be configured accordingly to initialize a particular interrupt. Also note that in addition to the above mentioned registers, the I-bit (Bit7, Global Interrupt Enable) of SREG register must also be set to 1. If Global Interrupt enable bit is set to 0, none of the interrupts will work irrespective of the other register settings. The set and clear of I-bit is done by SEI and CLI instructions.

Programming Steps: For programming an interrupt, the following steps must be followed: 1. 2. 3. 4. Clear Global Interrupt enable bit in SREG register. Initialize the interrupt by appropriately configuring the MCUCR, MCUCSR and GICR registers. Set Global Interrupt Enable bit in SREG register. Define the appropriate Interrupt service routine (ISR) for the interrupt.

There are two ways of writing ISR, for e.g. ISR for INT0 can be written in following two ways: A. ISR (INT0_vect) B. SIGNAL (SIG_INTERRUPT0)

sVDZBNcmnbcv

zddcfjgkhkhk jljhkljlkkgl.jh,hk,jkljkljkgftfg vx bc faegfdghgfhjgfchfcvhsxdy hukjkcvcvxbvbk ugiklhjlhjkl hjlkph;klhlkj ujholhjkoluiop;p jhlgjluk;;ilu hjlhkoli;k; yuypipuouipypkyo jjhkkjhfhjjkh

You might also like