606 Microcontroller and Embedded Systems
606 Microcontroller and Embedded Systems
EMBEDDED SYSTEMS
LABORATORY MANUAL (ECE - 327)
III/IV ECE SEM - II
COURSE OUTCOMES
At the end of the course student will be able to
1. Program 8051 microcontroller to meet the requirements of the user
2. Interface peripherals like switches, LEDs, stepper motor, Traffic lights controller, etc..,
3. Apply concept & types of interrupts for the given context.
4. Design a microcontroller development board to meet the requirements of the user
Scheme of Evaluation
(MICROCONTROLLER AND EMBEDDED SYSTEMS LABORATORY)
Total marks for each student to evaluate in
lab: 100
Out of 100 marks:
1. External Evaluation: 50 marks
2. Internal Evaluation: 50 marks
a. Internal Lab exam: 20 marks
b. Continuous Evaluation : 30 marks
III. Performance – 5M
(Experimentation skill - Connections,.etc )
IV. Result – 10M
(Identifying & Showing the inputs and outputs – 2M and/or
theoretical calculations – 2M, Output Verification – 6M (Partial output
– 3M, No Output – 0M )
V. Viva – 10M
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
Anil Neerukonda Institute of Technology & Sciences (Autonomous)
Sangivalasa-531 162, Bheemunipatnam Mandal, Visakhapatnam
RUBRICS
( MCES LABORATORY)
S.No Competency Performance Indicator
1 Demonstrate an ability Laboratory preparation (verification of Lab observation)
to conduct Stating clearly the aim of the experiment, its scope and
experiments importance for purpose of doing experiment.(Based on viva)
consistent with their Experimental procedures (Based on contents in Lab
level of knowledge observation)
and understanding. Ability to construct the circuit diagram on a bread board and
use meters/ instruments to record the measured data
according to the range selected.(Based on physical
observation)
2 Demonstrate an ability Finding the appropriate values of the components to meet the
to design experiments specifications.
to get the desired
output.
3 Demonstrate an ability Ability to gather materials and writing in lab record (Based
to analyze the data on lab record)
and reach valid
conclusions.
The objective of this lab is to impart skill (both Programming-Assembly level & Hardware)
in designing microcomputer systems. This Lab has 8085, 8086 microprocessor trainer kits
and 8051 micro controller trainer kits along with interfacing modules to demonstrate the
detailed applications of microprocessors& microcontrollers.
The facilities in the laboratory enable students to build a firm background in microcomputer
hardware as well as software. Students learn about assembly language programming, memory
and I/O design, interfacing of programmable chips and peripherals such as stepper motors,
analog – to – digital and digital – to – analog converters etc.
DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
Anil Neerukonda Institute of Technology & Sciences (Autonomous)
Sangivalasa-531 162, Bheemunipatnam Mandal, Visakhapatnam
2. Students should carry observation notes and record completed in all aspects.
3. Assembly level program and its theoretical result should be there in the observation
before coming to the next lab.
6. Student should follow the procedure to start executing the ALP they have to get
signed by the Lab instructor for theoretical result then with the permission of Lab
instructor they need to switch on the desktop and after completing the same they need
to switch off and keep the chairs properly.
7. After completing the ALP Students should verify the ALP by the Lab Instructor.
8. The Practical Result should be noted down into their observations and result must be
shown to the Lecturer In-Charge for verification.
9. Students must ensure that all switches are in the OFF position, desktop is shut down
properly.
Don’ts
1. Don‟t come late to the Lab.
2. Don‟t leave the Lab without making proper shut down of desktop and keeping the
chairs properly.
4. Don‟t leave the lab without the permission of the Lecturer In-Charge.
1. STUDY OF 8051 MICROCONTROLLER TRAINER KIT
Aim
To study the 8051 microcontroller trainer kit
1
Pin out Description
Pins 1-8: Port 1each of these pins can be configured as an input or an output.
Pin 9: RSA logic one on this pin disables the microcontroller and clears the contents of most
registers. In other words, the positive voltage on this pin resets the microcontroller. By
applying logic zero to this pin, the program starts execution from the beginning.
Pins10-17: Port 3Similar to port 1, each of these pins can serve as general input or output.
Besides, all of them have alternative functions:
2
Pin 18, 19: X2, X1Internal oscillator input and output. A quartz crystal which specifies
operating frequency is usually connected to these pins. Instead of it, miniature ceramics
resonators can also be used for frequency stability. Later versions of microcontrollers operate
at a frequency of 0 Hz up to over 50 Hz.
Pin 21-28: Port 2If there is no intention to use external memory then these port pins are
configured as general inputs/outputs. In case external memory is used, the higher address
byte, i.e. addresses A8-A15 will appear on this port. Even though memory with capacity of
64Kb is not used, which means that not all eight port bits are used for its addressing, the rest
of them are not available as inputs/outputs.
Pin 29: PSEN If external ROM is used for storing program then a logic zero (0) appears on it
every time the microcontroller reads a byte from memory.
Pin 30: ALE Prior to reading from external memory, the microcontroller puts the lower
address byte (A0-A7) on P0 and activates the ALE output. After receiving signal from the
ALE pin, the external register (usually 74HCT373 or 74HCT375 add-on chip) memorizes the
state of P0 and uses it as a memory chip address. Immediately after that, the ALU pin is
returned its previous logic state and P0 is now used as a Data Bus. As seen, port data
multiplexing is performed by means of only one additional (and cheap) integrated circuit. In
other words, this port is used for both data and address transmission.
Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and address
transmission with no regard to whether there is internal memory or not. It means that even
there is a program written to the microcontroller, it will not be executed. Instead, the program
written to external ROM will be executed. By applying logic one to the EA pin, the
microcontroller will use both memories, first internal then external (if exists).
Pin 32-39: Port 0Similar to P2, if external memory is not used, these pins can be used as
general inputs/outputs. Otherwise, P0 is configured as address output (A0-A7) when the ALE
pin is driven high (1) or as data output (Data Bus) when the ALE pin is driven low (0).
All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which can be configured as
inputs or outputs. Accordingly, in total of 32 input/output pins enabling the microcontroller to
be connected to peripheral devices are available for use.
Pin configuration, i.e. whether it is to be configured as an input (1) or an output (0), depends
on its logic state. In order to configure a microcontroller pin as an input, it is necessary to
apply a logic zero (0) to appropriate I/O port bit. In this case, voltage level on appropriate pin
will be 0.
3
is the case with any TTL input). This may seem confusing but don't loose your patience. It all
becomes clear after studying simple electronic circuits connected to an I/O pin.
Memory Organization
The 8051 has two types of memory and these are Program Memory and Data Memory.
Program Memory (ROM) is used to permanently save the program being executed, while
Data Memory (RAM) is used for temporarily storing data and intermediate results created
and used during the operation of the microcontroller. Depending on the model in use (we are
still talking about the 8051 microcontroller family in general) at most a few Kb of ROM and
128 or 256 bytes of RAM is used.
All 8051 microcontrollers have a 16-bit addressing bus and are capable of addressing 64 kb
memory. It is neither a mistake nor a big ambition of engineers who were working on basic
core development. It is a matter of smart memory organization which makes these
microcontrollers a real “programmers‟ goody“.
Special Function Registers (SFRs) are a sort of control table used for running and monitoring
the operation of the microcontroller. Each of these registers as well as each bit they include,
has its name, address in the scope of RAM and precisely defined purpose such as timer
control, interrupt control, serial communication control etc. Even though there are 128
memory locations intended to be occupied by them, the basic core, shared by all types of
8051 microcontrollers, has only 21 such registers. Rest of locations is intentionally left
4
unoccupied in order to enable the manufacturers to further develop microcontrollers keeping
them compatible with the previous versions. It also enables programs written a long time ago
for microcontrollers which are out of production now to be used today.
PSW register is one of the most important SFRs. It contains several status bits that reflect the
current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry, two
register bank select bits, Overflow flag, parity bit and user-definable status flag.
P - Parity bit. If a number stored in the accumulator is even then this bit will be
automatically set (1), otherwise it will be cleared (0). It is mainly used during data transmit
and receive via serial communication.
OV Overflow occurs when the result of an arithmetical operation is larger than 255
andcannot be stored in one register. Overflow condition causes the OV bit to be set (1).
Otherwise, it will be cleared (0).
RS0, RS1 - Register bank select bits. These two bits are used to select one of four register
banks of RAM. By setting and clearing these bits, registers R0-R7 are stored in one of four
banks of RAM.
5
RS1 RS2 Space in RAM
0 0 Bank0 00h-07h
0 1 Bank1 08h-0Fh
1 0 Bank2 10h-17h
1 1 Bank3 18h-1Fh
CY - Carry Flag is the (ninth) auxiliary bit used for all arithmetical operations and shift
instructions.
DPTR register is not a true one because it doesn't physically exist. It consists of two separate
registers: DPH (Data Pointer High) and (Data Pointer Low). For this reason it may be treated
as a 16-bit register or as two independent 8-bit registers. Their 16 bits are primarly used for
external memory addressing. Besides, the DPTR Register is usually used for storing data and
intermediate results.
6
Stack Pointer (SP) Register
A value stored in the Stack Pointer points to the first free stack address and permits stack
availability. Stack pushes increment the value in the Stack Pointer by 1. Likewise, stack pops
decrement its value by 1. Upon any reset and power-on, the value 7 is stored in the Stack
Pointer, which means that the space of RAM reserved for the stack starts at this location. If
another value is written to this register, the entire Stack is moved to the new memory
location.
If neither external memory nor serial communication system are used then 4 ports within
total of 32 input/output pins are available for connection to peripheral environment. Each bit
within these ports affects the state and performance of appropriate pin of the microcontroller.
Thus, bit logic state is reflected on appropriate pin as a voltage (0 or 5 V) and vice versa,
voltage on a pin reflects the state of appropriate port bit.
As mentioned, port bit state affects performance of port pins, i.e. whether they will be
configured as inputs or outputs. If a bit is cleared (0), the appropriate pin will be configured
as an output, while if it is set (1), the appropriate pin will be configured as an input. Upon
reset and power-on, all port bits are set (1), which means that all appropriate pins will be
configured as inputs.
As you already know, the microcontroller oscillator uses quartz crystal for its operation. As
the frequency of this oscillator is precisely defined and very stable, pulses it generates are
always of the same width, which makes them ideal for time measurement. Such crystals are
also used in quartz watches. In order to measure time between two events it is sufficient to
count up pulses coming from this oscillator. That is exactly what the timer does. If the timer
is properly programmed, the value stored in its register will be incremented (or decremented)
with each coming pulse, i.e. once per each machine cycle. A single machine-cycle instruction
lasts for 12 quartz oscillator periods, which means that by embedding quartz with oscillator
frequency of 12MHz, a number stored in the timer register will be changed million times per
second, i.e. each microsecond.
The 8051 microcontroller has 2 timers/counters called T0 and T1. As their names suggest,
their main purpose is to measure time and count external events. Besides, they can be used
for generating clock pulses to be used in serial communication, so called Baud Rate.
7
Timer T0
As seen in figure below, the timer T0 consists of two registers – TH0 and TL0 representing a
low and a high byte of one 16-digit binary number.
Accordingly, if the content of the timer T0 is equal to 0 (T0=0) then both registers it consists
of will contain 0. If the timer contains for example number 1000 (decimal), then the TH0
register (high byte) will contain the number 3, while the TL0 register (low byte) will contain
decimal number 232.
Since the timer T0 is virtually 16-bit register, the largest value it can store is 65 535. In case
of exceeding this value, the timer will be automatically cleared and counting starts from 0.
This condition is called an overflow. Two registers TMOD and TCON are closely
connected to this timer and control its operation.
8
TMOD Register (Timer Mode)
The TMOD register selects the operational mode of the timers T0 and T1. As seen in
figure below, the low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4 -
bit7) refer to the timer 1. There are 4 operational modes and each of them is described
herein.
GATE1 enables and disables Timer 1 by means of a signal brought to the INT1 pin
(P3.3):
o 1- Timer 1 operates only if the INT1 bit is set.
o 0- Timer 1 operates regardless of the logic state of the INT1 bit.
C/T1 selects pulses to be counted up by the timer/counter 1:
o 1 - Timer counts pulses brought to the T1 pin (P3.5).o
0- Timer counts pulses from internal oscillator.
T1M1,T1M0 These two bits select the operational mode of the Timer 1.
GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin
(P3.2):o 1- Timer 0 operates only if the INT0 bit is set.
o 0- Timer 0 operates regardless of the logic state of the INT0 bit.
C/T0 selects pulses to be counted up by the timer/counter 0:
o 1 - Timer counts pulses brought to the T0 pin (P3.4).o
0- Timer counts pulses from internal oscillator.
T0M1,T0M0 These two bits select the oprtaional mode of the Timer 0.
9
Timer Control (TCON) Register
TCON register is also one of the registers whose bits are directly in control of
timer operation.
Only 4 bits of this register are used for this purpose, while rest of them is used for
interrupt control to be discussed later.
Timer 1
Timer 1 is identical to timer 0, except for mode 3 which is a hold-count mode. It means that
they have the same function, their operation is controlled by the same registers TMOD and
TCON and both of them can operate in one out of 4 different modes.
Result:
10
Viva questions:
1) Compare and contrast the microprocessor and microcontroller.
2) How to change the register bank?
3) Name different Timer modes?
4) What is bit addressable ram and registers?
5) List the 16 bit registers.
6) What are the special registers in 8051 microcontroller?
7) Difference between timer and counter
8) How to switch between timer modes
9) How to change the baud rate?
10) What is the clock frequency?
11
2. ADDITION/SUBTRACTION OF 8-BIT NUMBERS USING 8051
Aim:
To do the addition/subtraction operations using 8051 microcontroller
Apparatus required:
8051 microcontroller kit
DAC interface kit
Keyboard
Algorithm:
Addition / Subtraction
Step 1 : Move 1H data to memory
Step 2 : Add or subtract 1H data with 2nd data
Step 3 : Initialize data pointer.
Step 4 : Move result to memory pointed by DPTR.
START
Initialize DPTR
Stop
12
Execution:
Addition:
ML Input ML Output
4103 4500
4109
Execution:
Subtraction:
ML Input ML Output
4101 4500
4103
Result:
Thus 8-bit addition/subtraction is performed using 8051.
Viva questions:
13
3. MULTIPLICATION/DIVISION OF 8-BIT NUMBERS USING 8051
Aim:
To do the multiplication/division operations using 8051 microcontroller
Apparatus required:
8051 microcontroller kit
DAC interface kit
Keyboard
Algorithm:
Multiplication / Division
Step 1 : Get 1H data and 2nd data to memory
Step 2 : Multiply or divide 1H data with 2nd data
Step 3 : Initialize data pointer.
Step 4 : Move result to memory pointed by DPTR (first port)
Step 5 : Increment DPTR
Step 6 : Move 2nd part of result to register A
Step 7 : Move result to 2nd memory location pointer byDPTR
START
Increment data
Increment DPTR
Stop
14
Program: 8-bit Multiplication:
Memory Label Opcode Mnemonics Comments
Location
4100 Start 7403 MOV A,#03 Move immediate data
to accumulator
4101 75F003 MOV B,#02 Move 2nd data to B
register
4105 A4 MUL AB Get the product in A &
B
4106 904500 MOV DPTR, # 4500 Load data in 4500
location
4109 F0 MOVX @DPTR,A Move A t ext RAM
410A INC DPTR
410B E5F0 MOV A,B Move 2nd data in A
410D F0 MOVX @DPTR,A Same the ext RAM
410E 80FE SJMP 410E Remain idle in infinite
Loop
Execution:
Multiplication:
ML Input Output Address Value
4101
4500
4103
Program: 8-bit Division:
Memory Label Opcode Mnemonics Comments
Location
4100 Start 7408 MOV A,#04 Move immediate data
to accumulator
4102 75F002 MOV B,#02 Move immediate to B
reg.
4105 84 DIV AB Divide content of A &
B
4106 904500 MOV DPTR, # 4500 Load data pointer with
4500 location
4109 F0 MOVX @DPTR,A Move A to ext RAM
410A A3 INC DPTR Increment data pointer
410B ESF0 MOV A,B Move remainder to A
410D F0 MOVX @DPTR,A Move A to ext RAM
410E 80FE SJMP 410E Remain idle in infinite
Loop
Execution:
Division:
ML Input Output Address Value
4101 4500
4103
15
Result:
Thus 8-bit multiplication and division is performed using 8051.
Viva questions:
16
4. LARGEST ELEMENTS IN AN ARRAY
Aim:
Write an assembly language program to find the biggest number in an array of 8-bit
unsigned numbers of predetermined length.
Apparatus required:
8051 Microcontroller kit
(0-5V) DC battery
Algorithm:
1. Initialize pointer and counter.
2. Load internal memory location 40H as zero.
3. Move the first element of an array to r5 register.
4. Compare the data stored in memory location 40H is equal to or less than the
value of first element of an array.
5. If it is lesser, then move the data of first element to 40H memory location
ELSE increment pointer and decrement counter.
6. Check the counter. If counter is not equal to zero, repeat from the 2nd
step else Move the R5 register to 40H memory location.
7. Stop the program.
Program:
Memory Label Opcode Mnemonics Comments
Location
4100 90 42 00 MOV DPTR,#4200H
MOV 40H,#00H
4103
75 40 00
4106
7D 0A MOV R5,#0AH
4108
LOOP2: E0 MOVX A,@DPTR
4109
B5 40 08 CJNE A,40H,LOOP1
410C
LOOP 3 A3 INC DPTR
410D
DD F9 DJNZ R5,LOOP2
410F
E5 40 MOV A,40H
4111
F0 MOVX @DPTR,A
4112 HLT 80 FE SJMP HLT
17
4114 LOOP1 40 F6 JC LOOP3
INPUT:
OUTPUT:
Result:
Thus the assembly language program was written to find the largest element in an
array and executed using 8051 microcontroller.
Viva questions:
18
5. SORTING OF DATA-ASCENDING ORDER AND DESCEDING ORDER
AIM:
To arrange an array of 8-bit unsigned numbers of known length in an ascending order and
descending order.
Apparatus required:
8051 microcontroller kit
(0-5V) DC battery
Algorithm:
1. Initialize the register and data pointer.
2. Get first two elements in registers A &B.
3. Compare the two elements of data. If value of B register is high then exchange
A & B data else increment pointer and decrement register R3.
4. Check R3 is zero, and then move the register R5 & R6.
5. Again increment pointer and decrement R4,
6. Check R4 is zero. If no repeat the process from step 2.
7. Otherwise stop the program.
Program:
Memory Label Opcode Mnemonics Comments
Location
MOV R3,#4
4100 7B 04
MOV R4,#4
4102 7C 04
4111 C3 CLR C
19
4118 C0 83 PUSH DPH
412B 1C DEC R4
412E OC INC R 4
20
Program for Descending:
4111 C3 CLR C
4114 50 13 JC CHKNXT
21
4126 F0 MOVX @DPTR,A
412B 1C DEC R4
412E OC INC R 4
INPUT:
22
OUTPUT:
Memory address Data
23
OUTPUT:
Memory address Data
Result:
Thus the assembly language program was written to sort the data in an
ascending/descending order and executed using 8051 microcontroller.
Viva questions:
24
6. SPEED CONTROL OF STEPPER MOTOR
Aim:
To write an assembly program to make the stepper motor run in forward and reverse
direction.
Apparatus required:
Stepper motor
8051 microcontroller kit
(0-5V) power supply
Algorithm:
1. Fix the DPTR with the Latch Chip address FFC0
2. Move the values of register A one by one with some delay based on the
2-Phase switching Scheme and repeat the loop.
3. For Anti Clockwise direction repeat the step 3 by reversing the value
sequence.
4. End the Program
25
412F SJMP 412F
413B DELAY
413D RET
Result:
Thus an assembly language program to control of stepper motor was
executed successfully using 8051 Microcontroller kit.
Viva questions:
26
7. Eight-Bit Analog to Digital Converter
Aim:
To write an assembly language program for analog to digital converter.
Apparatus required:
8051 microcontroller kit
(0-5V) DC battery
Algorithm:
1. Make ALE low/high by moving the respective data from A register to
DPTR.
2. Move the SOC( Start Of Conversion) data to DPTR from FFD0
3. Check for the End Of Conversion and read data from Buffer at address
FFC0
4. End the Program.
PROGRAM:
Port Address for 74LS174 Latch: FFC8
Port Address for SOC: FFD0
Port Address for EOC 1: FFD8
Port Address for 74LS 244 Buffer: FFC0
Memory Label Opcode Mnemonics Comments
Location
4100 90 FF C8 MOV DPTR, #FFC8
4103 74 10 MOV A, #10 Select Channel 0
4105 F0 MOVX @DPTR, A Make ALE Low
4106 74 18 MOV A, #18 Make ALE High
4108 F0 MOVX @DPTR, A
4109 90 FF D0 MOV DPTR, #FFD0
410C 74 01 MOV A, #01 SOC Signal High
410E F0 MOVX @DPTR, A
410F 74 00 MOV A, #00 SOC Signal Low
4111 F0 MOVX @DPTR, A
4112 90 FF D8 MOV DPTR, #FFD8
4115 E0 MOVX A, @DPTR
4116 30 E0 FC JNB E0, WAIT Check For EOC
4119 90 FF C0 MOV DPTR, #FFC0 Read ADC Data
411C E0 MOVX A, @DPTR
4110 90 41 50 MOV DPTR, #4150 Store the Data
4120 F0 MOVX @DPTR, A
4121 90 FE SJMP HERE
27
Result:
Thus an assembly language program is executed for analog to digital conversion.
Viva questions:
1. Why MOVX instruction is being used to access the ports of the 8255?
2. How many pins of the 8255 can be used as the I/O ports?
3. Why two pins for ground are available in ADC0804?
4. What is the function of the WR pin?
5. While programming the ADC0808/0809 IC what steps are followed?
6. In ADC0808/0809 IC which pin is used to select Step Size?
28
8. Eight-Bit Digital to Analog Converter
Aim:
To write an assembly language program for digital to analog converter.
Apparatus required:
8051 microcontroller kit
(0-5V) DC battery
Algorithm:
1. Move the Port Address of DAC 2 FFC8 to the DPTR.
2. Move the Value of Register A to DPTR and then Call the delay.
3. Move the Value of Register A (FFh) to DPTR and the call the dalay.
4. Repeat the steps 2 and 3.
29
PROGRAM TO GENERATE TRIANGULAR WAVEFORM
Memory Label Opcode Mnemonics Comments
Location
4100 90 FF C8 MOV DPTR, #0FFC8H
4103 74 00 MOV A, #00H
4105 F0 MOVX @DPTR, A
4106 04 INC A
4107 70 FC JNZ LOOP1
4109 74 FF MOV A, #0FFH
411B F0 MOVX @DPTR, A
410C 14 DEC A
410D 70 FC JNZ LOOP2
410F 02 41 03 LJMP START
Result:
Thus an assembly language program for Digital to Analog has been executed.
Viva questions:
1. Why the switches used in weighted resistor DAC are of single pole double throw (SPDT)
type?
2. Determine the Full scale output in a 8-bit DAC for 0-15v range?
3. How to decide the digital levels?
4. Which pins of a microcontroller are directly connected with 8255?
30
9. Transfer data serially between two kits
Aim:
To write an assembly language program Transmitting and Receiving the data between
two kits.
Apparatus required:
8051 microcontroller kit
(0-5V) DC battery
Algorithm:
1. Initialize TMOD with 20H
2. Set the values for TCON and SCON
3. Set the input address to DPTR
4. Based on the bit value on SCON store the data in SBUF
5. Increment DPTR and check for the loop end value
31
PROGRAM FOR TRANSMITTER.
Memory Label Opcode Mnemonics Comments
Location
4100 75 89 20 MOV TMOD, #20H
4103 75 8D A0 MOV TH1, #0A0H
4106 75 8B 00 MOV TL1, #00H
4109 75 88 40 MOV TCON, #40H
410C 75 98 58 MOV SCON, #58H
410F 90 45 00 MOV DPTR, #4500H
4112 RELOAD 7D 05 MOV R5, #05H
4114 REPEAT E0 MOVX A, @DPTR
4115 F5 99 MOV SBUF, A
4117 CHECK 30 99 FD JNB SCON.1, CHECK
411A C2 99 CLR SCON.1
411C A3 INC DPTR
411D B4 3F F2 CJNE A, #3FH,
RELOAD
4120 DD F2 DJNZ R5, REPEAT
4122 E4 CLAR A
4123 12 00 20 LCALL 0020H
Result:
Thus an assembly language program for transmitting and Receiving the data between two kits
Viva questions:
1. Which devices are specifically being used for converting serial to parallel and from parallel
to serial respectively?
2. What is the difference between UART and USART communication?
3. What is the function of the SCON register?
4. What should be done if we want to double the baud rate?
5. Why baud rate is mentioned in serial communication?
6. What is a null modem connection?
7. Which logic level is understood by the micro-controller/micro-processor?
8. Which signal controls the flow of data?
32
10.8051 MICROCONTROLLER TIMER/COUNTER PROGRAMMING
AIM:
Generate a Square wave form with an ON time of 3 ms and an OFF time of 10 ms an all pins of
port 0. Assume XTAL of 22 MHz (Use assembly language in Keil software).
SOFTWARE REQUIRED:
Keil IDE
PROCEDURE:
33
AGAIN: JNB TF0,AGAIN
CLR TR0
CLR TF0
RET
END
SIMULATION RESULT
Result:
A Square wave form with an ON time of 3 ms and an OFF time of 10 ms is generated and verified
using Keil software.
Viva questions:
1) What is timer/counter registers in 8051?
2) What is the size of timer/Counter?
3) When timer overflow occurs?
34
11. TRAFFIC LIGHT CONTROLLER
Aim:
To write an assembly language program to display Characters on a seven display interface.
Apparatus required:
8051 microcontroller kit
(0-5V) DC battery
Algorithm:
1. Fix the control the control and move the control word to control register.
2. Move the Traffic Light LED Position values to Port A, Port B and Port C
respectively based on the logic.
3. Fix the delay based on the requirement.
3. Execute the program.
PROGRAM:
4100 ORG 4100
CONTRL EQU 0FF0FH
PORT A EQU 0FF0CH
PORT B EQU 0FF0DH
PORT C EQU 0FF0EH
35
4129 90 FF 0D MOV DPTR, #PORT B
412C F0 MOVX @DPTR, A
412D 09 INC R1
412E 88 83 MOV DPH, R0
4130 89 82 MOV DPL, R1
4132 E0 MOVX A, @DPTR
4133 A8 83 MOV R0, DPH
4135 A9 82 MOV R1, DPL
4137 90 FF 0E MOV DPTR, #PORT C
413A F0 MOVX @DPTR, A
413B 09 INC R1
413C 12 41 75 LCALL DELAY
413F 8A 83 MOV DPH, R2
4141 8B 82 MOV DPL, R3
4143 E0 MOVX A, @DPTR
4144 AA 83 MOV R2, DPH
4146 AB 82 MOV R3, DPL
4148 90 FF 0C MOV DPTR, #PORT A
414B F0 MOVX @DPTR, A
414C 0B INC R3
414D 8A 83 MOV DPH, R2
414F 8B 82 MOV DPL, R3
4151 E0 MOVX A, @DPTR
4152 AA 83 MOV R2, DPH
4154 AB 82 MOV R3, DPL
4156 90 FF 0D MOV DPTR, #PORT B
4159 F0 MOVX @DPTR, A
415A 0B INC R3
415B 8A 83 MOV DPH, R2
415D 8B 82 MOV DPL, R3
415F E0 MOVX A, @DPTR
4160 AA 83 MOV R2, DPH
4162 AB 82 MOV R3, DPL
4164 90 FF 0E MOV DPTR, #PORT C
4167 F0 MOVX @DPTR, A
4168 0B INC R3
4169 12 41 82 LCALL DELAY1
416C 88 83 MOV DPH, R0
416E 89 82 MOV DPL, R1
4170 DC A4 DJNZ R4, GO
4172 12 41 06 LCALL START
4175 DELAY 7D 12 MOV R5, #12H
4177 L3 7E FF MOV R6, #0FFH
4179 L2 7F FF MOV R7, #0FFH
417B L1 DF FE DJNZ R7, L1
417D DE FA DJNZ R6, L2
417F DD F6 DJNZ R5, L3
4181 22 RET
4182 DELAY1 7D 12 MOV R5, #12H
36
4184 L6 7E FF MOV R6, #0FFH
4186 L5 7F FF MOV R7, #0FFH
4188 L4 DF FE DJNZ R7, L4
418A DE FA DJNZ R6, L5
418C DD F6 DJNZ R5, L6
418E 22 RET
418F LOOK 44 27 12 DB 44H, 27H, 12H
4192 92 2B 10 DB 92H, 2BH, 10H
4195 84 9D 10 DB 84H, 9DH, 10H
4198 84 2E 48 DB 84H, 2EH, 48H
419B LOOK1 48 27 12 DB 48H, 27H, 12H
419E 92 4B 10 DB 92H, 4BH, 10H
41A1 84 9D 20 DB 84H, 9DH, 20H
41A4 04 2E 49 DB 04H, 2EH, 49H
Result:
Thus an assembly language program for the Traffic Light Control has been executed.
Viva questions:
1. Which pins of a microcontroller are directly connected with 8255?
2. Which pins are used to select the ports and the control register?
3. How many pins of the 8255 can be used as the I/O ports?
4. How to move the position?
5. How to delay the signaling?
6. How to incorporate realtime traffic monitoring?
7. How to do demand based signaling?
8. How to sense the traffic density?
37
12. TEST PROGRAM USING ARM 9 mini 2440 KIT
Aim:
To write a test program for interfacing LED with ARM9 mini 2440 kit
Apparatus required:
ARM 9 mini 2440 kit
(0-5V) DC battery
Procedure:
1. When developing C language programs, the main function is generally used as the entry point, and
the main function is just a function, so it must be called by others and the return value is returned to
the caller. So when we are developing, when the LED is on, no one will call our function, so we need
to do this work by ourselves.
2. Hardware initialization: turn off the watchdog
3. Software initialization: set the stack: point the stack pointer sp to a certain piece of memory
4. The initialization of hardware and software is called a startup file, and the startup file is an
assembly code
PROGRAM:
Startup file crt0.S
.text
.global _start
_start:
LDR r0,=0x53000000 @WATCHDOG register address
MOV r1, #0x00000000 @r1 is 0
STR r1,[r0] @Write 0, disable WATCHDOG, otherwise the CPU will restart continuously
LDR sp,=1024*4 @Set the stack, note: it cannot be larger than 4k, because the available memory is
only 4k
@ Memory SRAM, 4k
The code in @Nand Flash will be moved to the internal ram after reset, this ram is only 4k
bl main @call the main function in the c program, the bl instruction will jump to the main function,
and put the return value in lr
halt_loop:
b halt_loop
ledon_c.c file
int main()
{
GPBCON = 0x00000400;//Set GPB5 as the output port
GPBDAT = 0x00000000;
38
return 0;
}
Makefile
Result:
Thus an assembly language program for interfacing LED with ARM9 mini 2440 kit has been done.
Viva questions:
1. What is the oscillator frequency of mini 2440 kit?
2. How many jumpers are available in mini 2440 kit?
3. How ARM 9 is different from 8085 and 8086 processors?
39
13. Hex TO ASCII CONVERSION
Aim:
Write an assembly language program to convert a binary number to its equivalent
ASCII code and display the result in the address field.
Apparatus required:
8051 microcontroller kit
(0-5V) DC battery
Algorithm:
40
SAMPLE INPUT AND OUTPUT:
INPUT:
OUTPUT:
Result:
Thus the assembly language program was written to converter Hexadecimal number to
equivalent ASCII Code and executed using 8051 microcontroller.
Viva questions:
41
14. ASCII TO BINARY CONVERSION
Aim:
Write an ALP to convert a ASCII to its equivalent BINARY number and display
the result in the data field.
Apparatus required:
8051 microcontroller kit
(0-5V) power supply
Algorithm:
Program:
4104 C3 CLR C
4107 C3 CLR C
410A 40 04 JC LOOP
410E 80 02 SJMP L1
42
4118 79 08 MOV R1,#08H
4120 40 05 JC LOOP1
Result:
Thus the assembly language program was written to converter ASCII
number to equivalent Binary Value and executed using 8051
microcontroller.
Viva questions:
1) How hex is different from binary?
2) What is ASCII?
3) What is extended ASCII?
4) How many iterations needed in the convertion?
5) How many registers are involved?
6) What is the complexity involved?
43
15. FIND THE SQUARE ROOT OF A GIVEN DATA
Aim:
To write an assembly language program to find the square root of a given data
Apparatus required:
8051 microcontroller kit
(0-5V) DC battery
Algorithm:
1. Enter a program.
2. Enter the input hex value to location 4200h.
3. Execute the program.
4. The output square root value stored in a location 4500h.
PROGRAM:
Memory Label Opcode Mnemonics Comments
Location
4100 Origin: 90 42 00 MOV DPTR,#4200h Get a input data
4103 e0 MOVX A,@DPTR
4104 f9 MOV R1,a
4105 7a 01 MOV R2, #01h Initialize counter
4107 LOOPI: e9 MOV A,R1
4108 8a f0 MOV B,R2
410a 84 DIV AB divide the given value
and counter
410b fb MOV R3,A
410c ac f0 MOV R4,B
410e 9a SUBB A ,R2 compare
410f 60 03 JZ RESULT Dividend and counter
4111 0a INC R2
4112 80 f3 SJMP L1
44
Result:
Thus an assembly language program is written to find the square root of a given data and
executed successfully.
Viva questions:
1) How to square the number?
2) How different is squaring from multiplication?
3) What is the complexity involved in finding the square root?
4) How many iterations needed?
5) How many registers are involved?
6) What is the complexity involved?
45
16. Seven segment display
Aim:
To write an assembly language program to display characters on a seven display interface.
Apparatus required:
8051 microcontroller kit
(0-5V) DC battery
Algorithm:
1. Enter a program.
2. Initialize number of digits to Scan
3. Select the digit position through the port address C0
4. Display the characters through the output at address C8.
5. Check whether all the digits are display.
6. Repeat the Process.
PROGRAM:
Memory Label Opcode Mnemonics Comments
Location
4100 START 90 41 2B DPTR, #TABLE Display message
4103 AA 82 MOV R2, DPL
4105 AB 83 MOV R3, DPH
4107 78 07 MOV R0, #07H
4109 7F 08 MOV R7, #08H Initialize no.of digits to
Scan
410B L1 E8 MOV A, R0 Select digit position
410C 90 FF C0 MOV DPTR, #0FFC0H
410F F0 MOVX @DPTR, A
4110 8A 82 MOV DPL, R2
4112 8B 83 MOV DPH, R3
4114 E0 MOVX A, @DPTR
4115 90 FF C8 MOV DPTR, #0FFC8H
4118 F0 MOVX @DPTR, A
4119 12 41 22 LCALL DELAY
411C 0A INC R2
411D 18 DEC R0 Check if 8 digits are
Displayed
411E DF EB DJNZ R7, L1 If not repeat
st
4120 21 00 AJMP START Repeat from the 1 digit
4122 DELAY 7C 02 MOV R4, #02H
4124 L3 7D FF MOV R5, #0FFH
4126 L2 DD FE DJNZ R5, R2
4128 DC FA DJNZ R4, L3
412A 22 RET
412B TABLE 3E 06 00 55 DB 3EH, 06H, 00H, 55H
412F 06 39 50 3F DB 06H, 39H, 50H, 3FH
4133 END
46
SAMPLE INPUT AND OUTPUT:
Result:
Thus an assembly language program displaying characters on seven segment display has been
executed.
Viva questions:
47