0% found this document useful (0 votes)
3 views

Lab Manual 1

The document outlines a series of experiments for a Microprocessor and Microcontroller course at Vishwakarma Government Engineering College, focusing on ATmega32 and 8085 Microprocessor. It includes detailed descriptions of various assembly language programs for operations such as addition, subtraction, data transfer, and timer programming, as well as C programs for ATmega32. Additionally, it covers practical applications like blinking an LED using Arduino and displaying characters on a 16x2 LCD display.

Uploaded by

luladamff999
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lab Manual 1

The document outlines a series of experiments for a Microprocessor and Microcontroller course at Vishwakarma Government Engineering College, focusing on ATmega32 and 8085 Microprocessor. It includes detailed descriptions of various assembly language programs for operations such as addition, subtraction, data transfer, and timer programming, as well as C programs for ATmega32. Additionally, it covers practical applications like blinking an LED using Arduino and displaying characters on a 16x2 LCD display.

Uploaded by

luladamff999
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Vishwakarma Government Engineering College-Chandkheda

EC Department
Sub: Microprocessor and Microcontroller (3141008)
List of Experiment / Index

Sr. Name of Experiment Date Sign


No.
1 To study and understand various features of ATmega32.

2 Write an assembly language program for addition and


subtraction for 8085 Microprocessor

3 Write an assembly language program (ALP) for data


transfer operations.

4 Write an AVR Assembly language program for addition and


subtraction.

5 Write Assembly language program for multiplication and


division.

6 Write Assembly language program for logical operations.

7 Write an assembly language program for I/O port


operations.
8 Write Assembly language program to convert a
hexadecimal number to a decimal number.
9 Write Assembly language program for timer programming.

10 Write Assembly language program for branch, call and


time delay loop.

11 Write a C language program for ATmega32

12 To blink an LED using Arduino.

13 To display a string of characters on 16*2 LCD display.


Experiment No: 1
To study and understand various features/specifications of ATmega32 IC.
ATmega32 – 8 Bit AVR Microcontroller

The AVR microcontrollers are based on the advanced RISC (Reduced Instruction Set Computer)
architecture. ATmega32 is a low power CMOS 8-bit microcontroller based on the AVR enhanced
RISC architecture. AVR can execute 1 million instructions per second if cycle frequency is 1MHz.
It is also called Microcontroller with Harvard architecture. In Harvard architecture, data bus and
address bus are separate. Thus a greater flow of data is possible through the central processing
unit, and of course, a greater speed of work.

ATmega32 is a powerful microcontroller because of its in system self programmable flash on a


monolithic chip, provides a high flexible and cost effective solution to many embedded control
applications.

Fig 1: General Block diagram of Microcontroller


The mega AVRs have many new features and peripheral capabilities as
shown in below table 1.0

Name Code Data Data I/O Pins ADC Timers


ROM REM EEPROM

ATmega8 8K 1K 0.5K 23 8 3
ATmega16 16K 1K 0.5K 32 8 3
ATmega32 32K 2K 1K 32 8 3
ATmega64 64K 4K 2K 54 8 4
ATmega128 128K 8K 4K 86 16 6

Key Features
32 x 8 general working purpose registers.
32K bytes of in system self programmable flash program memory
2K bytes of internal SRAM
1024 bytes EEPROM
Available in 40 pin DIP, 44 lead QTFP, 44-pad QFN/MLF
32 programmable I/O lines
8 Channel, 10 bit ADC
Two 8-bit timers/counters with separate prescalers and compare modes
One 16-bit timer/counter with separate prescaler, compare mode and capture mode.

4 PWM channels
In system programming by on-chip boot program
Programmable watch dog timer with separate on-chip oscillator.
Programmable serial USART
Master/slave SPI serial interface

Special Microcontroller Features:


Six sleep modes: Idle, ADC noise reduction, power-save, power-down, standby and
extended standby.

Internal calibrated RC oscillator


External and internal interrupt sources
Power on reset and programmable brown-out detection.
Pin Diagram of 8 Bit AVR Microcontroller

Fig 2: Pin Diagram of AtMega32 Microcontroller

Descriptions about all pins are as bellow table1.1

Pin name Description


VCC Digital voltage supply
Ground Ground
PORTA This port serves as analog inputs to the A/D converter. It also
serves as an 8-bit bidirectional I/O port (with pin PA0-PA7) if the
A/D converter is not used.
PORTB t is an 8-bit bidirectional I/O port with pin PB0-PB7. Its output
buffers have symmetrical drive characteristics with both high sink
and source capability. As inputs, these are extremely pulled low if
the pull-up resistors are activated. It also serves various special
function features of the ATmega32.
PORTC It is an 8-bit bidirectional I/O port with PC0PC7. If the JTAG
interface is enabled, the pull-up resistors on pins PC5 (TDI), PC3
(TMS), and PC2 (TCK) will be activated.
PORTD It is an 8-bit bidirectional I/O port with pins PD0-PD7. Port D
pins have alternate function. When a reset condition becomes
active port D lines tristated.
RESET It is an input
XTAL1 It is an input to the inverting oscillator amplifier and input to the
internal clock operating circuit.
XTAL2 It is an output from the inverting oscillator amplifier.
AVCC It is the supply voltage pin for Port A and A/D converter. It should
be connected to VCC.

AREF AREF is the analog reference pin for the A/D converter.

Memory Organization:
The Atmega32 memory is divided into two memory spaces: Program Memory space and the
data memory space.

Fig 3: Memory Organization


The Stack and Stack Pointer:

Stack:
A stack is a consecutive block of data memory allocated by the programmer. This block of memory
can be use both by the microcontroller internal control as well as the programmer to store data
temporarily. The stack operates with a Last In First Out (LIFO) mechanism, i.e the last thing store
on the stack is the first thing to be retrieved from the stack.
Stack Pointer:

The stack pointer is basically a register or registers that holds either "the memory address of the
last location on that stack where data was stored" or "the memory address of the next available
location on the stack to store data." The definition of the stack pointer depends on the design of
the microcontroller

Other Hardware Modules


1. Timers/Counters:

A timer is a simple counter! The input clock of microcontroller and operation of the timer is
independent of the program execution. All the Atmel microcontrollers have Timers as an inbuilt
peripheral. The 8-bit counters can count to 255 whilst the 16- bit counter can count to 65,536.
Timers can run asynchronous to the main AVR core hence timers are totally independent of CPU.
A timer is usually specified by the maximum value to which it can count, beyond which it
overflows and resets to zero. Speed of the counting can be controlled by varying the speed of clock
input to it. As we know, all the components of a microcontroller unit (MCU) are some way
connected to the central processing unit (CPU) and some registers, to share information between
them.

TCNT (Timer/Counter Register): when you reset microcontroller, TCNT becomes zero. It
counts up with each pulse. The content of timer/ counter may be excess using TCNT register.

TCCR (Timer/Counter Control Register): It is used to set mode of operation for time.

OCR (output compare register): The content of OCR register is compared with content of TCNT
register, and when they are equal, OCF will become zero.
2. Interrupts
AVR microcontroller has multiple interrupts sources. The ATmaga32 interrupts are as below:-

1. Reset

2. External hardware interrupts(INT0, INT1, Int2)

3. Timer0(TOV0), Timer1(TOV1), Timer2(TOV2) interrupt

4. Timer1 compare Match A (T1 COMPA), Timer1 Compare Match B, Timer2 compare
(T1 COMPB) Match (T2COMP) and Timer0 compare Match(T0COMP)

5. Serial communication Interrupts TXIF, RXIF UDRE

6. SPI interrupts

7. ADC interrupt-ADIF

3. Serial Port and USART: -

The USART stands for universal synchronous and asynchronous receiver and transmitter. It is a
serial communication of two protocols. This protocol is used for transmitting and receiving the
data bit by bit with respect to clock pulses on a single wire.

The registers that are responsible for serial communication and handling the USART

1. UBRR register (USART baud rate register)

2. UDR register (USART data register)

3. UCSRA register (USART control status register)

4. UCSRV register

5. UCSRC register
Experiment No: 2
Aim: Write an assembly language program for addition and subtraction for 8085
Microprocessor
1. Write a program to load accumulator from 4000h memory location
2. Write a program to store the FF h in memory location 5000h.
3. Write a program to add F0 h and 12 h. Store result in memory location 4000h and 4001h.
4. Write a program to subtract AA h and BB h. Store result in memory location 4000h and
4001h.
Experiment No:3
Aim: Write Assembly Language Program for data transfer operation.
1. Write a program to load 30H and 97H into memory location 0105H and 0106H.
2. Write a program to load 55H into memory location from 300H to 380H.
3. Write a program to transfer 55H into port B.
4. Write an assembly language program to copy data from memory location 0x68 to PORT
C.
5. Write a program to transfer data from R20 register to PORT D register.
Experiment No:4
Aim: Write Assembly Language Program for addition and subtraction operations.

1. Write a program to add 35H and 25H and store the result in R20 register.
2. Write a program to add 759AH and 39H and store the result in R24 and R25 register.
3. Write a program to add following numbers and save result in R20 register(25H,19H,12H).
4. Write a program to add 759AH to BC48H and save the result to R20and R24 register.
5. Write a program to subtract BC48H from 7F9AH and stote the result in R20 and R21
register.
Experiment No:5
Aim: Write Assembly Language Program for multiplication and division operations.
1. Write a program to perform multiplication operation of 77H and 39H.
2. Write a program to perform division operation of 64H and 04H.
Experiment No:6
Aim: To write assembly language program for logical operations.

1. Write a program that finds if number is odd or even in an R20 register.


