AVR
AVR
VIRTUAL
(ADVANCED
RISC )-- 8 BIT RISC
ATMEL ATMEGA32
MICROCONTROLLER
AVR (1994)
→ 8 bit bus, RISC architecture
→ one instruction per cycle
→ Harvard architecture . (separate bus for program and data memory)
→ Compilers Avr studio GCC, WinAVR, MikroC etc
INTRO TO ATMEGA32
8- bit Microcontroller with 4 I/O ports , PORTA,PORTB,PORTC,PORTD.
RAM = 2Kb , Flash = 32Kb , EEPROM = 1k
Maximum Crystal Frequency = 16MHz
8 ADC’s with 10-bit Resolution
One 16-bit timer/counter with separate prescaler, compare mode and
capture mode.
Two 8-bit timers/counters with separate prescalers and compare
modes
4 PWM channels
1- USART
Master/slave SPI serial interface
External interrupts
II: Atmega8 – Basic features
Pin and Port Overview
ATMEGA32:
GND: Ground (0V)
VCC: Digital Supply Voltage (2,7 – 5,5V)
AVCC: Analog Supply Voltage for PORTA and ADC’s.
connect to low-pass filtered VCC
AREF: Analog Reference Voltage, usually AVCC
Reset’: Low level on this pin will generate a reset
Examples: Example :
PORTA |= (1 << 2); // sets bit#2 at PortA DDRC.DDRC1=1; //make PC1 pin o/p
PORTA &= ~(1 << 3); //reset bit#3 at PortA
DDRA &= ~( (1<<0) | (1<<3) ); //PA0 and PA3 as inputs
PORTA |= (1<<0) | (1<<3); // internal Pull UP for both switch
on
while(1)
{
PORTC = PINB; //Read PORTB and send it to PORTC
}
}
A door sensor is connected to the PA1 pin, and a buzzer is connected to PA7. Write an MIKROC program to
monitor the door sensor, and when it opens, sound the buzzer. You can sound the buzzer by sending a square
wave of a few hundred Hz.
Code:
sbit Dsensor at PINA.PINA1;
void main(void)
{
DDRA.DDRA1=0; //Make PA1 (Door sensor pin) as input
DDRA.DDRA7=1; // Make PA7 (Buzzer pin) output
while (1)
{
while (Dsensor==1) //while it opens means switch is pressed
{
PORTA.PORTA7=0; //buzzer attached with PA7
delay_ms(200);
PORTA.PORTA7=1;
delay_ms(200);
}
}
}
LETS DISCUSS ADC’s
OF ATMEGA32
INTRO to ADC’S of
ATMEGA32
8 ADC’s (ADC0-ADC7) multiplexed with PORTA pins.
The A/D module has five 8-bit registers. These registers are: