Lab3 PDF
Lab3 PDF
A microcontroller often serves as the brain of a mechatronic system. Like a mini, selfcontained computer, it can be programmed to interact with both the hardware of the system
and the user. Even the most basic microcontroller can perform simple math operations,
control digital outputs, and monitor digital inputs. As the computer industry has evolved, so
has the technology associated with microcontrollers. Newer microcontrollers are much faster,
have more memory, and have a host of input and output features that dwarf the ability of
earlier models. Most modern controllers have analog-to-digital converters, high-speed timers
and counters, interrupt capabilities, outputs that can be pulse-width modulated, serial
communication ports, etc.
ATmega32 microcontroller:
Page 1
Atmels ATMega32 8-Bit Processor. 32K of program space, 32 I/O lines, 8 of which are
10bit Analog to Digital converter capable. Runs up to 16MHz with external crystal.
Digital I/O ports (PORTA ~ PORTD) of ATMEL ATMEGA32
8 pins are grouped together as ports. Generally there are 4 or more ports in an AVR.
The ports are named in in alphabetic letters, such as PORTA, PORTB, PORTC and
PORTD etc. Each port has 8 pins, from 0 to 7. For example, the pins of port B are
PB7, PB6, PB5, PB4, PB3, PB2, PB1, PB0
As you can see above, the atmega32 has 4 ports, A, B, C and D and each of them
have 8 pins. Most of the pins have some additional bracketed name, (for example
(RXD) on PD0.
This means that this pin is also an RXD pin).
Page 2
A well designed Trainer board is always essential for smooth development/experimentation with
microcontrollers. Every hobbyist or student must have some kind of development setup. Some people
use breadboard while others use general PCB to fabricate their development system. Development is
not very easy if bread boards or general PCB are used. If bread board is used, after few days of use the
wire will become loose or come out of the hole. While making large circuit in a general PCB is a
tedious job.
Such problems are solved by using AVR Trainer kit. It is a circuit board with basic connection
required to drive the microcontroller and also with features like serial port, LCD display, seven
segment displays, prototyping area, power supply and it supports 40 and 28 PDIP pin AVR Microcontrollers etc.
A trainer board is very useful as you can program the microcontroller and also check the outputs using
the LEDs or LCD display or even connect it to the rest of the project using wires or connectors. The
power supply provided on the board can be used to supply power to other circuits. The board also has
provision to run DC motors or even stepper motors with the help of motor driver ICs present on the
board.
A very good advantage of such a trainer board is that all the basic project requirements are present on
the board and it also occupies less space even with all the modules like LCD and seven segment
displays. The AVR trainer kit has features which helps you in making and testing a project involving a
variety of modules like:
Standard 40 Pin and 28 Pin PDIP Atmel AVR Series Chip support.
On Board integrated universal Atmel AVR USB Programmer with ZIP Socket
support
On Board 3 different Power Sources (5V, 12V, Variable 0-15V).
8 Logical LED display.
LCD Display
4 Digit 7 Segment Display
8*8 Dot-matrix Display
External 512byte EEPROM
DS1307 RTC(Real Time Clock) with 3V Battery Supported
RS232 Serial Communication Supported Via PC
Motor Support: DC, Stepper, Servo
IR Transmitter and Receiver Supported
Relay Supported for 2 different High voltage System Control
4 Input Switch
4*4 Matrix keypad
LDR (Light Dependent Resister)
LM35 Temperature Sensor
Variable Resistor(Pot) for volume support
A bread board also installed on trainer kit for extra components interfacing support
User friendly Output PORT excess
CodeVisionAVR:
CodeVision avr is a C cross-compiler, integrated development and automatic program
United International University (UIU)
Page 3
Page 4
4. Now a window opens for including various functions or header files in your program
automatically. First select your controller from chip option.
5. If you used LCD in your project then go to LCD and select LCD port.
Page 5
Page 6
7. Now this window opens 3 times save your project at the location you want and typr the file
name like evm in all 3 windows. All 3 file names must be same.
8. Now a project window opens where necessary header files are included automatically. You
also can include any header file you want from the CVAVR library.
Page 7
11. Declare all the variables above and scroll down to see while(1) function and write your
code in while(1).
12. Click the button as shown in window for building your project.
Page 8
13. Now a windows open make sure there is no error and no warning.
Page 9
Proteus:
Proteus has many features togenerate both analogue and digital result. However, this lab will
focus on only tools that will be used in digital schematic designs.
Page 10
LED interfacing
The first session in AVR Trainer kit V2 will begin with an experiment that flashes an LED on
and off. While this looks very simple it is the best project to start because this makes sure that
one can successfully wrote the program, compiled it, loaded inside the AVR, and check the
hardware simulation using AVR trainer kit.
In this lab session connect an LED to one of the port pin of Atmega32 and flash it
continuously with 1 sec duration.
One of the most basic features of any microprocessor is to be able to use the pins as general
input and output pin. The Pins as output pins can be used as both source (logic 1) and sink
(logic 0). The pins also have an internal pull-up resistor to avoid floating.
Page 11
let us assume we want to set PORTC as output and drive logic 1 on the first 4 LSB
pins. So, we need to set this port as output first using the DDR register setting a logic
one on the corresponding port. Take a look at the 3 example below
DDRC = 0b11111111; //here all the 8 pins of Port C are set as output
PORTC = 0b11110000; // PC7, PC6, PC5, PC4 will drive logic 1
This is a better example (red means logic 1, black means logic 0)
#include <atmega32.h>
main()
{
DDRC = 0b11111111;
PORTC = 0b11110000;
}
Important Notes :
If a pin is declared input (0 on DDR) but port pin has logic 1, there will still be
no output driven.
If a pin is declared output but Port pin drives logic 0 (sink), it acts like a ground
pin. (e.g.. Let us assume we have declared PB6 and PB5 as output but we are driving
logic 1 on PB5 only and logic 0 on PB6. We can then connect an LED with positive
terminal on PB5 and ground terminal on PB6. This method is very much used in
multiplexing LED or keypad inputs)
The PUD in SFIOR, when set to logic 1 will disable all pull up resistors. And if
set to logic 0, the DDR and PORT registers will declare it.
Page 12
Circuit Setup
1. First of all power up the trainer kit via given power supply adapter.
2. Then connect PORTB PB0 (pin1) with LED light placed on the trainer kit by given
connecting wire.
3. Now write the given code for flashing LED with 1 sec interval on codevision avr and build
the hex file.
4. Burn the code using in-built ISP programmer of AVR Trainer kit.
5. Check the hardware output.
Program:
Chip type
: ATmega32L
Program type
: Application
AVR Core Clock frequency: 8.000000 MHz
Memory model
: Small
External RAM size
:0
Data Stack size
: 512
*****************************************************/
#include <mega32.h>
#include <delay.h>
// Declare your global variables here
void main(void)
{
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=Out
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=0
United International University (UIU)
Page 13
1. There are eight led on the board. Blink all the even led and odd led. Use 2 second
delay.
2. Blink all the led one after another. Use 1 second delay.
Page 14