2. Write a program to convert 0x76 packed BCD number to ASCII , place the ASCII code
into R20 and R21 register.
3. Write a program to clear last four bits of data stored in R20.
4. Find if the data present in R20 and R21 are same or not, using logical instruction.
5. Write a program to read the temperature and test it for value 75. According to the test
results place the temperature value into the registers indicated by following in PORT B.
If T=75 then R16=T; R17=0; R18=0
T>75 R16=0; R17=T; R18=0
T<75 R16=0; R17=0; R18=T.
Experiment No:7
Aim: Write Assembly Language Program for input and output operations.
1. A switch is connected to PB2. Write a program to check status of the switch and do
following. If switch =0 then send letter ‘N’ to PORT A. Otherwise send letter ‘Y’ to PORT
A.
2. A switch is connected to PB3 and LED is connected to PB4 pin, write a program to get
status of the switch and send it to LED and also save the status of switch in memory
location 0x2000.
3. Write a program to create square wave of 50% duty cycle and 66% duty cycle on PC0 and
PC3 respectively.
4. Write a program to monitor PB5 and PB6 pins, when both of them are high send 0xAA to
PORT C, otherwise send 0x55 on PORT C.
5. Write a program to monitor PD3 pin when it is high make a low to high and to low pulse
on PC4 pin.
6. Write a program to toggle all the bits of PORT D continuously.
Experiment No:8

Aim: To write an assembly language program for hexa-decimal to decimal conversion.


Assume that the data memory location 0x315 has a value FDH. Write a program to convert it
into decimal. Save the digits in location 0x322, 0x323 and 0x324. Where least significant bit is
in location 0x322.
Experiment No:9
Aim: Write an Assembly Language Program for timer programming.
1. Assume crystal frequency of 8Mz . Find TCNTO value needed to generate a time delay of
20µs. Use normal mode, and any prescaler mode.
2. Assume crystal frequency of 1Mz.Find OCRO value needed to generate a time delay of
0.2ms. Use CTC mode.
3. Assume crystal frequency of 1Mz.Find OCR1 H and OCR1 L value needed to generate a
time delay of 2ms.
4. Write a program to generate a square wave of 20 KHz . Assume crystal frequency of 8Mz
and use timer 0 for programming. Use normal and CTC mode, generate wave form at PB3
pin.
5. Write a program for timer 1 to generate a square wave of 10KHz .Assume crystal frequency
8MHz . Do it by normal mode and CTC mode, generate wave form at PB3 pin.
Experiment No:10
Aim: To write a program for branch, Call and time delay loop .
1. Write a program to send 55H to PORT B 200 times.
2. Write a program to see if the internal RAM location 190 H contain an even value if so send
it to PORT B if not make it even and send it to PORT B.
Experiment No:11
Aim: To write C programs for Atmega 32.
1. Write a program to load 0FH into PORT B.
2. A switch is connected to PB2 pin. Write a program to check status of the switch .If switch
is S=0, then send letter ‘N’ PORT A otherwise letter ‘Y’ to PORT A.
3. A switch is connected to PB4 and LED is connected to PB4 pin. Write a program to get
status of the switch and send it to LED.
4. Write a program to monitor PB5 pin . When it is high send $AA to PORT C, otherwise
send $65 to PORT C.
5. Write a program to toggle all the bits at PORT 0 continuously.
6. Write a program to convert Hex to Decimal.
7. Write a program to convert $76 packed BCD to ASCII.
8. Write a program to generate a square wave at 20KHz . Assume crystal is 8MHz. Use timer
0 for programming generate wave on PB4(normal mode).

6
Experiment No:12

Aim: To blink an LED using Arduino.

Components required:
Arduino UNO
LED
Resistor
Circuit:
Program code:

/* To blink an LED*/

int LED_pin = 11;

void setup()
{
pinMode(LED_pin,OUTPUT); //initialize digital pin 11 as output
}

void loop()
{
digitalWrite(LED_pin,HIGH); // make LED_pin HIGH
delay(1000); // wait for a second
digitalWrite(LED_pin,LOW); // make LED_pin LOW
delay(1000); // wait for a second
}
Experiment No:13

Aim: To display a string of characters on 16*2 LCD display.

Components required:

16*2 LCD display


Arduino UNO
10K potentiometer
wires

Circuit:
Connections:

* LCD RS pin to digital pin 12


* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K potentiometer:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)

Program code:
/*
Demonstrates the use a 16x2 LCD display.
This sketch prints "VISHWAKARMA GOVT ENGG COLLEGE" to the
LCD
*/

// include the library


code: #include
<LiquidCrystal.h>

// initialize the library with the numbers of the interface


pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
// set up the LCD's number of columns and
rows: lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("VISHWAKARMA
GOVT");
// set the cursor to column 0 and row 1 of the
LCD. lcd.setCursor(0,1);
lcd.print("ENGG COLLEGE");
}

void loop()
{

Output:

You might also like