MPMC (10 6)
MPMC (10 6)
FOR
MICROPROCESSOR &
MICROCONTROLLER LAB
V SEMESTER ECE
Prepared By
Mrs. R. Kurinjimalar, AP/ECE
Mrs. G. Sivajanane, AP/ECE
Ms. S. Anbarasi, AP/ECE
1
EC P51 - MICROPROCESSOR AND MICROCONTROLLER LABORATORY
LCD interface
ADC /DAC interface
Stepper motor interface
Serial communication (kit-to-kit and/or pc-to-kit)
Watch dog timer
Real-time clock
Printer interfacing
Water level indicator
Traffic light controller
Elevator simulation
Pulse width modulation
Interfacing of relay switches
2
MICROPROCESSOR & MICROCONTROLLER LAB
V SEMESTER ECE
LIST OF EXPERIMENTS
CYCLE I
1
STUDY OF MICROPROCESSOR KIT 8085
CYCLE II
8
PROGRAM FOR ADC INTERFACE USING 8051 MICROCONTROLLER
9
PROGRAM FOR DAC INTERFACE USING 8051 MICROCONTROLLER
3
EXPT.NO 1- STUDY OF MICROPROCESSOR KIT 8085
AIM:
To Study the microprocessor kit 8085
APPARATUS REQUIRED:
1. Microcontroller kit with Power chord
2.Manual
THEORY:
A microprocessor - also known as a CPU or central processing unit - is a
complete computation engine that is fabricated on a single chip.
The first microprocessor was the Intel 4004, introduced in 1971. The 4004
was not very powerful - all it could do was add and subtract, and it could only do that 4
bits at a time. But it was amazing that everything was on one chip. Prior to the 4004,
engineers built computers either from collections of chips or from discrete components
4
(Transistors and such). The 4004 powered one of the first portable electronic
calculators. The architecture of microprocessor is shown in the above fig.
Control Unit
Generates signals within uP to carry out the instruction, which has been
decoded. In reality causes certain connections between blocks of the uP to be opened or
closed, so that data goes where it is required, and so that ALU operations occur.
Registers
The 8085/8080A-programming model includes six registers, one accumulator,
and one flag register, as shown in Figure. In addition, it has two 16-bit registers: the
stack pointer and the program counter. They are described briefly as follows. The
8085/8080A has six general-purpose registers to store 8-bit data; these are identified as
B,C,D,E,H, and L as shown in the figure. They can be combined as register pairs - BC,
DE, and HL - to perform some 16-bit operations. The programmer can use these
registers to store or copy data into the registers by using data copy instructions.
Accumulator
The accumulator is an 8-bit register that is a part of arithmetic/logic unit
(ALU). This register is used to store 8-bit data and to perform arithmetic and logical
operations. The result of an operation is stored in the accumulator. The accumulator is
also identified as register A.
Flags
The ALU includes five flip-flops, which are set or reset after an operation
according to data conditions of the result in the accumulator and other registers. They
are called Zero(Z), Carry (CY), Sign (S), Parity (P), and Auxiliary Carry (AC) flags;
they are listed in the Table and their bit positions in the flag register are shown in the
5
Figure below. The most commonly used flags are Zero, Carry, and Sign. The
microprocessor uses these flags to test data conditions.
Instruction Register/Decoder
Temporary store for the current instruction of a program. Latest instruction sent
here from memory prior to execution. Decoder then takes instruction and ‘decodes’ or
interprets the instruction. Decoded instruction then passed to next stage.
Control Generator
Generates signals within uP to carry out the instruction which has been
decoded. In reality causes certain connections between blocks of the uP to be opened or
closed, so that data goes where it is required, and so that ALU operations occur.
Register Selector
This block controls the use of the register stack in the example. Just a logic
circuit which switches between different registers in the set will receive instructions
from Control Unit.
6
General Purpose Registers
Microprocessor requires extra registers for versatility. Can be used to store
additional data during a program. More complex processors may have a variety of
differently named registers.
LOAD:
This command is opposite to save command. The contents of audio cassette
block is loaded (retrieved back) in the system RAM from a given DS (file name).
SAVE:
This command is used to save the contents of specified block on to a audio
cassette for permanent storage.
CODE:
When this command key is pressed the address field remains blank, Data field
shows a dot indicating that it expects a code. User is provided with a table of codes,
indicating the meaning and prerequisites of each code. User loads the appropriate code
and executes it by pressing EXEC. The monitor branches to the appropriate sub-
routines pointed by the code.
7
STEP:
Mere running a program with RUN is done whenever the program
development is complete i.e. to runa final working program. During the program
development stage some sort of aid to execute the part of program at a time and then
test its success is required.
The STEP command helps you to do the above.
There are two ways of stepping the program.
SINGLE STEPPING:
To execute single instruction at a time, using STEP command. The STEP
command requires a start address, break address and the no.of times the br should
occur.
BREAK POINT:
Set a software breakpoint RST1. This software breakpoint can be done using
the RUN command. It requires RST1 (CFH) to be inserted to a location where you
want to break. The disadvantage of this method is that you have to insert and remove
'CF' and you have to operate in the RAM area only.
EXEC:
Pressing EXEC will place the data field contents into the named register and
terminate the command.
REG:
This command allows you to display and optionally modify the contents of
8085 CPU registers. The various registers are A, B, C, D, E, F, I, H, L, SPH, SPL,
PCH, PCL. (H – higher byte, L – lower byte)
RES:
On RES, the display shows MP – 85 as a sign on message, indicating that the
monitor is ready to accept a command. Pressing any non-command key generates “Err”
message. After “-Err” user can immediately give a valid command.
8
Fig.2.Micro-85 Basic functional block diagram
9
SET:
You can use this command to SET the address of a required memory location.
A dot in the address field of display indicated that the entry will be displayed in the
address field.
INC:
Pressing INC, first time will shift the dot to the data field of display. Data field
will show the contents of the memory location pointed by the address set. You can
modify or retain the data field to any value.
DEC:
DEC acts as similar to INC, except the address field is decremented, pointing to
previous memory locations.
0 – F: Hex Keypad
Memory Devices:
1. IC – 6264 (RAM)
2. IC – 2764 (EPROM)
10
Memory Address Space:
ROM : 0000 – 1FFF
RAM : 2000 – 3FFF
Students should not use this address range for their program or do not modify the
Onboard Interfaces:
Study of Interrupts:
− RST 7.5 –
MEMORY CONFIGURATION:
The memory configuration is given in the following figure from which a clear idea
6000 5FFF
USER RAM AREA
4100 40FF
MONITOR PROGRAM
AREA
4000
3FFF
EPROM EXANSION
2000
1FFF
MONITOR EPROM
AREA
0000
RESULT:
Thus the microprocessor kit 8085 hardware & software details were studied.
12
AIM:
APPARATUS REQUIRED:
1. Microprocessor kit
2. Power chord
8- BIT ADDITION
ALGORITHM:
PROGRAM:
13
MEMORY
LABEL MNEMONIC OPCODE COMMENTS
ADDRESS
21 Load address of the data in HL
4100 LXI H, 4200
register pair for initializing the
00 memory location to get augend
4101
and addend.
42
4102
8- BIT SUBTRACTION
ALGORITHM:
14
1. Start the Process.
2. Initialize the memory location for getting minuend and subtrahend.
3. Initialize one register to store barrow.
4. Get minuend to accumulator and increment the memory pointer to get
subtrahend in memory.
5. Subtract subtrahend from minuend in memory.
6. Check for barrow. If barrow is not present go to 8 step.
7. Else Increment the Register assigned for carry storage.
8. Store difference (accumulator content) and barrow in the specific memory
location.
9. Stop the process.
PROGRAM:
MEMORY
LABEL MNEMONIC OPCODE COMMENTS
ADDRESS
4100 LXI H, 4200 21 Load address of the data in
4101 00 HL register pair for
initializing the memory
4102 42 location to get minuend and
subtrahend
4103 MVI B, 00 06 Initialize B register to store
borrow
4104 00
4105 MOV A,M 7E Move the content of the
memory to accumulator
4106 INX H 23 Increment the memory pointer
4107 SUB M 96 Subtract subtrahend from
minuend in memory
4108 JNC XXX D2 If no borrow, Go to xxx ,
4109 0C
410A 41
410B INR B 04 Increment the borrow register
410C XXX INX H 23 Increment the memory pointer
410D MOV M,A 77 Store the content of the
accumulator(Diff) to memory
410E INX H 23 Increment the memory pointer
410F MOV M,B 70 Move the content of the B
register (borrow )to memory
4110 HLT 76 End the program
8-BIT MULTIPLICATION
ALGORITHM:
1. Start the process.
15
2. Initialize the memory location for getting the multiplier and multiplicand and
transfer to 2 registers.
3. Clear the accumulator.
4. Initialize a register to store carry.
5. Add the accumulator content with the multiplier.
6. Check for carry. If carry is not present go to step 8.
7. Otherwise increment the register assigned for carry.
8. Decrement the multiplicand value.
9. Check for zero. If zero is not present go to step 5.
10. Else Store the (accumulator content) product & carry content in the specified
memory location.
11. Stop the process.
PROGRAM:
MEMORY
LABEL MNEMONIC OPCODE COMMENTS
ADDRESS
4100 LXI H, 4200 21 Load address of the data in
4101 00 HL register pair for
4102 42 initializing the memory
location to get multiplier&
multiplicant
4103 MOV B, M 46 Move the content(multiplier)
of the memory to B register
4104 INX H 23 Increment the memory pointer
4105 MOV C,M 4E Move the content
(multiplicant) of the memory
to C register
4106 XRA A AF Clear accumulator .
MVI E,00 1E Initialize E register to store
4107 00 carry.
16
410A 0E
410B 41
410C INR E 1C Increment E register
410D Loop1 DCR C 0D Decrement C register
410E JNZ Loop2 C2 If the result is not zero, Go to
410F 09 loop2
4110 41
4111 INX H 23 Increment the memory pointer
4112 MOV M, A 77 Store the content of the
accumulator(lower order byte)
to memory
4113 INX H 23 Increment the memory pointer
4114 MOV M, E 73 Store the content of the E
register (higher order byte) to
memory
4115 HLT 76 End the program
8-BIT DIVISION
ALGORITHM:
PROGRAM:
17
MEMORY
LABEL MNEMONIC OPCODE COMMENTS
ADDRESS
4109 JC Loop1 DA
If carry produced, Go to loop1
410A 10
410B 41
410C INR C Increment C register for
0C
Quotient
410D JMP Loop2 C3
Go to loop2
410E 08
410F 41
4110 Loop1 ADD B Add the content of B register
from content of accumulator
80
for Reminder.
18
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 02 FF 4202 04 FE
4201 02 FF 4203 00 01
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 10 05 4202 0B F5
4201 05 10 4203 00 01
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 1A FF 4202 4E 01
4201 03 FF 4203 00 FE
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 1A 1A 4202 03 03
4201 4E 4F 4203 00 01
RESULT:
VIVA QUESTIONS
19
1. What is Microprocessor?
2. Specify The Applications OF Microprocessor.
3. What are basic elements present in a Microprocessor?
4. Classify the instruction set of 8085.
5. What is the function ALE & ALU?
20
AIM:
To write a program to do 16 bit arithmetic operation such as
i) 16 bit addition ii) 16 bit subtraction iii) 16 bit Multiplication
iv) 16 bit division
APPARATUS REQUIRED:
1. Microprocessor kit
2. Power chord
ALGORITHM:
PROGRAM:
MEMORY
LABEL MNEMONIC OPCODE COMMENTS
ADDRESS
4100 MVI B,00 06 Initialize B register to store
21
00 carry
4102 LHLD 4200 2A Load the lower byte of addend
00 from memory location 4200
42 to L register and higher byte
from 4201 to H register.
4105 XCHG EB Exchange the contents of HL
with DE
4106 LHLD 4202 2A Load the lower byte of augend
4107 02 from memory location 4202
4108 42 to L register and higher byte
from 4203 to H register.
4109 DAD D 19 Add the contents of HL with
DE
410A JNC L1 D2 If no carry, Go to L1
0E
41
410D INR B 04 If carry is set, increment B
register
410E L1 SHLD 4204 22 Store the lower byte of the
04 sum in the memory location
42 4204 and store the higher byte
in 4205
4111 MOV A,B 78 Move the carry to
accumulator
4112 STA 4206 32 Store the carry in memory
06 location 4206
42
4115 HLT 76 End the program
16 BIT SUBTRACTION.
1. Start the process.
2. Get the LSB and MSB of minuend in two registers.
3. Initialize a register for borrow storage.
4. Get the LSB and MSB of subtrahend in two registers.
22
5. Subtract the LSB of subtrahend from LSB of minuend & store LSB difference.
6. Subtract the MSB of subtrahend from MSB of minuend along borrow.
7. Check for carry. If carry is not present go to step 9
8. Else increment the register assigned for borrow storage.
9. Store the difference and borrow content in the specified memory location.
10. Stop the process.
PROGRAM:
16 BIT MULTIPLICATION
1. Start the process.
2. Initialize a register pair for carry storage.
3. Get the multiplicand and multiplier from memory in register pairs.
4. Move the multiplicand to stack pointer.
5. Clean the HL Register pair.
6. Add the HL content with the multiplicand.
7. Check for carry. If carry is not present go to step 9.
8. Increment the register pair assigned for carry storage.
9. Decrement the multiplier check for zero.
10. If non Zero is not present go to step 6
11. Else Store the product and carry in specified memory location.
12. Stop the process.
4502 00
4530 LHLD 4300 2A Get the Multiplier data in HL
4504 00
4505 42
24
4506 XCHG EB Exchange HL and DE
4507 LHLD 4302 2A Get the Multiplicand in HL
4508 02
4509 43
450A SPHL F9 Transfer it to stack pointer
450B LXI H , 0000 21 Make HL as 0000
450C 00
450D 00
450E MUL DAD SP 39 Add Multiplicand &
Multiplier
450F JNC CAR D2 Go to CAR if no carry
4510 13
4511 45
4512 INX B 03 Increment BC by one
4513 CAR DCX D 1B Decrement DE by one
4514 MOV A , E 7B Transfer E content to A
4515 ORA D B2 OR the A content with D
4516 JNZ MUL C2 Go to MUL if result is zero
4517 0E
4518 45
4519 SHLD 4304 22 Store the product in memory
451A 04
451B 43
451C MOV L , C 69 Move C to L
451D MOV H , B 60 Move B to H
451E SHLD 4306 22 Store carry in memory
451F 06
4520 43
4521 HLT 76 Stop the program
PROGRAM:
16 BIT DIVISION
1. Start the process.
2. Initialize a register pair for quotient storage.
3. Get the LSB and MSB of dividend in 2 registers.
4. Get the LSB and MSB of divisor in 2 registers.
25
5. Subtract the LSB of divisor from dividend & transfer partial different in a
register.
6. Subtract the MSB of divisor from MSB dividend with carry.
7. Check for carry. If carry is present go to step 9.
8. Else increment the register assigned for quotient & go to step5.
9. Add the carry with divisor to get the reminder.
10. Store the quotient and reminder in the specified memory location.
11. Stop the process.
PROGRAM:
26
4517 45
4518 REM DAD B 09 Add BC with HL
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 DE FF 4204 EF FE
4201 DE FF 4205 EF FF
4202 11 FF 4206 00 01
4203 11 FF 4207 00 00
27
OBSERVATION - 16 BIT SUBTRACTION
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 1A 31 4204 79 20
4201 A1 84 4205 80 E1
4202 A1 51 4206 00 01
4203 12 65 4207 00 00
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 02 4204 02
4201 03 4205 23
4202 01 4206 30
4203 10 4207 00
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 2A 2A 4204 00 02
4201 11 11 4205 00 00
4202 A8 AA 4206 04 04
4203 44 44 4207 00 00
RESULT:
VIVA QUESTIONS
AIM:
To write a program to do Block operation such as i) Forward Block Transfer ii)
Reserve Block Transfer
29
APPARATUS REQUIRED:
1. Microprocessor kit
2. Power chord
ALGORITHM:
1. Start the Process.
2. Initialize memory to get data (say source memory).
3. Initialize memory to store the data (say destination memory).
4. Get the block size in any register through accumulator from memory(say count)
5. Get data from source memory to accumulator and store it in destination
memory.
6. Increment source & Destination memory pointer and decrement the block
size(count)
7. Check for zero. If zero in not there go to step5.
8. Stop the process.
PROGRAM:
30
450C JNZ xxx D2 If counter is zero, terminate
450D 07 the program. Else repeat the
450E 45 program for next data.
450F HLT 76 Terminate the program
ALGORITHM:
PROGRAM:
32
RESULT:
Thus programs for block operations were written, executed successfully and
outputs were verified.
VIVA QUESTIONS
33
EXPT.NO 5- PROGRAM FOR CODE CONVERSIONS WITH 8085
MICROPROCESSOR
AIM:
To write a program to do Block operation such as
i) HEXA DECIMAL to ASCII
ii) ASCII to HEXA DECIMAL
iii) BINARY TO BCD CODE CONVERSION
iv) BCD TO BINARY CODE CONVERSION
APPARATUS REQUIRED:
1. Microprocessor kit
2. Power Chord
PROGRAM:
ALGORITHM:
PROGRAM:
36
410B 07 Accumulator content
410C Loop1 STA 4201 32 Store the content of
410D 01 accumulator in 4201
410E 42
410F HLT 76 Stop the program
ALGORITHM:
PROGRAM:
37
410E INR C 0C Increment C register by one.
410F JMP XYZ C3 Go to XYZ
4110 07
4111 41
4112 XXX CPI 0A FE Compare the content of
4113 0A Accumulator with 0A
4114 JC XYY DA If carry is set, Go to XYY
4115 1D
4116 41
4117 SUI 0A D6 Subtract 0A from the
4118 0A Accumulator content
4119 INR D 14 Increment D register by one.
411A JMP XXX C3 Go to XXX
411B 12
411C 41
411D XYY MOV E,A 5F Move the content of
Accumulator to C register.
411E MOV A,D 7A Move the content of D register
to Accumulator.
411F RLC 07 Rotate the Accumulator
content left
4120 RLC 07 Rotate the Accumulator
content left
4121 RLC 07 Rotate the Accumulator
content left
4122 RLC 07 Rotate the Accumulator
content left
4123 ADD E 83 Add the content of C register
with Accumulator
4124 STA 4201 32 Store the content of
4125 01 Accumulator in 4201
4126 42
4127 MOV A,C 79 Move the content of E register
to Accumulator.
4128 STA 4202 32 Store the content of
4129 02 Accumulator in 4202
412A 42
412B HLT 76 Stop the program
38
BCD TO BINARY CODE CONVERSION
ALGORITHM:
PROGRAM:
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 6F 0A 4201 11 10
4202 01 00
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 96 10 4201 60 0A
40
RESULT:
Thus programs for code conversions were written, executed successfully and
outputs were verified.
VIVA QUESTIONS
41
EXPT.NO 6- PROGRAM FOR ARRAY OPERATIONS WITH 8085
MICROPROCESSOR
AIM:
To write a program to do Array operation such as
i) Find The Largest Element In An Array
ii) ii) Find the Smallest Element in an Array
iii) iii) Search An Element In An Array
APPARATUS REQUIRED:
1. Microprocessor kit
2. Power Chord
ALGORITHM:
6. Check for carry. If there is carry, copy the memory content (Largest number) to
accumulator.
PROGRAM:
43
430B MOV A , M 7E Move the content of the
memory to A register
430C YYY DCR B 05 Decrement the B register
430D JNZ XXX C2 f the result is not zero, Go to
430E 06 loop2
430F 43
4310 STA 4500 32 Store accumulator content
4311 00 (largest no) in the memory
4312 45 location 4500
4313 HLT 76 Stop the program
PROGRAM:
ADDRESS LABEL MNEMONICS OPCODE COMMENTS
4400 LXI H , 4200 21 Load address of first number
4401 00 in HL register pair for
4402 42 initializing the memory
location for getting elements
of an array.
4403 MOV B , M 46 Move the content of the
memory to B register to store
array size
4404 MVI A , FF 3E Initialize accumulator to FF.
4405 FF
44
4406 XYZ INX H 23 Increment the memory pointer
4407 CMP M BE Compare the content of the
memory to the content present
in the accumulator
4408 JC CCC DA If carry produced, Go to CCC,
4409 0C
440A 44
440B MOV A , M 7E Move the content of the
memory to A register
440C CCC DCR B 05 Decrement the B register
440D JNZ XYZ C2 f the result is not zero, Go to
440E 06 XYZ
440F 44
4410 STA 4500 32 Store accumulator content
4411 00 (largest no) in the memory
4412 45 location 4201
4413 HLT 76 Stop the program
SEARCH AN ELEMENT IN AN ARRAY
ALGORITHM:
1. Start the process.
2. Initialize memory for getting array of element.
3. Get the block size in any register from memory.
4. Get the element to be searched in Accumulator.
5. Compare this element with the array element.
6. Check for zero if zero is there go to step 10.
7. If not increment memory pointer & Decrement the block size.
8. Check for zero. If there is no zero go to step5.
9. If there is no element means, print FF to indicate no element & go to step11.
10. Store the location of the searched element.’
11. Stop the process.
PROGRAM:
ADDRESS LABEL MNEMONICS OPCODE COMMENTS
4400 LXI H , 4200 21 Load address of first number
4401 00 in HL register pair for
4402 42 initializing the memory
location for getting elements
of an array.
4403 MOV B , M 46 Move the content of the
memory to B register to store
array size
4404 MVI A , FF 3E Initialize accumulator to FF.
4405 FF (Element to be searched)
45
4406 INX H 23 Increment the memory pointer
4407 XYZ CMP M BE Compare the content of the
memory to the content present
in the accumulator
4408 JZ CCC CA
If carry produced, Go to CCC,
4409 18
440A 44
440B INX H 23 Increment the memory pointer
440C DCR B 05 Decrement the B register
440D JNZ XYZ C2
If the result is not zero, Go to
440E 07
XYZ
440F 44
4410 MVI A, FF 3E Move the immediate value FF
4411 FF in accumulator
4412 STA 4500 32 Store accumulator content in
4413 00 the memory location 4400
4414 45
4415 JMP HLT C3
4416 1B Go to HLT
4417 44
4418 CCC SHLD 4500 22
Store the HL pair value in
4419 00
4400
441A 45
441B HLT HLT 76 Stop the program
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 03 03 4500 0A FF
4201 05 AA
4202 0A CC
4203 09 FF
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 03 04 4500 05 02
4201 05 AA
4202 0A CC
4203 09 FF
02
46
OBSERVATION - SEARCH AN ELEMENT IN AN ARRAY
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
4200 03 04 4500 03 FF
4201 05 AA 4501 42
4202 0A CC
4203 FF DD
02
RESULT:
Thus programs for array operation were written, executed successfully and
outputs were verified.
VIVA QUESTIONS
47
EXPT.NO 7- STUDY OF MICROCONTROLLER KIT 8051 &
PROGRAMMING 8051
AIM:
APPARATUS REQUIRED:
1. Microcontroller kit
2. Power Chord
It is 8-bit microcontroller, means MC 8051 can Read, Write and Process 8 bit
data. This is mostly used microcontroller in the robotics, home appliances like mp3
player, washing machines, electronic iron and industries. Mostly used blocks in the
architecture of 8051 are as follows:
B-Register
This register is used in only two instructions MUL AB and DIV AB. This is also bit
addressable and 8 bit register.
PC-Program Counter
• Points to the address of next instruction to be executed from ROM
• It is 16 bit register means the 8051 can access program address from 0000H to
FFFFH. A total of 64KB of code. 16 bit register means.
Initial value 0 0 0 0 0000 0000 0 0 0 0 (0000H)
Final value 1111 1111 1111 1 1 1 1 (F F F FH)
49
There are four flags in 8051
• P → Parity flag → PSW 0.0
1 – odd number of 1 in ACC
0 – even number of 1 in ACC
• OV(PSW 0.2) → overflow flag → this is used to detect error in signed
arithmetic operation. This is similar to carry flag but difference is only that carry flag is
used for unsigned operation.
50
Address range of RAM is 00H to 7FH.
→ In MC8051, 128 byte visible or user accessible RAM is available which is shown in
figure. Extra 128B RAM which is not user accessible. 80H to FFH used for storage of
SFR (special function register)
Stack in 8051
→ RAM locations from 08H to 1FH can be used as stack. Stack is used to store the
data temporarily.
51
Stack is last in first out (LIFO)
→ Stack pointer (SP)
• 8bit register
• It indicates current RAM address available for stack or it points the top of stack.
• Initially by default at 07H because first location of stack is 08H.
• After each PUSH instruction the SP is incremented by one while in MC after PUSH
instruction SP is decremented.
• After each POP instruction the SP is decremented.
52
•VCC → 5V supply
• VSS → GND
• XTAL2/XTALI are for oscillator input
• Port 0 – 32 to 39 – AD0/AD7 and P0.0 to P0.7
• Port 1 – 1 to 8 – P1.0 to P1.7
• Port 2 – 21 to 28 – P2.0 to P2.7 and A 8 to A15
• Port 3 – 10 to 17 – P3.0 to P3.7
53
Following figure shows special function bit address, all access to the fourI/O
ports CPU register, interrupt control register, timer/counter, UART,power
control are performed through registers between 80H and FFH.
8 BIT ADDITION
ALGORITHM:
8102
8103 MOV Ro,#00 Initialize R0 as 00 for carry
8104 storage
8105 MOVX A,@DPTR Move the content pointed by
DPTR to Accumulator
8106 MOV R1,A Move the Accumulator
content to R1
8107 INC DPTR Increment DPTR by one.
8108 MOVX A,@DPTR Move the content pointed by
DPTR to Accumulator
8109 ADD A,R1 Add R1 content with
Accumulator
810A JNC 810D Goto 810D if there is no
810B carry
55
PROGRAM:
8 BIT SUBTRACTION
ALGORITHM:
1. Start the process
2. Initialize the memory location for input and output and one register to store
carry
3. Get minuend to the accumulator and increment the memory pointer
4. Get subtrahend in any of the register
5. Subtract minuend with subtrahend in the memory
6. Check for carry if carry is not present go to step 7
7. Increment the register assigned for borrow storage
8. Store the difference and borrow in specific memory location
9. Stop the process
PROGRAM:
56
ADDRESS LABEL MNEMONICS COMMENTS
8100 MOV DPTR,#8200 Move the data input location to
8101 DPTR
8102
8103 MOV Ro,#00 Initialize R0 as 00
8104
8105 MOVX A,@DPTR Move the content pointed by
DPTR to Accumulator
8106 MOV R1,A Move the Accumulator content
to R1
8107 INC DPTR Increment DPTR by one.
8108 MOVX A,@DPTR Move the content pointed by
DPTR to Accumulator
8109 CLR C Clear Carry bit
810A SUBB A,R1 Subtract R1 content from
810B Accumulator
810C JNC 810E Go to XX label specified
location when there is no carry
810D INC R0 Increment R0 by one
810E XX INC DPTR Increment DPTR by one.
810F MOVX @DPTR,A Move the accumulator value to
the memory location pointed by
DPTR
8110 INC DPTR Increment DPTR by one.
8111 MOV A,R0 Move the R0 content to
Accumulator
8112 MOVX @DPTR,A Move the accumulator value to
the memory location pointed by
DPTR
8113 SJMP 8113 End the program
57
8 BIT MULTIPLICATION
ALGORITHM:
1. Start the process
2. Initialize the memory location for input and output
3. Get multiplicand in any of the register
4. Get multiplicand to the accumulator and increment the memory pointer
5. Multiply multiplier with multiplicand
6. Store the product in specific memory location
7. Transfer the carry to the accumulator from the specified register
8. Store the carry in specific memory location
9. Stop the process
PROGRAM:
8102
8 BIT DIVISION
58
ALGORITHM:
PROGRAM:
59
OBSERVATION - 8 BIT ADDITION
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
8200 02 FF 8202 04 FE
8201 02 FF 8203 00 01
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
8200 10 05 8202 0B F5
8201 05 10 8203 00 01
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
8200 03 FF 8202 4E 01
8201 1A FF 8203 00 FE
INPUT OUTPUT
ADDRESS DATA 1 DATA 2 ADDRESS DATA 1 DATA 2
8200 1A 1A 8202 03 03
8201 4E 4F 8203 00 01
RESULT:
60
VIVA QUESTIONS
61
EXPT.NO 8- PROGRAM FOR ADC INTERFACE WITH 8051
MICROCONTROLLER
AIM:
To Study the Analog to Digital Convertor Interface Using 8051
APPARATUS REQUIRED:
1. Microcontroller kit
2. ADC Interface
WORKING PRINCIPLE:
There are numerous ways in which an analog signal can be converted to digital
form. The Analog to Digital convertors can be classified into two general groups based
on the conversion technique.
One technique involves comparing a given analog signal with the internally
generated equivalent signal. This group includes successive approximation, counter,
and flash-type converters. The second technique involves changing an analog signal
into time or frequency and comparing these new parameters against known values.
Thus group includes integrator converters and Voltage to Frequency converters. The
trade-off between the two techniques is based on accuracy Vs speed. The successive
approximation and the flash type are faster but generally less accurate than the
integrating and the Voltage to Frequency converters. Furthermore, the flash type is
expensive and difficult to design for high accuracy.
The most commonly used A/D converters are successive approximation and
integrating type A/D converters. The successive approximation A/D converters are
used in applications such as data loggers and instrumentation, where conversion speed
is important. On the other hand, integrating type converters are used in applications
such as digital meters, panel meters and monitoring systems, where the conversion
accuracy is critical.
First bit D3 is turned ON and the output of the DAC is compared with an
analog signal. If the comparator changes state, indicating that the output generated by
D3 is larger than the analog signal, bit D3 is turned OFF in the SAR and bit D2 is
turned ON. The process continues until the input reaches bit D0.
63
FUNCTIONAL DESCRIPTION FOR ADC 0809:
ADC 0809 is a monolithic CMOS device, with an 8-bit analog to digital
converter, 8 channel multiplexer and microprocessor compatible control logic.
The main features of ADC 0809 are,
1) 8 bit resolution
2) 100 µS conversion time
3) 8 channel multiplexer with latched control logic
4) No need for external zero or full scale adjustments
5) Low power consumption 15 mW
6) Latched tristate output
The device contains an 8 channel single ended analog signal multiplexer. A particular
input channel is selected by using the address decoding. Following table shows the
input states for the address lines to select any channel. The address is latched into the
decoder of the chip on low to high transition of the address latch enable (ALE). The
64
A/D converter’s successive approximation register is reset on the positive edge of the
start of conversion pulse. The conversion is begun on the falling edge of the SOC
pulse. End of conversion will go low between 0 and 8 clock pulses after the rising edge
of start of conversion.
ADDRESS LINE
Select Analog Channel
ADD C ADD B ADD A
IN0 0 0 0
IN1 0 0 1
IN2 0 1 0
IN3 0 1 1
IN4 1 0 0
IN5 1 0 1
IN6 1 1 0
IN7 1 0 1
I/O DECODING:
A 3 TO 8 decoded 74LS138 is employed to generate I/O decoding logic. Pin1,
Pin2 and Pin3 of 74LS138 is connected to Address lines A3, A4, and A5 respectively.
IOR and IOW signals are NANDed together and the NAND gate output is connected to
Pin6 of 74LS138. Similarly the Address lines A6 and A7 are NANDed and the NANd
gate output lied to Pin5 of the 3 to 8 decoder. Pin4 is grounded.
The buffer 74LS244 which transfers the converted data outputs to data bus is
selected when
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 0 X X X
= C0 (Hex)
The I/O address for the latch 74LS174 which latches the data bus to ADD A,
ADD B, ADD C and ALE 2 is
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 1 X X X
= C8 (Hex)
65
DATA (HEX)
EOC
Channel CH NO CH NO CH NO
Sl.No Address
Number ALE LOW ALE LOW ALE LOW
(Hex)
OE HIGH OE HIGH OE HIGH
1 CH0 D8 10 18 10
2 CH1 D8 11 19 11
3 CH2 D8 12 1A 12
4 CH3 D8 13 1B 13
5 CH4 D8 14 1C 14
6 CH5 D8 15 1D 15
7 CH6 D8 16 1E 16
8 CH7 E0 17 1F 17
9 CH8 E0 00 20 00
10 CH9 E0 01 21 01
11 CH10 E0 02 22 02
12 CH11 E0 03 23 03
13 CH12 E0 04 24 04
14 CH13 E0 05 25 05
15 CH14 E0 06 26 06
16 CH15 E0 07 27 07
The start of conversion pulse can be given by means of software also. The flip
flop 74LS74 which transfers the D0 line status to the SOC pin of AAADC 0809 is
selected when
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 1 0 X X X
= D0 (Hex)
The EOC output of ADC1 and ADC2 is transferred to D0 line by means of two
tri-state buffers. The EOC1 is selected when
A7 A6 A5 A4 A3 A2 A1 A0
1 1 1 0 0 X X X
66
= D8 (Hex)
GO TOER DETAILS:
J2: (soc Go toer selection for ch0-ch7)
67
Place this Go toer according to your requirement.
J5: (provision to connect the on board trimpot to any of the below mentioned channels)
J6: (Provision to connect the on board trimpot to any of the below mentioned channels)
68
2. Transfer the control word to the control register to select channel 0 with ALE
low, 0E high.
3. Transfer the control word to the control register to select channel 0 with ALE
high, 0E high.
4. Stop the process.
PROGRAM 1:
PROGRAM 2:
69
ADDRESS LABEL MNEMONICS COMMENTS
8100 MOV DPTR,#FFC8 Move the port address
to DPTR
8103 MOV A,#10 Move the value 10 to
Accumulator
8105 MOVX @DPTR,A Move the accumulator
value to DPTR
8106 MOV A,#18 Move the value 18 to
Accumulator
8108 MOVX @DPTR,A Move the accumulator
value to DPTR
8109 MOV DPTR,#FFD0 Move the port address
to DPTR
810C MOV A,#01 Move the value 01 to
Accumulator
810E MOVX @DPTR,A Move the accumulator
value to DPTR
810F MOV A,#00 Move the value 00 to
Accumulator
8111 MOVX @DPTR,A Move the accumulator
value to DPTR
8112 MOV DPTR,#FFD8 Move the port address
to DPTR
8115 WAIT MOVX A,@DPTR Move the value
indicated by the address
present in DPTR to
Accumulator
8116 JNB E0,WAIT If no bit at E0, Go to to
WAIT
8119 MOV DPTR,#FFC0 Move the port address
to DPTR
811C MOVX A,@DPTR Move the value
indicated by the address
present in DPTR to
Accumulator
8110 MOV DPTR,#8150 Move the memory
location to DPTR
8120 MOVX @DPTR,A Move the accumulator
value to DPTR
8121 HERE SJMP HERE Short Go to here.
PROCEDURE:
i) Connect the microcontroller kit with ADC interface board using 50 core
connector (VXT BUS).
70
ii) Vary the analog input using pot in ADC board.
iii) Execute the program
iv) Check the output in leads with proper Go toer position
v) Also check the output in the memory location.
RESULT:
APPARATUS REQUIRED:
1. Microcontroller kit
2. Power chord
3. DAC Interface
4. CRO with Probe
WORKING PRINCIPLE
D/A CONVERTERS:
Digital to Analog converters can be classified as current output, voltage output
and multiplying type. The current output DAC provides current as the output signal.
The voltage output DAC internally converts the current signal into the voltage signal.
The voltage output DAC is slower than the current output DAC because of the delay in
converting the current signal into the voltage signal. The multiplying DAC is similar to
the other 2 types except its output represents the product of input signal and the
reference source and the product is linear over a broad range.
72
Fig. 9.1
SUCCESSIVE APPROXIMATION TECHNIQUE:
Successive approximation process can be shed through either software or
hardware approach. In software approach, an A/D converter is designed using A/D
converter and the microprocessor plays the role of the comparator and the SAR. Block
diagram for successive approximation ADC is shown in Fig 9.2.
Fig. 9.2
The basic microprocessor board, VBMB-002, incorporates two 8-bit Digital to
Analog converters, DAC 0800.
DAC 0800 is a monolithic, high speed, current output Digital to Analog
converter. Its unique features are:
Typical settling time of 100 Nanoseconds.
Complementary current outputs.
73
Differential output voltages of 20V peak to peak with simple resistor loads.
2-quadrant wide range multiplying capability.
The DAC interface section comprises of
I/O decoding
D/A conversion circuit
I/O DECODING:
The IC’s 74LS138 and 74LS00 form the address decoding logic in this
interface board. The address lines A3, A4 and A5 are tied to pin1, pin2 and pin3 of
74LS138 respectively. The address lines A6 and A7 are NANDed together and the
NAND gate output is connected to pin5 of 74LS138. Similarly IOW and IOR signals
are NANDed and the NAND gate output is connected to pin6 of 74LS138. Pin4 is
grounded.
Thus with
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 0 X x X
= C0 (Hex)
DAC1 is selected, and with
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 1 X X X
= C8 (Hex)
DAC2 is selected.
The DAC outputs are available at the 5 pin connector (P2). DAC 1 and DAC 2
outputs are terminated at pin 5 and pin4 respectively. Pin1 is connected to the ground.
A/D CONVERSION CIRCUIT:
It is possible to construct an ADC using DAC, if a register (SAR) or a counter
is available. The software based A/D converter microprocessor can act as a counter or
successive approximation register. To illustrate this, we have provided a comparator
LM-311 in our card VBMB-002. The output of DAC channel 1 is given to one of the
inputs of the comparator. An analog voltage can be given between -5 to +5V to be
converted to digital forms the other input. Fig 9.3 illustrates the arrangement.
Fig. 9.3
The comparator’s output goes high when DAC 1 and the analog voltage are
approximately equal. To check the output of the comparator, we have provided one
tristate buffer (U10) the output of which is connected to D0 line. The 74125 address is
decoded as follows.
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 1 0 0 0 0
= D0 (Hex)
ALGORITHM:
75
SQUARE WAVE GENERATION
1. Start the process.
2. Transfer the low output equivalent hex data to DAC address through
accumulator.
3. Call delay subroutine to maintain the low state.
4. Transfer the high output voltage equivalent hex data to DAC port address
through accumulator.
5. Call delay subroutine to maintain the high level.
6. Else go to step2
7. Stop the process.
SUB ROUTINE
1. Start the subroutine.
2. Transfer outer loop count to any of the register.
3. Transfer inner loop delay count to any other register
4. Decrement the inner loop count.
5. Check for zero. If zero does not occur go to step4.
6. Decrement the outer loop count.
7. Check for zero. If zero does not occur, go to step3.
8. Return to main program.
76
ADDRESS LABEL MNEMONICS COMMENTS
8100 MOV DPTR,#FFC8 Move the port address
8101 to DPTR
8102
8103 START MOV A,#00 Move the value 10 to
Accumulator
8104
8105 MOVX @DPTR,A Move the accumulator
value to the memory
location pointed by
DPTR
8106 LCALL DELAY Long call DELAY
8107
8108
8109 MOV A,#FF Move the value FF to
Accumulator
810B MOVX @DPTR,A Move the accumulator
value to the memory
location pointed by
DPTR
810C LCALL DELAY Long call DELAY
810F LJMP START Long Go to to START
8112 DELAY MOV R1,#05 Move 05 to Register R1
8114 LOOP MOV R2,#FF Move FF to Register R2
8115
8116 HERE DJNZ R2,HERE Decrement R2. If no
zero, Go to to HERE.
8118 DJNZ R1,LOOP Decrement R1. If no
zero, Go to to LOOP.
811A RET Return
77
ADDRESS LABEL MNEMONICS COMMENTS
8100 MOV Move the port
DPTR,#FFC0 address to DPTR
8101
8102
8103 MOV A,00 Move the value 00
8104 to Accumulator
8105 LOOP MOVX Move the
@DPTR,A accumulator value
to the memory
location pointed by
DPTR
8106 INC A Increment
Accumulator by one
8107 SJMP LOOP Short Go to to
LOOP
SQUARE WAVE
TRIANGULAR WAVE
78
ADDRESS LABEL MNEMONICS COMMENTS
8100 MOV DPTR,#FFC0 Move the port address
to DPTR
8101
8102
8103 START MOV A,#00 Move the value 00 to
Accumulator
8104
8105 LOOP1 MOVX @DPTR,A Move the accumulator
value to the memory
location pointed by
DPTR
8106 INC A Increment
Accumulator by one
8107 JNZ LOOP1 If zero flag not set, Go
to to LOOP1
8108
8109 MOV A,#FF Move the value FF to
Accumulator
810A
810B LOOP2 MOVX @DPTR,A Move the accumulator
value to the memory
location pointed by
DPTR
810C DEC A Decrement
Accumulator by one
810D JNZ LOOP 2 If zero flag not set, Go
to to LOOP2
810E
811F LJMP START Long Go to to start
79
PROCEDURE:
i) Connect the microcontroller kit with DAC interface board using 50 core
connector (VXT bus).
80
ii) Connect CRO channel 1 to DAC 1 or DAC 2 in DAC board.
iii) Execute the program
iv) Check the output in CRO for the required output.
v) Note the amplitude & time period for the waveform
RESULT:
81
APPARATUS REQUIRED:
1. Microcontroller kit
2. Stepper Motor Interface
STEPPER MOTOR:
A motor in which the rotor is able to assume only discrete stationary angular
position is a stepper motor. The rotary motion occurs in a stepwise manner from one
equilibrium position to the next.
Stepper motor control is a very popular application of microprocessor in control
area. They are widely used in a variety of applications such as computer peripherals
and in the areas of process control machine tools, medicine, numerically controlled
machines and Robotics.
CONSTRUCTIONAL FEATURES:
A stepper motor could be either of the reluctance type or of the permanent
magnet type (PM). A PM stepper motor consists of multiphased stator and two part
permanent magnet rotor. The VR stepper motor has unmagnetised rotor. PM stepper
motor is the most commonly used type. The basic two phase stepper motor consists of
two pairs of stator poles. Each of the four poles has its own winding. The excitation of
any one winding generates a north pole (N), a south pole (S) gets induced at the
diametrically opposite side.
82
As shown in the figure the four pole structure is continuous with the stator
frame and the magnetic field passes through the cylindrical stator annular ring. The
rotor magnetic system has two end faces. The left face is permanently magnetized as
South Pole and the right face as North Pole. The South Pole structure and the North
Pole structure possess similar pole faces. The North Pole structure is twisted with
respect to the South Pole structure so that South Pole comes precisely between two
north poles. The North Pole structure is offset with respect to the South Pole structure
by one pole pitch. The cross sectional view is shown in fig. In an arrangement where
there are four stator poles and three pairs o rotor poles, there exits 12 possible stable
positions in which a south pole of the rotor can lock with a north pole of the stator.
From this it can be noted that the step size is
[360o/(Ns*Nr)]
Where
Ns is the no. of stator poles.
Nr is the no. of pairs of rotor poles.
Generally step size of the stepper motor depends upon NR. These stable
positions can be attained by simply energizing the winding on any one of the stator
poles with a DC. There are three different schemes available for stepping a stepper
motor. These are:
a) Wave scheme
2-PHASE SCHEME:
83
In this scheme, any two adjacent stator windings are energized. There are two
magnetic fields active in quadrature and none of the rotor pole faces can be in direct
alignment with the stator poles. A partial but symmetric alignment of the rotor poles is
of course possible.
Typical equilibrium conditions of the rotor when the windings on two
successive stator poles are excited are illustrated in the following fig. In step (a), A1
and B1 are energize. The pole-face S1 tries to align itself with the axis of A1(N) and
the pole face S2 with B1(N). The north pole N3 of the rotor finds itself in the neutral
zone between A1(N) and B1(N). S1 and S2 of the rotor, position themselves
symmetrically with respect to the two stator north pole.
Next, when B1 and A2 are energized, S2 tends to align with B1(N) and S3 with
A2(N). Of course, again under equilibrium conditions, only partial alignment is
possible and N1 finds itself in the neutral region, midway between B1(N) and A2(N)
[step (b)]. In step (c), A2 and B2 are on. S3 and S1 tend to align with A2(N) and
B2(N), respectively, with N2 in the neutral zone. Step (d) illustrates the case with A1
and B2 are on.
84
Fig. Step (c) Fig. Step (d)
The step angle is 30o as in the wave scheme. However, the rotor is offset by 15 o
in the two-phase scheme with respect to the wave scheme. A total of 12 steps are
required to move the rotor by 360o (mechanical). Two-phase drives produce more
torque than the wave drives.
The switching sequence for the 2-phase scheme is given in the following table.
Clockwise Anti-clockwise
Step A2 A2 B1 B2 Step A2 A2 B1 B2
1 1 0 0 1 1 1 0 1 0
2 0 1 0 1 2 0 1 1 0
3 0 1 1 0 3 0 1 0 1
4 1 0 1 0 4 1 0 0 1
Table: Phase switching scheme
85
Eight steps are required to move the shaft by 120 o and 24 steps for one
complete revolution. By reversing the switching sequence, we can reverse the direction
of rotation. One major disadvantage of the half stepping scheme is torque fluctuations.
This is because the aligning torque for the wave scheme is different from that for the 2-
phase scheme.
ADDRESS DECODING:
The 74138 chip (U2) generates the address decoding logic to generate the
device select pulses, CS1 and CS2 for selecting the ICs 74175 (U3 & U5). The 74175
(U3 & U5) latches the data bus to the stepper motor driving circuitry. Address lines A7
& A6 from VXT Bus is NANDed and the o/p is connected to 138 enable signal.
Similarly IOW & IOR signals are NANDed and the NAND gate o/p is connected to
Pin6 of 74138, Pin4 is grounded.
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 0 X x X
= C0 (Hex)
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 1 X x X
= C8 (Hex)
ALGORITHM:
TO RUN THE STEPPER MOTOR FOR DIFFERENT SPEED
1. Start the process
2. Initialize the memory for storing the data used to energize the poles
3. Initialize the count
4. Transfer the memory content to accumulator and deliver it to the specified port
address
5. Provide delay to energize poles and make rotation
6. Increment the memory pointer
7. Decrement the count
8. Check for non zero if it is non zero go to step 4
9. Else go to step 2
10. Terminate the process
87
ADDRESS LABEL MNEMONICS COMMENTS
811D
811E INC DPTR Increment the data pointer
811F DJNZ R0,JO Decrement R0 , if no zero, Go to JO
8120
8121 SJMP START Go to START
8122
8123 END End the program
8500 TABLE 09,05,06,0A Data
PROGRAM TO RUN A STEPPER MOTOR FOR REQUIRED ANGLE
88
WITHIN 360 DEGREE WHICH IS EQUIVALENT TO 256 STEPS
ADDRESS LABEL MNEMONICS COMMENTS
8100 MOV R4,#05 Move the immediate
8113 value 05 to R4register
8101
8114 LOOK DB 09H,05H,06H,0AH Loading the lookup
8102 UP START MOV DPTR,#LOOK valuesMove look up table
tableUP
8103 value to data pointer
8115
8104
8116
8105 MOV R0,#04 Move the immediate
8117 value 04 to R0 register
8106 Move the immediate
8118 CALL MOV R2,#03
8107
8119 JO MOVX A,@DPTRvalue 03 to R2 register
Move DPTR value to
Accumulator
811F
810D value FF00 to data
812C
812D END End the program
89
PROCEDURE:
i) Connect the microcontroller kit with stepper motor interface board using
50 core connector (VXT bus). & connect the motor to the interface
board
ii) Execute the program
iii) Check the motor for various speed (or) particular angle of rotation.
90
RESULT:
APPARATUS REQUIRED:
1. Microcontroller kit
2. Power Chord
3. Keyboard/ Display Interface
91
DISPLAY MODE SETUP:
The command word for keyboard and display mode is,
0 0 0 D D K K K
DD-DISPLAY MODE:
00 – 8 8 bit Character display – Left Entry
01 – 16 8 bit Character display – Left Entry
10 – 8 8 bit Character display – Right Entry
11 – 8 8 bit Character display – Right Entry
Table below shows the correspondence between the data bus and output port
bits of 8279. Also, the segment relationship with these is given:
Data bus D7 D6 D5 D4 D3 D2 D1 D0
8279 Output A3 A2 A1 A0 B3 B2 B1 B0
Segments d c b a dp g f e
D0 bit of the byte sent to the display RAM corresponds to B0 and D7 of the
byte sent to the display RAM corresponds A3. In order to light up a segment the
corresponding bit of data written into the display RAM should be a “0”.
I/O DECODING:
IC’s 74LS00 (U1) and 74LS138 (U2) form the address decoding logic to
generate the chip select signal for 8279. Address lines A6 and A7 are NANDed and the
NAND gate output is connected to pin 5 of 74LS138 (U2). Similarlly, the IOW and
IOR are NANDed and the NAND gate output is connected to Pin6 of 74LS138. The
92
inputs A, B and C of 74LS138 are connected to address lines A3, A4 and A5
respectively.
The 8279 is selected when,
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 0 X x X
= C0 (Hex)
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 0 X 1 X
= C2 (Hex)
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 0 X 0 X
= C0 (Hex)
1 0 0 AI A A A A
This command is written with A0 (pin 21 of 8279) = 1. All subsequent writes with
A0=0 will be to the Display RAM.
AI – Auto Increment Flag. If AI-1, the row address selected will be
incremented after each following read or write to the Display RAM.
AAAA – Selects one of the 16 rows of the Display RAM.
CLEAR DISPLAY:
The command word format for clear display is,
1 1 0 CD CD CD CF CA
CD CD CD – The lower two CD bits specify the blanking code to be sent to the
segments to turn them off while the 8279 is switching from one digit to next.
93
ALGORITHM:
DISPLAY A CHARACTER
1. Transfer the control word to control register the mode and display set and
specify the character with left entry and display it.
2. Transfer the control word to control word to control register to clear the
Display
3. Transfer the control word to control register for auto increment set and with
RAM Address.
4. Transfer the data for the character to accumulater to display it
5. Transfer the data to data register to blank the rest of the display..
6. Terminate the process.
ROLLING DISPLAY
1. Initialize the memory for storing the data to to be rolled.
2. Initialize the count register
3. Transfer the control word to control register the mode and display set and
specify the character with left entry and display it.
4. Transfer the control word to control word to control register to clear the
Display
5. Transfer the control word to control register for auto increment set and with
RAM Address.
6. Transfer the all the Data one by one to data register for display .
7. Repeat step 6 for rolling the display.
94
ADDRESS LABEL MNEMONICS COMMENTS
8100 MOV R0,#05 Move 05 to Register R0
8102 MOV DPTR,#FFC2 Move the port address
to DPTR
8104 MOV A,#02 Move the value 02 to
Accumulator
8107 MOVX @DPTR,A Move the accumulator
value to the memory
location pointed by
DPTR
8109 MOV A,#CC Move the control word
CC to Accumulator
810A MOVX @DPTR,A Move the accumulator
value to the memory
location pointed by
DPTR
810C MOV A,#90 Move the control word
90 to Accumulator
810D MOVX @DPTR,A Move the accumulator
value to the memory
location pointed by
DPTR
810F MOV A,#88 Move the data 88 to
Accumulator
8110 MOV DPTR,#FFC0 Move the port address
FFC0 to DPTR
8112 MOVX @DPTR,A Move the accumulator
value to the memory
location pointed by
DPTR DISPLAY
8115 MOV A,#FF Move the data FF to A
Accumulator
8116 MOV DPTR,#FFC0 Move the port address
FFC0 to DPTR
8118 LOOP1 MOVX @DPTR,A Move the accumulator
value to the memory
location pointed by
DPTR
811B D JNZ R0,LOOP1 Decrement R0. If no
zero, Go to LOOP1
811C SJMP 811C Short Go to to 811C
CHARACTER
95
ROLLING DISPLAY
96
4100 START MOV R1,# 44 Move higher byte of the memory
location to Register R1
4103 MOV R0,# 00 Move lower byte of the memory
location to Register R1
4105 MOV DPTR, #FFC2 Move the port address to DPTR
4107 MOV A,# 10 Move the value 10 to Accumulator
4109 MOVX @DPTR,A Move the accumulator value to the
memory location pointed by DPTR
410A MOV A,#CC Move the control word CC to
Accumulator
410C MOVX @DPTR,A Move the accumulator value to the
memory location pointed by DPTR
410D MOV A,#90 Move the control word 90 to
Accumulator
410F MOVX @DPTR,A Move the accumulator value to the
memory location pointed by DPTR
4110 LOOP MOV DPL,R0 Move the value of R0 to DPL
4112 MOV DPH,R1 Move the value of R1 to DPH
4114 MOVX A, @DPTR Move the content pointed by DPTR
to Accumulator
4115 MOV DPTR, #FFC0 Move the port address to DPTR
4118 MOVX @DPTR,A Move the accumulator value to the
memory location pointed by DPTR
4119 LCALL DELAY Long call DELAY
411C D JNZ R0,LOOP Decrement R0 by one. If no zero,
Go to LOOP.
411E INC R0 Increment R0 by one.
411F CJNE R0,#0F,LOOP If the content of R0 and 0F are not
equal, Go to LOOP
4122 LJMP START Go to START
4400 FF FF FF FF
4404 FF FF FF FF
4408 98 68 7C C8
440C FF 1C 29 FF
97
PROCEDURE:
i) Connect the microcontroller kit with keyboard & display interface board
using 50 core connector (VXT bus).
ii) Execute the program
iii) Check the seven segment display for a character (or ) rolling display
RESULT:
98
INTERFACE WITH 8051 MICROCONTROLLER
AIM:
To Study the Serial Communication Interface Using 8051
APPARATUS REQUIRED:
1. Microcontroller kit
2. Serial communication Interface board
TIMER INTERFACE:
CS RD WR A1 A0 FUNCTION
0 1 0 0 0 Load Counter 0
0 1 0 0 1 Load Counter 1
0 1 0 1 0 Load Counter 2
0 1 0 1 1 Write Control word
0 0 1 0 0 Read Counter 0
0 0 1 0 1 Read Counter 1
0 0 1 1 0 Read Counter 2
0 0 1 1 1 No-operation 3-state
1 X X X X Disabled 3-state
0 1 1 X X No-operation 3-state
RS232C INTERFACE:
PROGRAMMABLE COMMUNICATION INTERFACE – IC 8251:
99
The RS232C interface of VBMB-004 comprises of the universal
synchronous/asynchronous receiver/transmitter 8251 (USART), RS232C driver (MC
1488) and RS232C receiver (MC 1489).
The 8251A is used here as a peripheral device for serial communication and is
programmed by the CPU to operate using virtually any serial data transmission
technique. The USART accepts data characters from the CPU in parallel format and
then converts them into a continuous serial data stream for transmission.
Simultaneously, it can receive serial data streams and convert them into parallel data
characters for the CPU. The CPU can read the status of the USART at any time. These
include data transmission errors and control signals.
The main features of 8251A are,
1) Both synchronous and Asynchronous operation,
2) False start Bit Detection,
3) Automatic Break Detect and Handling,
4) Clock rate – 1, 16 or 64 time Baud rate,
5) Error Detection – Parity, Overrun and Framing Errors,
6) Break Character Generation.
The control pins with which the 8251A communicates with the CPU are the
RESET, CLK, WR, RD, CS, C/D, D0-D7. The table below shows basic operations
performed by 8251, as determined by the control signals.
C/D RD WR CS FUNCTION
0 0 1 0 8251A DATA=> DATA BUS
0 1 0 0 DATA BUS => 8251A DATA
1 0 1 0 STATUS => DATA BUS
1 1 0 0 DATA BUS => CONTROL
X 1 1 0 DATA BUS => 3 STATE
X X X 1 DATA BUS => 3 STATE
100
voltage level different from TTL levels, -12V corresponds to logic high and +12V
corresponds to logic low.
Obviously, 8251 is not directly compatible with these signal levels. Standard
method to interface RS232C and TTL levels is with MC1489 quad TTL-to- RS232C
drivers and MC1489 quad RS232C-to-TTL receivers. Of the 25 handshake signals
provided by the RS232C standard, lets discuss RTS, CTS, RxD and TxD signals.
When connected with another system for serial communication, these signals
will connect with the CTS, RTS, TxD and Rxd signals of that system respectively.
1) CTS: Clear to Send – Enables 8251A to transmit serial data, if TxEnable bit in
the command byte is set to one.
2) RTS: Request to Send – When low, indicates that 8251A can receive serial
data. It can be made low by setting the RTS bit in the command byte.
3) TxD: Transmit serial data.
4) RxD: Receive serial data.
I/O DECODING:
I/O decoding logic is generated by a 3 to 8 decoder 74LS138 and NAND gates
74LS00. As usual, the address lines, A3, A4 and A5 are connected to Pin1, Pin2 and
Pin3 of 74LS138. Address lines A6 and A7 are NANDed and the NAND gate output is
connected to Pin6 of 74LS138. Similarly IOW and IOR are NANDed together and the
NAND gate output is connected to Pin5. Pin4 is grounded.
Thus 8251 is selected with address,
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 0 X X X
Since the address line A1 is connected to control/data input of 8251, the control
register of 8251 is selected when,
A7 A6 A5 A4 A3 A2 A1 A0
1 1 0 0 0 0 1 X
= C2 (Hex)
The two address lines A1 and A2 are connected to the Pin A0 (Pin 19) and A1
(Pin 20) of 8253 respectively. Thus the I/O address for control register, Channel 0,
Channel 1 and Channel 2 are:
A7 A6 A5 A4 A3 A2 A1 A0 HEX
CONTROL REG 1 1 0 0 1 1 1 0 CE
CHANNEL 0 1 1 0 0 1 0 0 0 C8
CHANNEL 1 1 1 0 0 1 0 1 0 CA
CHANNEL 2 1 1 0 0 1 1 0 0 CC
ALGORITHM:
TRANSMITTER:
102
1. Start the process
2. Transfer the control word to control register of 8253 to select channel 0, mode 3
with binary count
3. Transfer LSB count to counter 0
4. Transfer MSB count to counter 0
5. Transfer control word to control register of 8251 to set the bandrate of the
processor bandrate with 8 bit character length with no parity, one bit stop bit.
6. Transfer the command instruction to 8251 control register.
7. Check the transmitter empty and transmitter ready state. If transmitter is ready
and transmitter empty is enable then transfer data to data register.
8. Stop the process.
RECEIVER:
1. Start the process
2. Transfer the control word to control register of 8253 to select channel 0, mode 3
with binary count
3. Transfer LSB count to counter 0
4. Transfer MSB count to counter 0
5. Transfer control word to control register of 8251 to set the bandrate of the
processor bandrate with 8 bit character length with no parity, one bit stop bit.
6. Transfer the command instruction to 8251 control register.
7. Check the receiver empty and receiver ready state. If receiver is ready and
receiver empty is enable then get the data from buffer to accumulator and store
it.
8. Stop the process.
103
TO CHECK TRANSMISSION AND RECEPTION OF CHARACTER
ADDRESS LABEL MNEMONICS COMMENTS
8100 MOV A,#36 Initialize control word format for 8253
8101
8102 MOV Initialize the control register for 8253
DPTR,#FFCE
8103
8104
8105 MOVX @DPTR,A Move Accumulator value to DPTR
location
8106 MOV A,#12 Set the higher order timer value
8107
8108 MOV DPTR,#FFC8 Initialize the control word for channel 0
8109
810A
810B MOVX @DPTR,A Move A to DPTR location
810C MOV A,#00 Set the lower order timer value
810D
810E MOVX @DPTR,A Move A to DPTR location
810F MOV A,#4E Initialize the mode instruction format
8110
8111 MOV DPTR,#FFC2 Initialize the control register address for
8251
8112
8113
8114 MOVX @DPTR,A Move A to DPTR location
8115 MOV A,#37 Initialize the command instruction
8116 format
104
TO CHECK KIT TO KIT DATA (TRANSMITTER)
8110
8111
8112 REPT JNB SCON.0 REPT Check whether the byte is
received
8113
8114
8115 CLR SCON.0 Clear SCON.0 to receive
next register
8116
8117 MOV A,SBUF Store the data in
8118 accumulator
8119 MOV DPTR,#4200 Set the pointer
811A
811B
8118 MOVX @DPTR,A Store the data
8119 HERE SJMP HERE Stop the program
106
PROCEDURE:
i) Connect the microcontroller kit with serial communication interface
board using 50 core connector (VXT bus).
ii) Check the Go toer position.
iii) Execute the receiver program and then the transmitter program
iv) Check the output at the receiver memory location.
RESULT:
107