You are on page 1of 102

Exp 1.a.

:Introduction to emu8086

1.a. INTRODUCTION TO EMU 8086

An assembly language program consists of a series of lines of assembly language


instructions, which consists of mnemonics optionally followed by one or two operands.
The operands are the data items being manipulated, and the mnemonics are the
commands to the CPU, telling it what to do with those items.

8086 Instruction - Basic Structure:

Label Operator Operand[s] ; Comment


Label - Optional alphanumeric string
1st character must be a-z,A-Z,?,@,_,$
Last character must be :
Operator - assembler language instruction
mnemonic an instruction format for humans
assembler translates mnemonic into hexadecimal code
Operand[s] - 0 to 2 pieces of data required by instruction can be several different
forms delineated by commas immediate, register name, memory data,
and memory address.
Comment - Extremely useful in assembler language general rule is 1 comment per
instruction.
These fields are separated by White Space (tab, blank, \n, etc.)

8086 Instruction – Example:


Label Operator Operand[s] ; Comment
INIT: mov ax, bx ; Copy contents of bx into ax

Comment - Alphanumeric string between; and \n

1. Anatomy of ASM Source File

• Assembler Program Divided Into Segments


– Not Exactly the same as Memory Segments.
– Program can have Several Segments; Only 1 Active.

• Segments Defined in 1 or More Modules


– contain instructions, data and directives.

• Each Module is a Separate File


– Assembler Translates Modules to Object Files.

 Linker Does Several Things


– Combines Multiple Object Files.
– Resolves Relative Addresses.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 1


Exp 1.a.:Introduction to emu8086

– Inserts Loader Code.


– Creates Executable.

2. Steps to create and execute a program: Flow diagram

EDITOR
PROGRAM
<filename>.asm

ASSEMBLER
PROGRAM

<filename>.lst
other .obj files
<filename>.obj

LINKER
PROGRAM

<filename>..exe

3. Using EMU8086:

 Write the assembly language program in the editor provided by emu8086


tool and save it with extension ‘.asm’ to c:\emu8086\MySource, this is said to be
a source file.

 To run this example in the emulator, click emulate (or press F5). The
program then attempts to assemble and save the executable to
c:\emu8086\MyBuild. If the assembler succeeds in creating the file, the emulator
will also automatically load it into memory.

 You can then click single step (or press F8) to step through the code
one instruction at a time, observing changes in registers and the emulator screen.

You can also click step back (or press F6) to see what happens when
reversing those changes.
(or)

 You can click run (or press F9) for burst execution.
 Results can be verified either in registers or memory by view → memory.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 2


Exp 1.a.:Introduction to emu8086

Notation for Registers and status Flags:

Table 1: Registers

Symbol Register Symbol Register


AX Accumulator BP Base Pointer
BX Base CS Code segment
CX Count DS Data segment
DX Data SS Stack segment
SI Source Index ES Extra Segment
DI Destination Index F Flag
SP Stack Pointer IP Instruction pointer

Table 2: Flag status indication

Flag Meaning Set Reset


OF Overflow OV NV
DF Direction DN UP
IF Interrupt EI DI
SF Sign NG PL
ZF Zero ZR NZ
AF Auxiliary carry AC NA
PF Parity PE PO
CF carry CY NC

4. Data Allocation Directives:

Assemble Description
r
Directive
DB define byte
DW define word (2 bytes)
DD define double word (4 bytes)
DQ define quad word (8 bytes)
DT define ten bytes
EQU Equate, assign numeric expression or
constant to a name.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 3


Exp 1.a.:Introduction to emu8086

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 4


Exp 1.b: Addressing Modes

1. b. ADDRESSING MODES

Aim: To transfer the 10h bytes from location 2000h: 0100h to 3000h: 0100h using different
addressing modes.

Equipment Required:

1. A PC with
a. Emu 8086 Installed

Program:

CODE SEGMENT ;start of code segment


ASSUME CS: CODE ;define segments
START:MOV AX, 2000H ;define data for the code
MOV DS, AX
MOV SI, 0100H ;copy source block offset address in
; SI register
MOV AX, 3000H
MOV ES, AX
MOV DI, 0100H ;copy dest. block address in DI reg.
MOV CX, 10H ;Initialize count register

AGAIN:MOV AL, [SI] ;copy a data byte at offset SI in DS


;to AL(AX is used for word transfer)
MOV ES:[DI], AL ;copy data byte in AL to memory at
; offset DI in DS
INC SI ;Increment SI to point to next byte
; location
INC DI ;Increment DI to point to next byte
; location
DEC CX ;decrement count
JNZ AGAIN ;jump if non zero to relative again
INT 3 ;Exit to DOS mode
CODE ENDS ;End of code segment
END START ;End Program

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 5


Exp 1.b: Addressing Modes

Flowchart:

START

DS 2000H
ES 3000H

SI 0100H
DI 0100H
CX 10H

AL [SI]
[DI] AL

SI SI + 1
DI DI + 1
CX CX - 1

NO (ZF = 1)?

YES

STOP

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 6


Exp 1.b: Addressing Modes

Result:
View memory contents.
First fill the source contents from 20100h to 20110h with some value 'FF'

Before block transfer:


Source:
View ds:0100 0110
2000:0100 FF FF FF FF FF FF FF FF – FF FF FF FF FF FF FF FF …………
2000:0110 FF .

Destination:
View es:0100 0110
3000:0100 00 00 00 00 00 00 00 00 – 00 00 00 00 00 00 00 00 …………
3000:0110 00 -

After block transfer:


Source:
View ds:0100 0110
2000:0100 FF FF FF FF FF FF FF FF – FF FF FF FF FF FF FF FF …………
2000:0110 FF -

Destination:
View es:0100 0110
3000:0100 FF FF FF FF FF FF FF FF – FF FF FF FF FF FF FF FF …………
3000:0110 00 -

Exercise:

1. Transfer 10 words from location 32000H to 21000H.


2. Transfer 10 words from location 32000H to 31200H using register relative addressing
mode.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 7


Exp 2: Multiplication and Division

2 MULTIPLICATION AND DIVISION

Aim: Assembly Language program to perform multiplication and division on the given
signed numbers.

Equipment required:
1. A PC with
a. Emu 8086 Installed
Program:

DATA SEGMENT ;start of data segment


OPR1 DW 4349H ;number 1
OPR2 DW 1298H ;number 2
PROD DW 2 DUP(?) ; Memory for result of multiplication
QUO DW ? ; Memory for result of division
REM DW ? ;end of data segment
DATA ENDS

CODE SEGMENT ;start of code segment


ASSUME CS:CODE, DS:DATA ;define segments
START: MOV AX,DATA ;define data for the code
MOV DS,AX

;MULTIPLICATION
MOV AX, OPR1 ;copy the first number in AX
MOV BX, OPR2 ;copy the second number in BX
IMUL BX ;multiply the contents of AX and BX
MOV PROD, AX ;save the lower word of result
MOV [PROD+2], DX ;save the higher word of result

;DIVISION
MOV AX, OPR1 ;copy the first operand in AX
CWD ;convert word in AX to double word
; i.e., DX =0, hence becomes DX:AX
IDIV BX ;divide the contents of DX:AX by BX
MOV QUO, AX ;save the Quotient
MOV REM, DX ;save the Remainder
HLT ;Exit to DOS mode
CODE ENDS ;End of code segment
END START ;End Program

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 8


Exp 2: Multiplication and Division

Flowchart:

START

AX OPR1
BX OPR2

AX OPR1
AX AX * BX

PROD AX
[PROD+2] DX

AX OPR1
AX DX: AX / BX

QUO AX
REM DX

STOP

Result:
Data Input:
OPR1 = 4349H
OPR2 = 1298H
Expected Output:
PROD = 4E31558H
QUO (QUOTIENT) = 3H
REM (REMAINDER) = B81H
View Memory contents
Before execution:
View ds:0000 000B
0B52:0000 49 43 98 12 00 00 00 00 – 00 00 00 00

After execution:
View ds:0000 000B
0B52:0000 49 43 98 12 58 15 E3 04 – 03 00 81 0B

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 9


Exp 2: Multiplication and Division

Exercise:
1. Write an ALP
a. To perform Multiplication and division on the given set of unsigned operands.
i. opr1 =7698H, opr2 =1234H
ii. opr1 =1234H, opr2 =7698H
iii. opr1 =9182H, opr2 =189H
iv. opr1 =6FH, opr2 =24H
v. opr1 =B4H, opr2= 19H and comment on the result.
b. To perform
i. -21 x 4
ii. -21 x -4
iii. -3/2
iv. 3/-2.
v. -3/-2 and comment on the result.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 10


Exp 3 (a): Single and Multi Byte Binary Addition

3 (a). SINGLE AND MULTI BYTE BINARY ADDITION AND SUBTRACTION

Aim: Assembly Language program to perform binary addition and subtraction on the given
numbers.

Equipment required:
1. IBM PC with
a. Emu 8086 Installed

Program:

DATA SEGMEN ;start of data segment


T
NUM1 DB 0E8H ;Number 1
NUM2 DB 43H ;Number 2
SUM DB 0 ;memory for result of summation
CARRY DB 0
DIFF DB 0 ;memory for result of subtraction
BORROW DB 0
DATA ENDS ;end of data segment

CODE SEGMEN ;start of code segment


T
ASSUME CS:CODE,DS:DATA ;define segments
START MOV AX, DATA ;define data for the code
:
MOV DS,AX
;ADDITION
MOV AL, NUM1 ;get the first number
ADD AL, NUM2 ;add second number to first number
MOV SUM, AL ;store the result of addition
JNC NEXT ;check the carry flag
INC BYTE PTR CARRY ;increment carry if CF is se

;SUBTRACTION
NEXT: MOV AL, NUM1 ;get the first number
SUB AL, NUM2 ;subtract the second number from the first
MOV DIFF, AL ;store the result of subtraction
JNC NEXT1
DEC BYTE PTR BORROW ;decrement borrow if CF is set
NEXT1 HLT ;Exit to DOS mode
:
CODE ENDS ;code segment ends here
END START ;end of the program

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 11


Exp 3 (a): Single and Multi Byte Binary Addition

Flowchart:

START

AL NUM1

AL AL+ NUM2

SUM AL

NO (CF=1)?

YES
CARRY CARRY +1

AL NUM1

AL AL – NUM2

DIFF AL

NO (CF=1)?

YES
BORROW BORROW – 1

STOP

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 12


Exp 3 (a): Single and Multi Byte Binary Addition

Result:
Data Input:
Num1 = E8H
Num2 = 43H
Expected Output:
Sum = 2BH
Carry =1
Diff = A5H
Borrow =0

View Memory contents


Before execution:
View ds:0 5
0B52:0000 E8 43 00 00 00 00

After execution:
View ds:0 5
0B52:0000 E8 43 2B 01 A5 00

Exercise:
1. Write an ALP
a. To perform addition and subtraction on the given set of numbers.
i. NUM1 = B4H, NUM2 = 19H
ii. NUM1 = D182H, NUM2 = 179H
Observe the flag status.
2. Write an ALP
a. To find the result of (P+(Q*R)/S-T, If P=5, Q=-1,R=3, S=2, T=1.
b. To find GCD of two given numbers.
c. To find LCM of two given numbers.
d. To find Celsius for the given Fahrenheit temperature.
e. To perform addition, subtraction of the numbers E2ABC198H and
931EF125H.
f. To perform the addition of the following binary numbers, Result should also
be in binary.
5AH, 46H, 89H, 27H, 22H, ABH,D7H,87H,FH,19H.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 13


Exp 3 (b): Single and Multi Byte BCD Addition and Subtraction

3(b). SINGLE AND MULTI BYTE BCD ADDITION AND SUBTRACTION

Aim: Assembly Language program to perform BCD addition and subtraction on the given
BCD numbers.

Equipment required:
1. IBM PC with
a. Emu 8086 Installed
Program:
DATA SEGMENT ;start of data segment
NUM1 DB 98H ;BCD Number 1
NUM2 DB 43H ;BCD Number 2
SUM DB 0 ;memory for result of BCD summation
CARRY DB 0
DIFF DB 0 ;memory for result of BCD subtraction
BORROW DB 0
DATA ENDS ;end of data segment

CODE SEGMENT ;start of code segment


ASSUME CS:CODE, DS: DATA ;define segments
START: MOV AX, DATA ;define data for the code
MOV DS, AX
;ADDITION
MOV AL, NUM1 ;get the first number
ADD AL, NUM2 ;add second number to first number
DAA ; Decimal Adjust after Addition
MOV SUM, AL ; store the result of addition
JNC NEXT ;check the carry flag
INC BYTE PTR CARRY ;increment carry if CF is set
;SUBTRACTION
NEXT: MOV AL, NUM1 ; get the first number
SUB AL, NUM2 ;subtract the second number from the
first
DAS ;Decimal Adjust after Subtraction
MOV DIFF, AL ; store the result of subtraction
JNC NEXT1
DEC BYTE PTR BORROW ; decrement borrow if CF is set
NEXT1: HLT ; break point interrupt
CODE ENDS ; code segment ends here
END START ; end of the program

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 14


Exp 3 (b): Single and Multi Byte BCD Addition and Subtraction

Flowchart:
START

AL NUM1
AL AL+ NUM2

DECIMAL ADJUST
AFTER ADDITION

SUM AL

NO (CF=1)?

YES

CARRY CARRY +1

AL NUM1
AL AL – NUM2

DECIMAL ADJUST
AFTER SUBTRACTION

DIFF AL

NO (CF=1)?

YES
BORROW BORROW – 1

STOP

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 15


Exp 3 (b): Single and Multi Byte BCD Addition and Subtraction

Result:
Data Input:
NUM1 = 98
NUM2 = 43
Expected Output:
SUM = 41
CARRY =1
DIFF = 55
BORROW =0

View Memory contents


Before execution:
View ds:0 5
0B52:0000 98 43 00 00 00 00

After execution:
- ds:0 5 98 43 41 01 55 00

Exercise:
1. Write an ALP
a. To perform addition and subtraction on the given set of numbers.
i. Num1 =89, Num2= 14
ii. Num1 =88, Num2 = 98
iii. Num1 =347834, Num2 = 189754
b. To perform addition of the following BCD numbers.
89, 80, 9, 27, 73, 45, 67, 36

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 16


Exp 4: Code Conversion

4. CODE CONVERSION

Aim: Assembly Language program to perform the code conversion from BCD to 7-segment.
Equipment required:
1. IBM PC with
a. Emu 8086 Installed
Look – up table for BCD to 7-segment:

7-segments
Decima
BCD 7-segmant d 7-segment
l
code Display p g f e d c b a code (hex)

0 0000 0 0 1 1 1 1 1 1 3F

1 0001 0 0 0 0 0 1 1 0 06

2 0010 0 1 0 1 1 0 1 1 5B

3 0011 0 1 0 0 1 1 1 1 4F

4 0100 0 1 1 0 0 1 1 0 66

5 0101 0 1 1 0 1 1 0 1 6D

6 0110 0 1 1 1 1 1 0 1 7D

7 0111 0 0 1 0 0 1 1 1 27

8 1000 0 1 1 1 1 1 1 1 7F

9 1001 0 1 1 0 1 1 1 1 6F

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 17


Exp 4: Code Conversion

Program:

DATA1 SEGMENT ;start of data segment


CODELIST DB 3FH,06H,5BH,4FH,66H, ;look – up table for BCD to ; 7-
6DH,7DH,27H,7FH,6FH segment code conversion
CHAR DB 5 ;BCD input
CODEC DB ? ; memory for 7-segment code output
DATA1 ENDS ;data segment ends here

CODE SEGMENT ;start of code segment


ASSUME DS: DATA1, CS: CODE
START: MOV AX, DATA1 ;define data for this code segment
MOV DS, AX
LEA BX, CODELIST ;store the offset address of lookup table
MOV AL, CHAR ;take the BCD code input
XLAT ;translate
MOV CODEC, AL ;Save the7-segment code output
HLT ;Break point interrupt
CODE ENDS ;end of code segment
END START ;end of program

Flowchart:

START

BX OFFSET CODELIST
AL CHAR (BCD code)

XLAT (Translate)
(AL [AL+BX])

CODEC AL
(7-segment code)

STOP

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 18


Exp 4: Code Conversion

Result:

Data Input:
BCD input = 05
Expected Output:
7-segment output = 6DH

View Memory contents


Before execution:
View ds:0000 000b
0B56:0000 3F 06 5B 4F 66 6D 7D 27 – 7F 6F 05 00

After execution:
View ds:0000 000b
0B56:0000 3F 06 5B 4F 66 6D 7D 27 – 7F 6F 05 6D
Exercise:

1. Write an ALP
a. To perform Binary to gray code conversion.
b. To perform Binary to ASCII code conversion.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 19


Exp 5(a): Searching For a Character in a String

5(a). SEARCHING FOR A CHARACTER IN A STRING

Aim: Assembly Language program to search for a character in the given string.

Equipment required:
1. IBM PC with
a. Emu 8086 Installed
Program:

DATA SEGMENT ;data segment starts here


BYTE1 EQU 'P' ;character to be searched
STRING DB ;given string
'MICROPROCESSOR8086'
COUNT EQU ($-STRING) ;length of the given string
DATA ENDS ;end of data segment

CODE SEGMENT ;code segment starts here


ASSUME DS:DATA, CS:CODE ;define physical segments
START: MOV AX, DATA ;define data for this code
MOV DS, AX
MOV ES, AX ;initialize string segment addr.
MOV DI, OFFSET STRING ;and offset address
MOV CX, COUNT ;count decides number of searches
MOV BX, 0 ;Bx = match position
MOV AL, BYTE1
CLD ;auto increment mode
SCAN1: NOP
REPNE SCASB ;scan string ES:DI for byte in AL
; ZF will set if character found
JNZ EXIT0
MOV BX, DI ; copy the final match position to BX reg

EXIT0: HLT ; return to DOS


CODE ENDS ;code segment ends here
END START ;end of program

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 20


Exp 5(a): Searching For a Character in a String

Flowchart:

START

CX COUNT
DI OFFSET STRING
BX 0
AL BYTE1

CLEAR DIRECTION FLAG


(Says auto increment mode)

SCAN STRING POINTED BY


ES: DI FOR THE BYTE IN AL
YES

(ZF=1)? NO

DI DI +1
DI DI +1 CX CX – 1

(CX =0)? NO

YES
(ZF =1)? NO

YES

BX DI

STOP

Result:

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 21


Exp 5(a): Searching For a Character in a String

View Register contents.


Given string: MICROPROCESSOR

Character to be
Position (HEX)
searched
AL BX
'c' 3
'M' 1
'r' 4
'6' 12
'a' 0

Observation: If BX =0 indicates that no such character found in the


given string.
BX ≠ 0 indicates the position of the character in the
given string.

Exercise:
1. Write an ALP
a. To count the number of times that the letter ‘S’ is present in the string
‘MICROPROCESSORS’.
b. To delete the character ‘S’ in the given string ‘MICROPROCESSORS’.
c. To replace the character ‘S’ by ‘$’ in the given string
‘MICROPROCESSORS’.
d. To find the number of times that the string “he” occurs in the string “He was
playing in the garden” and also the position at which it occurs.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 22


Exp 5(b): Sorting given set of numbers

5(b). SORTING GIVEN SET OF NUMBERS

Aim: Assembly Language program to sort the given set of unsigned numbers in ascending
order.

Equipment required:
1. IBM PC with
a. Emu 8086 Installed

Program:

DATA SEGMENT ;start of data segment


LIST DB 54, 47, 38H, 26, 46H, 87, ;array of no.s
88, 45, 76H, 55, 87H, 45H
COUNT EQU $-LIST ;number of bytes to be sort
DATA ENDS ;end of data segment

CODE SEGMENT ;start of code segment


ASSUME CS: CODE, DS:DATA ;define segments
START: MOV AX, DATA ;define data for the code
MOV DS, AX
MOV DX, COUNT-1
REPEAT: MOV SI, OFFSET LIST ;copy offset address of list in SI reg.
MOV CX, DX ;initialize count register
AGAIN: MOV AL, [SI] ;copy first byte in AL
CMP AL, [SI+1] ;compare it with next byte in the list
JC NEXT ;jump to next if carry exists
XCHG AL, [SI+1]
XCHG AL, [SI] ;else replace AL with present max no
NEXT: INC SI ;Increment SI
LOOP AGAIN ;decrement count
DEC DX ;jump if non zero to address repeat
JNZ REPEAT
HLT ;Exit to DOS mode
CODE ENDS ;End of code segment
END START ;End Program

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 23


Exp 5(b): Sorting given set of numbers

Flowchart:

START

DX COUNT-1

SI OFFSET LIST
CX DX

AL [SI]
COMPARE AL AND [SI+1]

(CF = 1)?
YES

EXCHANGE AL AND
[SI+1]NO

SI SI + 1
CX CX – 1

(ZF = 1)? NO

YES

DX DX – 1

NO (ZF = 1)?

YES

STOP

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 24


Exp 5(b): Sorting given set of numbers

Result:

Data Input:
Given unordered numbers:
36H, 2FH, 38H, 1AH, 46H, 57H, 58H, 2DH, 76H, 37H, 87H, 45H
Expected Output:
Ascending order:
1AH, 2DH, 2FH, 36H, 37H, 38H, 45H, 46H, 57H, 58H, 76H, 87H

View Memory contents


Before execution:
View ds:0000 000b
0B56:0000 36 2F 38 1A 46 57 58 2D – 76 37 87 45

After execution:
View ds:0000 000b
0B56:0000 1A 2D 2F 36 37 38 45 46 – 57 58 76 87

Exercise:
1. Write an ALP
a. To sort the given set of unsigned numbers in descending order.
b. To sort the given set of signed numbers in ascending order.
c. To sort the given set of signed numbers in descending order.
d. To sort the word ‘MICROPROCESSOR8086’
i. In Ascending order
ii. In descending order

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 25


Exp 6: Interfacing Traffic Signal Control

6. INTERFACING TRAFFIC SIGNAL CONTROL

AIM: Program to interface traffic light controller using 8086

HARDWARE:

1. IBM PC with
a. Emu 8086 Installed

DESCRIPTION:

The emu8086 has virtual traffic lights shown in below figure. There are 12 LEDs
arranged in a 'X' junction form. These 12 LEDs are interface to 8086 in IO Mapped method at
an address 0004H of 16bits (of which most significant 4 bits are unused).
Out of 12 LEDs,
3 are Red LEDs corresponds to bit positions 0,3,6 and 9;
3 are Yellow LEDs corresponds to bit positions 1,4,7 and A;
3 are Green LEDs corresponds to bit positions 2,5,8 and B;

INTERFACE DIAGRAM

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 26


Exp 6: Interfacing Traffic Signal Control

PROGRAM:

CODE SEGMENT ;start of code segment


ASSUME CS: CODE ;define segments
START: MOV DX, 0004H ;load port address in dx(variable
Addressing mode)
MOV AX,0249H ;All red LEDs are on
OUT DX, AX
CALL DELAY ;Execute delay routine
MOV AX, 0492H ;all Yellow LEDs are on
OUT DX, AX
CALL DELAY ;Execute delay routine
MOV AX, 0924H ;all Green LEDs are on
OUT DX, AX
JMP START
; Delay routine
DELAY:
MOV CX, 0FFFFH ; Initialize count
AGAIN: DEC CX ; decrement count by 1
JNZ AGAIN ; repeat till count become zero
RET

HLT ;Exit to DOS mode


CODE ENDS ;End of code segment
END START ;End Program

RESULT:

Observe the LED changes.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 27


Exp 6: Interfacing Traffic Signal Control

FLOWCHART:

START

GLOW ALL
RED LEDS

CALL DELAY

GLOW ALL
YELLOW LEDS

CALL DELAY

GLOW ALL
GREEN LEDS

CALL DELAY

Assignment:

1. Write an ALP

a. To control the traffic at the given junction.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 28


Exp 7(a): Introduction to 8051 Compiler

7. INTRODUCTION TO 8051 COMPILER (KEILΜVISION4)

µVision4 is an IDE (Integrated Development Environment) that helps you write,


compile, and debug embedded programs. It encapsulates the following components:

 Multiple Monitor - flexible window management system.


 System Viewer - display device peripheral register information.
 Debug Views - create and save multiple debug window layouts.
 Multi-Project Workspace - simplify working with numerous projects.
 Source and Disassembly Linking - the Disassembly Window and Source Windows
are fully synchronized making program debugging and cursor navigation easier.
 Memory Window Freeze - store the current Memory Window view allowing easy
comparison of memory contents at different points in time.
 Device Simulation has been updated to support many new devices such as Infineon
XC88x, SiLABS C8051Fxx, Atmel SAM7/9, and Cortex-M3 MCUs from Luminary,
NXP, and Toshiba.
 Support for Hardware debug adapters added including ADI miDAS-Link, Atmel
SAM-ICE, Infineon DAS, and ST-Link.
 New Data and Instruction Trace capabilities for ARM and Cortex MCUs.
 XML based Project Files - create, view and modify projects as easily readable XML
text files.
 Serial Window - extended to provide a basic VT-100 terminal, ASCII Mode, Mixed
Mode, and Hex Mode views.
 Watchpoints and Logic Analyzer variables are now easier to set.

Building an Application in µVision4

To build (compile, assemble, and link) an application in µVision4, you must:

1. Select Project - Open Project.


2. If loading a µVision3 project, change the file filter in the Select Project File dialog to
Previous Project Files (*.uv2; *.uv3; *.mpw).
3. Select the project to load (for
example, \ARM\EXAMPLES\MEASURE\MEASURE.UV2).
4. Select Project - Rebuild all target files or Build target.

µVision4 compiles, assembles, and links the files in your project.

Debugging an Application in µVision4

To debug an application created using µVision4, you must:

1. Select Debug - Start/Stop Debug Session.


2. Use the Step toolbar buttons to single-step through your program. You may enter G,
main in the Output Window to execute to the main C function.
3. Open the UART #2 Window using the Serial Windows - UART #2 button on the
toolbar.
4. Debug your program using standard options like Step, Go, Break, and so on.

Creating Your Own Application in µVision4

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 29


Exp 7(a): Introduction to 8051 Compiler

To create a new project in µVision4, you must:

1. Select Project - New Project.


2. Select a directory and enter the name of the project file.
3. Select Project - Select Device and select an ARM, 8051, 251, or C16x/ST10 device
from the Device Database™.
4. Create source files to add to the project.
5. Select Project - Targets, Groups, Files. Add/Files, select Source Group1, and add the
source files to the project.
6. Select Project - Options and set the tool options. Note when you select the target
device from the Device Database™ all special options are set automatically. You
typically only need to configure the memory map of your target hardware. Default
memory model settings are optimal for most applications.
7. Select Project - Rebuild all target files or Build target.

Programming Software - Proload

89Sxx In-Circuit Serial Programmer

1. Overview
Using this programmer with your application board will enable you to program AT89Sxx
based microcontrollers In-circuit. You shall not need of any external programmer or do not
need to remove the chip from your hardware to update its firmware (embedded system
software inside microcontroller). The programmer communicates through a serial port to PC
which has “Proload” programming software installed. The process of reprogramming thus
becomes totally touch less. Proload software is used with this hardware to provide all the
necessary read, write, lock, and fuse functions.
2. Features

· Auto Execution of microcontroller program on successfully programming


· Powered from Target Board
· Atmel Standard 10 pin ICSP connector
· 5700 high speed communication
· Low Cost and Easy to Use
· Busy Indication LED

3. Supported Chips
· AT89S51
· AT89LS51
· AT89S52

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 30


Exp 7(a): Introduction to 8051 Compiler

· AT89LS52

4. Proload V5.2

· Select the hardware Model


· Select Com Port
· In Device Click on Device Select and select the Microcontroller under the given list
on which you are working with.
· In File Click on Browse and select your Test.hex file which was generated using
RIDE Compiler
· Click on the Check box - Reload file before programing
· Under commands select Auto Program and click on Auto program. The status of it
will be shown in status window.
· As and when program is loaded in MCU, it starts running. Output can be viewed
according to the program after giving the hardware connections.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 31


Exp 7(b): Addressing Modes

7 (b). ADDRESSING MODES

Aim: Program to copy the value 55H into RAM memory locations 30H to 35H using
a. Direct Addressing mode.
b. Register Indirect Addressing mode without a Loop.
c. Register Indirect Addressing mode with a Loop.

Hardware:

1. IBM PC with
a. Keil Compiler

Program:

a.
ORG 20C0H ; Start at location 20C0 (hex)
MOV A,#55H ; Load A with value 55H

MOV 30H,A ; Copy A to RAM location 30H


MOV 31H,A ; Copy A to RAM location 31H
MOV 32H,A ; Copy A to RAM location 32H
MOV 33H,A ; Copy A to RAM location 33H
MOV 34H,A ; Copy A to RAM location 34H
RET ; Return from the Program/ Subroutine

Flowchart:

START

A 55H

[30H] A
[31H] A
[32H] A
[33H] A
[34H] A

STOP

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 32


Exp 7(b): Addressing Modes

Program:

b.
ORG 20C0H ; Start at location 20C0 (hex)
MOV A,#55H ; Load A with value 55H
MOV R0,#30H ; Load the pointer. R0 = 40H

MOV @R0,A ; Copy A to RAM location R0 points to


INC R0 ; Increment pointer. Now R0 = 41H
MOV @R0,A ; Copy A to RAM location R0 points to
INC R0 ; Increment pointer. Now R0 = 42H
MOV @R0,A ; Copy A to RAM location R0 points to
INC R0 ; Increment pointer. Now R0 = 43H
MOV @R0,A ; Copy A to RAM location R0 points to
INC R0 ; Increment pointer. Now R0 = 44H
MOV @R0,A ; Copy A to RAM location R0 points to

RET ; Return from the Program/ Subroutine

Flowchart:

START

A 55H
R0 30H

[R0] A
R0 R0+1
[R0] A
R0 R0+1
[R0] A
R0 R0+1
[R0] A
R0 R0+1

STOP

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 33


Exp 7(b): Addressing Modes

Program:

c.
ORG 20C0H ; Start at location 20C0 (hex)
MOV A,#55H ; Load A with value 55H
MOV R0,#30H ; Load the pointer. R0 = 40H
MOV R2, #05 ; Load counter, R2 = 5

AGAIN: MOV @R0,A ; Copy A to RAM location R0 points to


INC R0 ; Increment R0 pointer
DJNZ R2,AGAIN ; Loop until counter = zero

RET ; Return from the Program/ Subroutine

Flowchart:

START

A 55H
R0 30H
R2 05

[R0] A
R0 R0+1

R2 R2-1

NO (R2=0)?

YES

STOP

Result:

View internal memory locations

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 34


Exp 8 : Timer/ Counter Applications

8. TIMER / COUNTER APPLICATIONS

Aim: Program to generate a square wave of frequency 100Hz on P2.3 pin using time delay.
Assume that XTAL = 11.0592 MHz.

Hardware:

1. IBM PC with
a. Keil Compiler

Program:

Polling method:

; SPECIAL FUNCTION REGISTER EQUATES


P2 EQU 0A0H
TMODEQU 89H
TL0 EQU 8AH
TH0 EQU 8CH
TR0 EQU 8CH
TF0 EQU 8DH

ORG 0 ; Start at location 0


CLR P2.3 ; Clear P2.3
MOV TMOD, #01H ; Timer 0, mode 1(16-bit mode)

HERE: MOV TL0, #0 ; TL0=0, the low byte


MOV TH0, #0EEH ; TH0=EEH, the high byte
SET TR0 ; Start the timer0

AGAIN: JNB TF0, AGAIN ; monitor flag 0, stay until timer rolls
over
CPL P2.3 ; complement P2.3 to get hi, lo
CLR TR0 ; stop the timer 0
CLR TF0 ; clear timer 0 flag for next round
SJMP HERE

END

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 35


Exp 8 : Timer/ Counter Applications

Interrupt method:

; SPECIAL FUNCTION REGISTER EQUATES


P2 EQU 0A0H
TMODEQU 89H
TL0 EQU 8AH
TH0 EQU 8CH
TR0 EQU 8CH
TF0 EQU 8DH
IE EQU 0A8H
ORG 0
LJMP MAIN ; by-pass interrupt vector table

;ISR for timer 0 to generate square wave


ORG 000BH ; Timer 0 interrupt vector table
CPL P2.3 ; Toggle P2.3 pin
MOV TL0, #0 ; load T0 low byte
MOV TH0, #0EEH ; load T0 high byte
RETI ; return form ISR

; The main program for initialization


ORG 0030H ; after vector table space
MAIN:MOV TMOD, #01H ; Timer 0, mode 1(16-bit mode)
MOV TL0, #0 ; TL0=0, the low byte
MOV TH0, #0EEH ; TH0=EEH, the high byte
MOV IE, #82H ; IE=10000010 (bin) enable timer 0
SETB TR0 ; start timer 0
HERE: SJMP HERE ; keep doing it
; loop unless interrupted by TF0
END

Result:

Connect 8051 pin P2.3 to Oscilloscope View square wave from in CRO.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 36


Exp 8 : Timer/ Counter Applications

Flowchart:

START

DECIDE TIMER AND MODE OF


OPERATION BY INITILIZING TMOD
REGISTER
TMOD 01H

CALUCULATE & INITIALIZE


TL0, TH0 FOR DELAY OF
5msec
TL0 0
TH0 EEH

START TIMER RUN


TR0 1

NO TF0 =1

YES
COMPLEMENT P2.3
P2.3 !P2.3

STOP TIMER RUN


TR0 0

CLEAR TF0
TF 0

10.

CBIT (Autonomous) – ECE – MICROPROCESSOR AND MICROCONTROLLER LAB MANUAL Page 37


Exp 9: Interfacing Applications using LEDs, Switches, Relay and Buzzer

9.a. INTERFACING AN LIGHT EMITTING DIODE (LED)

Aim: Interfacing an LED with a 8051 micro controller

Hardware:
1. AT89S51
2. LED
3. 500 ohms & 1k Resistor’s
4. SL100 Transistor

Circuit Diagram:

Fundamentals:
A current limiting resistor in series
should always be included in the circuit to protect not only the LED, but also the driver circuitry from
high current flow.
Resistance value is calculated as follows:
According to Ohm’s Law
V = IR
V = supply voltage = 5V

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL Page 38


Exp 9: Interfacing Applications using LEDs, Switches, Relay and Buzzer

I = required current= 10mA


R =?
R = V/I = 5/(10*10-3) = 500 ohms

About the Circuit:


In this circuit Transistor works as switch. LED is connected through a Resistor (500Ωohms).
Micro controller port pin sources current to drive the Transistor.
Generally
Logic high = 1
Logic low = 0

By making P1.0 High, Transistor is ON, LED can turn ON.


By making P1.0 Low, Transistor is OFF, LED can turn OFF.

To blink an LED with 50% duty cycle continuously; The time delay between ON and OFF state should
be equal.

Need of Time delay:

For better view of ON and OFF states, there is a need to implement minimum time delay of 100 ms.
Between ON and OFF states.

Port Map:

P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0


X X X X X X X LED

Flow Chart:

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL Page 39


Exp 9: Interfacing Applications using LEDs, Switches, Relay and Buzzer

START

CONNECT PORT 1.0 OF 8051


TO LED LEG

P1.0 = HIGH
TRANSISTOR ON
(LED ON)

DELAY = 1000 ms

P1.0 = LOW
TRANSISTOR OFF
(LED OFF)

DELAY = 1000 ms

STOP

Program:
/****Program to interface a LED with a 8051 micro controller***/

#include<reg51.h>
void delay_ms(unsigned int);
sbit LED = P1^0; /*equating P1^0 pin to a constant(LED)*/

void main(void)
{
P1= 0x00;
while(1)

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL Page 40


Exp 9: Interfacing Applications using LEDs, Switches, Relay and Buzzer

{
LED = 1;
delay_ms(1000);
LED = 0;
delay_ms(1000);
}
}
//generates delay in milli seconds
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++);
}
}
Result:
Observe the LED’s status.

Exercise:
1. Write a C Program to generate the given pattern by interfacing 8 LEDs to 8051.
a. Blink all LEDs at a frequency of 1Hz.
b. Blink alternate LEDs at a frequency of 2Hz.
(Hint: use #define LED P1 to equate P1 port to a constant (LEDS)*/

9.b. INTERFACING A SWITCH AND AN LED

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL Page 41


Exp 9: Interfacing Applications using LEDs, Switches, Relay and Buzzer

Aim: Interfacing a Switch & LED with a 8051 micro controller


Hardware:
1. AT89S51
2. Resistor
3. Transistor
4. LED
5. Switch (push button switch)
Circuit Diagram:

AT89S51

Fundamentals:
Switch: A device, which opens or closes the circuit.
Switch State: Port Pin status
ON (close) = Logic high
OFF (open) = Logic low
What will happen if resistor (1OK) is not present?

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL Page 42


Exp 9: Interfacing Applications using LEDs, Switches, Relay and Buzzer

Anytime you press the switch, P1.0 is directly connected to ground. P1.0 would try to deliver a
+5 logic level through a direct short to ground. It may cause damage to the internal circuitry of
micro controller.

About Circuit:
Fig1: Normal position of the switch is open. In this case logic high = 1 is port pin status. When
switch is pushed, P1.0 is connected to ground resulting logic low = 0 on port pin.

Fig2: Normal position of the switch is open. In this case logic low = 0 is port pin status. When
switch is pushed, P1.0 is connected to Vcc resulting logic high = 1 on port pin.
Need of delay: Switches suffer from a condition known as switch bounce. When switch is
closed at first, it won’t provide permanent connection instantaneously. It results in multiple logic
level transitions on port pin. If micro controller checks the port pin at this instance it may not get
a true current state of the switch.

DO NOT TRY TO CONNECT THE CIRCUITS IN THE FOLLOWING MANNER.

Fig.1 Fig.2

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL Page 43


Exp 9: Interfacing Applications using LEDs, Switches, Relay and Buzzer

The circuits also can be connected in the following way.


Fig. 3 Fig. 4

1) When the switch is closed, the port pin gets shorted to the Vcc directly. It causes the damage
to the circuit.
2) When the switch is closed, the port pin gets shorted to the ground. It causes the damage to the
circuit.
3) It is an open circuit. P1.0 will be in the toggle state. So, the output will not be reliable.
4) Same for fig. 4.

Port Map:

P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0


X X X X X X X LED

P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0


X X X X X X X SWITC
H

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL Page 44


Exp 9: Interfacing Applications using LEDs, Switches, Relay and Buzzer

Flowchart:

START

CONNECT P2.0 TO LED


AND P1.0 TO SWITCH

NO (SW=0)?

YES

COMPLEMENT
P2.0

DELAY

STOP

Program:
/*********Program to interface a led and a switch*********/
#include<reg51.h>
#include<delay.h>

sbit LED = P2^0; /*equating P2^0 pin to a constant(LED)*/


sbit SWITCH = P1^0; /*equating P1^0 pin to a constant(SWITCH)*/

void main(void)
{
LED = 0;
while (1) /*toggling a switch results in a led coming on and off*/
{

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL Page 45


Exp 9: Interfacing Applications using LEDs, Switches, Relay and Buzzer

if ( SWITCH == 0)
{
LED = 1 – LED;
delay(200);
}
}
}

Result:
Observe the LED status when the switch toggles.

Exercise:
1. Write a C Program to Interface Switch and LED using an Interrupt.
2. Interface a LED in such a way that it should be ON only when the switch is closed. When
the switch is open LED should be OFF.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL Page 46


Exp 9: Interface applications using LED, Switch, Relay and Buzzer

9.c. INTERFACING A RELAY


Aim: Interfacing a Relay with a bulb
Hardware:
1. AT89S51
2. Relay
3. Bulb
4. Diode(IN 4001)
5. Transistor(2N222)
6. Resistor(IK)

Fundamentals:

LS1

5
3
4
1
2

Relay internal circuit


Mechanical relays come in wide variety of shapes, sizes, configurations and ratings.
However, they all operate on the same basic principle, which is to operate a set of contacts by
energizing an electromagnetic coil. By passing electric current through coil these mechanical
contacts “open” and/or “close” associates circuits.

Usually a transistor is used whenever it is connected to a microcontroller. A transistor


requires only a small base current to let a much large current flow through its collector. This
makes it ideal to control relays from the I/O pins of the microcontroller.

Also by using a transistor to provide a switching, any high voltage is isolated from low
voltage digital circuit that the micro controller operates in.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 47
Exp 9: Interface applications using LED, Switch, Relay and Buzzer

Circuit Diagram:

About Circuit: - This circuit uses transistor as the switching device.

A logic high signal on port pin P2.0 cases the transistor to conduct and sink the relay to
ground. The magnetic field energizes, and relay contacts to activate. (Relay is closed).

A logic signal on port pin P2.0 cases the transistor to push into OFF state. Hence there is no
current flow from collector to ground; the relay will be in OFF state.

Whenever relay comes from ON state to OFF state, the coil generates a reverse voltage spike
due to the collapsing magnetic field around it. This voltage can destroy the transistor. Hence,
some protection is needed for transistor. This is the reason behind the diode being connected
across the relay coil. When the high voltage is produced, the diode conducts and shunts this
voltage back through the relay coil.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 48
Exp 9: Interface applications using LED, Switch, Relay and Buzzer

Flow Chart:

START

CONNECT P0 TO RELAYS
AND P2 TO LEDS

MOVE 15H ON PORT 0

DELAY

MOVE 2AH ON PORT 0

DELAY

MOVE 80H ON PORT 0

DELAY

STOP

Port Map:
P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
X X RELAY RELAY RELAY RELAY RELAY RELAY

P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0


X X LED LED LED LED LED LED

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 49
Exp 9: Interface applications using LED, Switch, Relay and Buzzer

Program:
/******Program for interfacing a relay with a bulb******/

#include<reg51.h> //include at89c51 microcontroller header file


#define relay P0 //connect P0 to relay
#define led P2 //connect P2 to leds
void delay_ms(unsigned int);

void main(void)
{
while(1) //infinite loop
{
relay=0x15; //relay1, 3, 5 are on
led=0x15; //led1, 3, 5 are on
delay_ms(1000); //delay 1000 milli seconds

relay=0x2A; //relay2, 4, 6 are on


led=0x2A; //led2, 4, 6 are on
delay_ms(1000); //delay 1000 milli seconds
}
}
/*generates delay in milli seconds*/
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
for(j=0;j<500;j++);
}
Result:
Observe the Relay position change.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 50
Exp 9: Interface applications using LED, Switch, Relay and Buzzer

9.d. INTERFACING A BUZZER

Aim: Interfacing a Buzzer with a 8051 microcontroller


Hardware:
1. AT89c51
2. Buzzer
3. Transistor(2N222)
4. Resistor(1K)
Circuit Diagram:
VCC

1
B1
BUZZER
2

R1
3

P0.0 2 Q1A
SL100
330 ohms
1

AT89c51

Port Map :
P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P1.0
X X X X X X X BUZZE
R

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 51
Exp 9: Interface applications using LED, Switch, Relay and Buzzer

Program:
/******program for interfacing a buzzer with 8051 microcontroller****/
#include<reg51.h>
#include<spectro_delay.h>
sbit BUZZER = P1^0;
void main(void)
{
BUZZER = 0;
while(1)
{
BUZZER = 1;
delay(1000);
BUZZER = 0;
delay(1000);
}
}
Flowchart:
START

CONNECT PORT 1.0 OF


8051 TO LED LEG

P1.0 = HIGH
(BUZZER IS ON)

DELAY = 1000

P1.0 = LOW
(BUZZER IS OFF)

DELAY = 1000 ms
CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL
Page 52
STOP
Exp 9: Interface applications using LED, Switch, Relay and Buzzer

Result:
Observe the sound coming from Buzzer.

Exercise:
1. Interface 6 relays and one buzzer to 8051; and write a program to on the buzzer when
6th relay is on.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 53
Exp 9: Interface applications using LED, Switch, Relay and Buzzer

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 54
Exp 10: Interfacing ADC

10. INTERFACING ADC


Aim: Interfacing ADC-0808.
Hardware:
1. ATC89c51
2. ADC-0808
Circuit diagram:

Fundamentals:
The ADC0808 data acquisition component is a monolithic CMOS device with an 8 bit
Analog –to –Digital converter 8 channel multiplexer & microprocessor compatible control
logic. The 8 bit A/D converter uses successive approximation as the conversion technique.
The converter features a high impedance chopper stabilized comparator, a 256R voltage
divider with analog switch tree and a successive approximation register. The 8 channel
multiplexer can directly access any of 8 –single-ended analog signals. Easy interfacing to
microprocessor is provided by the latched & decoded multiplexer address input as latched
TTL TRI-STATE outputs.
The ADC0808 offers high speed, high accuracy minimal temperature dependence,
excellent long-term accuracy & repeatability & consumes minimal power.
Features:
 Easy interface to all microprocessors
 Operates ratio metrically or with 5V DC or analog span adjusted voltage reference.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 55
Exp 10: Interfacing ADC

 No zero or full scale adjusts required.


 8-channel multiplexer with address logic.
 0V to 5V input range with single 5V power supply.
 Outputs meet TTL voltage level specifications.
 Molded 28-pin DIP package.
Key Specifications
 Resolution 8 bits
 Total unadjusted Error +/- ½ LSB & +/- 1 LSB
 Single Supply 5V DC
 Low Power 15 mW
 Conversion time 100 usec
Functional Description
Multiplexer: The device contains an 8-channel single-ended analog signal multiplexer. A
particular I/P channel is selected by using the address decoder. Below table shows the I/P
states for the address lines to select any channel. The address is latched into the decoder on
the low to high transition of the address latch enable signal.

Table:
Address Lines

SELECTED ANALOG CHANNEL C B A

IN0 L L L
IN1 L L H
IN2 L H L
IN3 L H H
IN4 H L L
IN5 H L H
IN6 H H L
IN7 H H H
Converter Characteristics:
The Converter

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 56
Exp 10: Interfacing ADC

The heart of this single chip data acquisition system is its 8-bit analog-to-digital
converter. The converter is designed to give fast, accurate & repeatable conversions over a
wide range of temperatures.

Functional Description:
The A/D converter’s successive approximation register (SAR) is reset on the positive
edge of the start conversion (SC) pulse. The conversion begins on falling edge of the start
conversion pulse. The continuous conversion may be accomplished by tying the end-of-
conversion (EOC) output to the SC input. If used in this mode an external start conversion
pulse should be applied after power up. End-of-conversion will go low between 0 & 8 clock
pulses after the rising edge of start conversion. The most important section of A/D converter
is the comparator. It is this section which is responsible for the ultimate accuracy of the entire
converter. It is also the comparator drift which has the greatest influence on the repeatability
of the device. A chopper stabilized comparator provides the most effective method of
satisfying all converter requirements.

Pin diagram:

IN0-IN7 - Analog Input Channels.


ADD A,ADD B,ADD C -Address Lines
EOC -End of Conversion
D7,D6,D5,D4,D3,D2,D1,D0

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 57
Exp 10: Interfacing ADC

(2-1,2-2,2-3,2-4,2-5,2-6,2-7,2-8) -Data Lines


VREF (+) - Positive Reference Voltage
VREF (-) - Negative Reference Voltage
In this experiment Reference voltage supplied is 4V.
Flowchart:

START

SELECT CHANNEL IN0 BY MAKING


A2,A1,A0 PINS 0,0,0 LATCH IT USING ALE

START CONVERSION

(EOC = 1)? NO

YES
DISPLAY ADC DATA
ON LCD

RETURN

PORT MAP FOR INTERFACING ADC 0808

P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0


D7 D6 D5 D4 D3 D2 D1 D0

P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0


X X EOC ALE START A2 A1 A0

P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0


D7 D6 D5 D4 X X EN RS

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 58
Exp 10: Interfacing ADC

Program:
//program to implement analog to digital conversion using ADC0808

#include<reg51.h>
#define LCD P2
#define ADC P0 //acquires analog to digital converted data

sbit A0=P1^0; //A0 A1 & A2 are analog input channel selection bits
sbit A1=P1^1;
sbit A2=P1^2;
sbit START=P1^3; //start conversion bit
sbit ALE=P1^4; //Select channel according to A0 A1& A2
sbit EOC=P1^5; //end of conversion bit

#define VREF 4.96 //set voltage reference


#define MAX_RES 0xff //set maximum resolution of ADC0808 (8bit)

void init_lcd(void);
void cmd_lcd(unsigned char);
void write_lcd(unsigned char);
void display_lcd(unsigned char *);
void integer_lcd(int);
void float_lcd(float);
void delay_ms(unsigned int);

void main(void)
{
init_lcd();
ALE =0;

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 59
Exp 10: Interfacing ADC

A0=0; //set channel 0


A1=0;
A2=0;
ALE=0;
START=0;
display_lcd("Data Acqisition");
while(1)
{
cmd_lcd(0xc0);
START=1; //start conversion
ALE=0; //select channel
START=0;
while(EOC==0); //wait till end of conversion
float_lcd((VREF*ADC)/MAX_RES); //converting back to voltage
display_lcd(" volts");
delay_ms(1000);
}
}

void init_lcd(void)
{
delay_ms(10);
cmd_lcd(0x28);
cmd_lcd(0x0e);
cmd_lcd(0x06);
cmd_lcd(0x01);
}

void cmd_lcd(unsigned char c)


{
unsigned char temp;
temp=c>>4;
LCD=temp<<4|0x02;

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 60
Exp 10: Interfacing ADC

LCD=0;
LCD=c<<4|0x02;
LCD=0;
delay_ms(2);
}

void write_lcd(unsigned char c)


{
unsigned char temp;
temp=c>>4;
LCD=temp<<4|0x03;
LCD=0;
LCD=c<<4|0x03;
LCD=0;
delay_ms(2);
}

void display_lcd(unsigned char *s)


{
while(*s)
write_lcd(*s++);
}

void integer_lcd(int n)
{
unsigned char c[6];
unsigned int i=0;
if(n<0)
{
write_lcd('-');
n=-n;
}
if(n==0)

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 61
Exp 10: Interfacing ADC

write_lcd('0');
while(n>0)
{
c[i++]=(n%10)+48;
n/=10;
}
while(i-->=1)
write_lcd(c[i]);
}

void float_lcd(float f)
{
int n;
float temp;
n=f;
integer_lcd(n);
write_lcd('.');
temp=f-n;
if(temp>=0.00&&temp<=0.09)
write_lcd('0');
f=temp*100;
n=f;
integer_lcd(n);
}

void delay_ms(unsigned int i)


{
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++);
}
}

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 62
Exp 10: Interfacing ADC

Result:
Connect POT between JP6.1 and JP6.4 and apply the outline of POT to IN0 of ADC0808.
Then vary the POT and observe the display on LCD.
(We can view amount of voltage that is applied to IN0)
Exercise:
1. Interface ADC0800 to 8051 and display the digital converted data in hex format after
applying analog input to it.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 63
Exp 11: Interfacing DAC

11. INTERFACING DAC


Aim: Interfacing of 8 bit DAC

Hardware: AT89c51
DAC0808

Circuit diagram:

Fundamentals:

The DAC-0808 series is an 8-bit monolithic digital to analog converter(DAC) featuring the a
full scale output current setting time of 150ns while dissipating only 33mw with +/-
5vsupplies.No reference current(Iref) trimming is required for most applications since the full
scale output current is typically +/-1LSB of 255 Iref/256. Relative accuracies of better than
+/-0.19% assure 8-bit monotonicity and linearity while zero level output current of less than
4ua provides zero accuracy for Iref >=2ma. The power supply contents of the DAC-0808
series are independent of bit codes, and exhibits essentially constant device characteristics
over the entire supply voltage range. The DAC-0808 will interface directly with popular
TTL,DTL or CMOS logic levels.

PIN DIAGRAM

NC 1 16
COMPENSATION
2 15
GND -VREF
3 14
VEE +VREF
4 13
IO DAC0808 VCC
5 12
MSB A1 A8 LSB
6 11
A2 A7
7 10
A3 A6
8 9
A4 A5

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 64
Exp 11: Interfacing DAC

FEATURES:

 Relative accuracy: +/-0.19% error maximum.


 Full scale current match.
 7 and 6-bit accuracy available
 Fast setting time:150ns typ.
 Non inverting digital inputs are TTL and CMOS compatible
 High speed multiplying input slew rate:8ma/us.
 Power supply voltage range:+/-4.5v to +/-18v.
 Low power consumtion:33mw @ +/-5v.

Reference Amplifier & Drive And Compensation

The reference amplifier provides a voltage at pin 14 for converting the reference voltage to a
current, and a turn around circuit or current mirror for feeding the ladder. The reference
amplifier input current, I14, must always flow into pin 14,regardless of the setup method or
reference voltage priority.Connections for a positive voltage are shown in fig 1. The
reference voltage source supplies the full current !14. for bipolar reference signals, as in the
multiplying mode,R15 can be tied to a negative voltage corresponding to the minimum input
level. It is possible to eliminate R15 with only a small sacrifice in accuracy and temperature
drift. The compensation capacitor value must be increased with increases in R14 to maintain
proper phase margin; for R14 values of 1, 2.5 &5Kohms, minimum capacitor values are
15,37 & 75pF. The capacitor may be tied to either VEE or ground, but using VEE increases
negative supply rejection.

A negative reference voltage may be used if R14 is grounded and the reference voltage is
applied R15 as shown in fig 2 a high input impedance is the main advantage of this method.
Compensation involves a capacitor to VEE on pin 16, using the same values as used before.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 65
Exp 11: Interfacing DAC

The negative reference voltage must be at least 4V above VEE supply. Bipolar input signals
may be handled by connecting R14 to a positive reference voltage equal to the peak positive
input level at pin 15.

When a DC reference voltage is used, capacitive bypass to ground is recommended. The 5V


logic supply is not recommended as a reference voltage. If a well regulated 5V supply which
drives logic is to be used as the reference, R14 should be decoupled by connecting it to 5v
through another resistor and bypassing the junction of two resistors with 0.1uF to ground. For
reference voltage greater than 5V, a clamp diode is recommended between pin14 & ground.
If pin 14 is driven by high impedance such as transistor current source, none of the above
compensation methods apply and the amplifier must be heavily compensated, decreasing the
overall bandwidth.

OUTPUT VOLTAGE RANGE

The voltage on pin 4 is restricted to a range of -0.55 to 0.4V when VEE=-5V due to the
current switching methods employed in the DAC0808.The negative output voltage
compliance of the DAC0808 is extended to -5V where the negative supply voltage is more
negative than -10V. Using a full scale current of 1.992mA and load resistor of 2.5 K ohm
between pin 4 and ground will yield a voltage output of 256 levels between 0 and -4.980V.
Floating pin 1 does not effect the converter speed or power dissipation. However the value of
the load resistor determines the switching time due to increased voltage swing. Values of RL
up to 500ohm do not significantly affect performance , but a 2.5Kohm load increases worst-
case settling time to 1.2us.

OUTPUT CURRNT RANGE

The output current maximum rating of 4.2mA may be used only for negative supply voltages
more negative than -8V, due to the increased voltage drop across the resistors in the reference
current amplifier.

ACCURACY

Absolute accuracy is the measure of each output current level with respect to its intended
value, and is dependent upon relative accuracy and full scale current drift. Relative accuracy
is the measure of each output current level as a fraction of the full scale current. The relative
accuracy of the DAC0808 is essentially constant with temperature due to the excellent
temperature tracking of the monolithic resistor ladder.

FLOWCHART:

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 66
Exp 11: Interfacing DAC

PORT MAP FOR INTERFACING DAC 0808

P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0


D7 D6 D5 D4 D3 D2 D1 D0

P3.7 P3.6 P3.5 P3.4 P3.3 P3.2 P3.1 P3.0


X X X X X X X ENABLE

P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0


D7 D6 D5 D4 X X EN RS

Program:

/**Program to interface a DAC-0808**/

#include<reg51.h>
#include<delay.h>
#include<lcd.h>
#include<int.h>
#include<float.h>

#define DAC P1 //8 bit data is transmitted to DAC0808 for digital to analog conversion

sbit ENABLE = P3^0; //enable latch

void main(void)
{
init_lcd(4);
display_lcd("Digital-Analog");
cmd_lcd(0xc0);
display_lcd("Conversion");

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 67
Exp 11: Interfacing DAC

while(1)
{
for(c=0;c<=255;c++)
{
cmd_lcd(0xcd);
integer_lcd(c); //display digital data
write_lcd(' ');
write_lcd(' ');
START=1; //enable latch
DAC=c; //transmit digital data to dac0808
START=0; //disable latch
delay_ms(500);
display_float(DAC);
}
}
}

Exercise:

1. Write a program to generate up stair case waveform by interfacing DAC to 8051.


2. Write a program to generate down stair case waveform by interfacing DAC to 8086.
3. Generate a sine waveform of P-P voltage 2V by interfacing DAC.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 68
Exp 12: Interfacing Stepper Motor

12. INTERFACING STEPPER MOTOR


Aim : Interfacing of Stepper motors in Unipolar & Bipolar mode.

Hardware : AT89s51
BDX33 Transistor
1N4007 Diodes
Resistors
Unipolar & Bi Polar Stepper motor’s

Circuit Diagram :

Schimatic: Unipolar mode Schimatic: Bipolar mode

Fundamentals :

Whenever there is a need to rotate the shaft with precise angle, it can be easily achieved by
using a stepper motor. For example if you need to rotate the shaft with an angle of 1.8
degrees, a stepper motor can do it. Stepper motors are driven by pulse. Each pulse drives the
shaft through a step angle. Stepper motors are devices, which convert electrical impulses into
discrete mechanical rotations.

Difference Between Stepper & DC Motors :

Stepper motors instead of being powered by a continuous flow of current as with DC motors
they are directly driven by the pulse.

Stepper Motor :

Motors are available in either 2 coil (bipolar) or 4 coil (unipolar) windings.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 69
Exp 12: Interfacing Stepper Motor

Types of Stepper Motors :

Unipolar : The Unipolar Stepper motor has 2 coils, simple lengths of wound wire. The coils
are identical and are not electrically connected.

In unipolar stepper motor there are 2 coils and 2 directions that gives us a possible 4-phase
sequence. All we need to do is get the sequencing right and the motor will turn continuously.

Bipolar : The Bipolar Stepper motor has 2 coils. The coils are identical and are not
electrically connected. The Bipolar Controller must be able to reverse the polarity of the
voltage across either coil, so current can flow in both directions. And, it must be able to
Energize these coils in sequence.

In the chart bellow, + indicates the coil is conducting in the forward Direction with one end
being positive with respect to ground. The indicates that the coil is conducting in the opposite
direction. Continuing the sequence as outlined above causes the rotor to rotate in a forward
direction.

Reversing this sequence causes the motor to rotate in the reverse direction. The coils only are
required to be energized long enough for the rotor to move to its' next position.

FULL STEP SEQUENCE


HALF STEP SEQUENCE

Port Map (unipolar) :

P1.7 P1.6 P1.5 P1.4 P1.3 P1.2 P1.1 P1.0


X X X X PHASE PHASE PHASE PHASE
4 3 2 1

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 70
Exp 12: Interfacing Stepper Motor

Flowchart :

FLOWCHART FOR FORWARD FLOWCHART FOR REVERSE


DIRECTION DIRECTION

Program:

/******interfacing unipolar stepper motor**********/

#include<reg51.h>
#include<delay.h>

void main(void)
{
while(1) /*Clockwise Movement (9a65)*/
{
P1 = 0x09;
delay(3);
P1 = 0x0a;
delay(3);

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 71
Exp 12: Interfacing Stepper Motor

P1 = 0x06;
delay(3);
P1 = 0x05;
delay(3);
}
}
//for Counter Clockwise Movement, reverse the stepping sequence(56a9)

#include<reg51.h>
#include<delay.h>

void main(void)
{
while(1) /*Counter Clockwise Movement (56a9)*/
{
P1 = 0x05;
delay(3);
P1 = 0x06;
delay(3);
P1 = 0x0a;
delay(3);
P1 = 0x09;
delay(3);
}
}

Result:
Observe the rotation of stepper motor.
Exercise:

1. Write a program to move the motor clockwise continuously by applying


a. Full step sequence
b. Half step sequence
c. Wave drive sequence

2. Write a program to move the motor by an angle 180 degrees in anticlockwise


direction by applying
a. Full step sequence
b. Half step sequence
c. Wave drive sequence

3. Write a program to rotate the stepper motor by an angle 270 degrees in clockwise
direction by applying above different sequences.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 72
Exp 12: Interfacing Stepper Motor

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 73
Exp 13: Interfacing 7 - Segment Display

13. INTERFACING 7 SEGMENT LED DISPLAY USING SPI

Aim: Interfacing MAX 7219 driver to drive 7 segment led display’s with a at89c51
microcontroller using a SPI bus.
Hardware:
1. AT89c51
2. MAX 7219(SPI) SEVEN SEGMENT DISPLAY DRIVER
3. EIGHT 7 SEGMENT LED DISPLAYS

Circuit Diagram:

Description:
The Max7219 is compact, serial input/output common cathode display driver that interface
microcontrollers to 7 segment numeric led displays of up to 8 digits, bar graph displays, or 64
individual leds Included on chip are a BCD code-B decoder, multiplex scan circuitry,
segment and digit drivers, and an 8*8 static RAM that stores each digit. Only one external

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 74
Exp 13: Interfacing 7 - Segment Display

resister is required to set the segment current for all led’s. The MAX7219 is compatible with
SPI, QSPI and Microwire, and has slew rate limited segment drivers to reduce EMI.
A convenient 3 wire serial interface connects to all common microcontrollers. Individual
digits may be addressed and updated without rewriting the entire display. The Max7219 also
allow the user to select code-B decoding or no-decode for each digit.

The devices include a 150 micro ampere low power shutdown mode, analog and digital
brightness control, a scan limit register that allows the user to display from 1 to 8 digits, and a
test mode that forces all led’s on.

Applications:

Bar Graph Displays


7-Segment Displays
Industrial Controllers
Panel Meters
LED Matrix Displays

Features:

10MHz Serial Interface


Individual LED Segment Control
Decode/No-Decode Digit Selection
150 micro amps Low Power Shutdown
Digital and Analog Brightness Control
Display Blanked on Power Up
Drive Common Cathode LED Display
SPI, QSPI, MICROWIRE Serial Interface
24-Pin DIP and SO Packages

PORT MAP FOR INTERFACING MAX 7219 USING SPI

P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 75
Exp 13: Interfacing 7 - Segment Display

X X DIN LOAD CLK X X X

Program:
//program to interface seven segment display driver using software implemented SPI protocol

#include<reg51.h> //include at89c51 microcontoller header file

sbit CS=P0^0; //chip select pin


sbit MOSI=P0^1; //master out slave in pin
sbit CLK=P0^2; //clock pin

void init_7seg(void);
void write_7seg(unsigned char,unsigned char);
void send_byte(unsigned char);
void clear_7seg(void);
void delay_ms(unsigned int);

unsigned char i,j,k,l,m,n,o,p,s[10]={0x7e,0x30,0x6d,0x79,0x33,0x5b,0x5f,0x70,0x7f,0x7b};


void main(void)
{
init_7seg();
while(1)
{
for(i=10;i>0;i--)
{
write_7seg(1,s[i-1]);
for(j=10;j>0;j--)
{
write_7seg(2,s[j-1]);
for(k=10;k>0;k--)
{
write_7seg(3,s[k-1]);

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 76
Exp 13: Interfacing 7 - Segment Display

for(l=10;l>0;l--)
{
write_7seg(4,s[l-1]);
for(m=10;m>0;m--)
{
write_7seg(5,s[m-1]);
for(n=10;n>0;n--)
{
write_7seg(6,s[n-1]);
for(o=10;o>0;o--)
{
write_7seg(7,s[o-1]);
for(p=10;p>0;p--)
{
write_7seg(8,s[p-1]);
delay_ms(100);
}
}
}
}
}
}
}
}
}
}
//initialize 7 segment driver max7219
void init_7seg(void)
{
write_7seg(0x0b,0x07); //Scan limit
write_7seg(0x09,0x00); //Decode
write_7seg(0x0c,0x01); //Shutdown
write_7seg(0x0f,0x00); //Display Test

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 77
Exp 13: Interfacing 7 - Segment Display

write_7seg(0x0a,0x0f); //Intensity
clear_7seg(); //clear 7segment display
}

void write_7seg(unsigned char loc,unsigned char c)


{
CS=1; //select max7219
send_byte(loc); //transmit register address of max7219
send_byte(c); //transmit data to be stored in the register
CS=0; //end communication
}
//transmit byte
void send_byte(unsigned char c)
{
unsigned char mask=0x80;
do //transmits 8 bits
{
CLK=0; //clock low
if(c&mask) //set data line accordingly(0 or 1)
MOSI=1;
else
MOSI=0;
CLK=1; //clock high
mask/=2;
}while(mask>0);
}
//clear 7 segment display
void clear_7seg(void)
{
unsigned char i;
for(i=1;i<=4;i++)
write_7seg(i,0x00);

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 78
Exp 13: Interfacing 7 - Segment Display

}
//generates delay in milli seconds
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++);
}
}

Result:
Observe the display on 7-seg display units.

Exercise:
1. Write a C Program by interfacing 2 7-segment displays and display the count from 99
to 00. And it restarts the counting after reaches the final Count.
2. Write a C program by interfacing 8 7-segment displays and display the string
“CBIT-ECE”.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 79
Exp 14: Interfacing LCD

14.a. INTERFACING LIQUID CRYSTAL DISPLAY (LCD) IN 8-BIT MODE

Aim: To interface a LCD to 8051


Hardware:
1. AT89S51
2. LCD
Fundamentals:
Standard LCD 14 pins

Pin # Name I/O Description


1 Ground - Power supply zero volts and signal ground
2 VSS + +5Vdc power supply. Works with lower voltages
VD
3 Contrast I It needs to be closed to ground level
Voltage and it can be adjusted via a variable resistor
Data sent to LCD can be a character to be displayed (RS: High)
4 RS I
command to be executed by the LCD controller (RS = Low)
Data Direction RW: High means a write to LCD
5 RW I
RW: Low means read from the LCD
CE: high tells LCD to initiate internal operation
6 E or CE I
based on the RS, RW and data signal levels
7-14 Data pins (8) I/O Data to be displayed or command to be executed.

LCD Addressing Values :


1 x 16
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F

2 x 16
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF

Command Encoding
Instruction RS RW D7 D6 D5 D4 D3 D2 D1 D0 Description
Clear Display 0 0 0 0 0 0 0 0 0 1 Clear all display and returns the cursor

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 80
Exp 14: Interfacing LCD

to the home position, address 080h


Returns the cursor to the home position
(address 080h). Also returns the display
Return home 0 0 0 0 0 0 0 0 1 *
being shifted to the original position.DD
Ram contents remain unchanged.
Set the cursor move direction and
Entry Mode specifies or not the shift display. These
0 0 0 0 0 0 0 1 I/D S
Set operations are performed during data
write and read.
I/D=1 Increment(+1)
I/D=0 Decrement(-1)
S=1 Followsdisplayshift

Sets On/Off of all display (D), Cursor


Display On/
0 0 0 0 0 0 1 D C B On/Off (C), and blink of cursor position
Off Control
character (B)
Moves the Cursor and shifts the
Cursor and
0 0 0 0 0 1 SC RL * * display without changing DD Ram
Display Shift
contents
SC=1 DisplayShift
SC=0 Cursormove
RL=1 ShifttotheRight
RL=0 ShifttotheLeft

Sets Interface data length (DL), number


Function Set 0 0 0 0 1 DL N F * * of display lines (N) and
character font (F)
DL=1 bits:8
DL=0 bits:4
N=1 lines:2
N=0 lines:1
F=1 dots:5x10
F=0 dots:5x7

Write Data 1 0 Write Data Writes data into DD Ram


Read Data 1 1 Read Data Reads data from DD Ram
Set CG Ram Sets the CG Ram address. CG Ram
0 0 0 1 Address CG Ram
Address Data is sent and received after this.

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 81
Exp 14: Interfacing LCD

Set DD Ram Sets the DD Ram address. DD Ram


0 0 1 Address DD Ram
Address Data is sent and received after this.
BF=1 ControllerBusy
BF=0 Contr.Available
DDRAM DisplayDataRam
CGRAM CharacterGeneratoruserRAM

Circuit Diagram (8 bit mode):

8 Bits Initialization Sequence:

DB Busy Bit
Activity RS RW DB7 DB5 DB4 DB3 DB2 DB1 DB0
6 readable?
Power On No
Wait more than 15ms
No
after Vcc raises to +4.5V
Send to LCD 0 0 0 0 1 1 * * * * No
Wait more than 4.1ms No
Send to LCD 0 0 0 0 1 1 * * * * No
Wait more than 100us No

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 82
Exp 14: Interfacing LCD

Send to LCD 0 0 0 0 1 1 * * * * No
Send to LCD (function set) 0 0 0 0 1 1 N F * * Yes
Continuous with regular initialization sequence...

Port Map(8 bit mode) :


P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
X X X X X X EN RS

P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0


DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0

Flowchart :

START

DELAY 15MS

CALL
LCD INITIALIZATION

CALL DISPLAY

END

Program:
/*Program to interface lcd in 8 bit mode*/
#include<reg51.h> //include at89c51 microcontroller header file
sbit RS=P0^0; //connect p0.0 to rs pin of lcd
sbit EN=P0^1; //connect p0.1 to en pin of lcd
#define LCD P2 //connect p2 to 8 i/o pins of lcd

void init_lcd(void);
void cmd_lcd(unsigned char);
CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL
Page 83
Exp 14: Interfacing LCD

void write_lcd(unsigned char);


void display_lcd(unsigned char *);
void delay_ms(unsigned int);

void main(void)
{
init_lcd(); //initialize lcd
while(1) //infinite loop
{
cmd_lcd(0x01); //clear lcd
display_lcd("Good Morning");
cmd_lcd(0xc0); //goto line 2 column 0
display_lcd("Hello Everybody");
delay_ms(1000); //delay 1000 milliseconds
cmd_lcd(0x01); //clear lcd
display_lcd("Welcome to");
cmd_lcd(0xc0); //goto line 2 column 0
display_lcd("Spectrochem Ints");
delay_ms(1000); +
}
}

//initialize lcd
void init_lcd(void)
{
delay_ms(10); //delay 10 milliseconds
cmd_lcd(0x38); //8 bit initialize, 5x7 character font, 16x2 display
cmd_lcd(0x0e); //lcd on, cursor on
cmd_lcd(0x06); //right shift cursor automatically after each character is displayed
cmd_lcd(0x01); //clear lcd
}

//transmit command or instruction to lcd

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 84
Exp 14: Interfacing LCD

void cmd_lcd(unsigned char c)


{
EN=1; //set enable pin
RS=0; //clear register select pin
LCD=c; //load 8 bit data
EN=0; //clear enable pin
delay_ms(2); //delay 2 milliseconds
}
//transmit a character to be displayed on lcd
void write_lcd(unsigned char c)
{
EN=1; //set enable pin
RS=1; //set register select pin
LCD=c; //load 8 bit data
EN=0; //clear enable pin
delay_ms(2); //delay 2 milliseconds
}
//transmit a string to be displayed on lcd
void display_lcd(unsigned char *s)
{
while(*s)
write_lcd(*s++);
}
//generates delay in milli seconds
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++);
}
}
Result:

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 85
Exp 14: Interfacing LCD

Observed the display on LCD.


14.b. INTERFACING LIQUID CRYSTAL DISPLAY (LCD) IN 4-BIT MODE

Aim: To interface a LCD in 4-bit mode to 8051


Hardware:
1. AT89S51
2. LCD
Circuit Diagram (4 bit mode):

Program:
/*Program to interface lcd in 4 bit mode*/

#include<reg51.h> //include at89c51 microcontroller header file

#define LCD P2 //connect p2.0 to rs pin, p2.1 to en pin,


//p2.4-p2.7 to 4 higher order i/o pins of lcd

void init_lcd(void);

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 86
Exp 14: Interfacing LCD

void cmd_lcd(unsigned char);


void write_lcd(unsigned char);
void display_lcd(unsigned char *);
void delay_ms(unsigned int);

void main(void)
{
init_lcd(); //initialize lcd
while(1)
{
cmd_lcd(0x01); //clear lcd
display_lcd("Good Morning");
cmd_lcd(0xc0); //goto line 2 column 0
display_lcd("Hello Everybody");
delay_ms(1000); //delay 1000 milliseconds
cmd_lcd(0x01); //clear lcd
display_lcd("Welcome to");
cmd_lcd(0xc0); //goto line 2 column 0
display_lcd("Spectrochem Ints");
delay_ms(1000); //delay 1000 milliseconds
}
}

//initialize lcd
void init_lcd(void)
{
delay_ms(10); //delay 10 milliseconds
cmd_lcd(0x28); //4 bit initialize, 5x7 character font, 16x2 display
cmd_lcd(0x0e); //lcd on, cursor on
cmd_lcd(0x06); //right shift cursor automatically after each character is
displayed
cmd_lcd(0x01); //clear lcd
}

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 87
Exp 14: Interfacing LCD

//transmit command or instruction to lcd


void cmd_lcd(unsigned char c)
{
unsigned char temp;
//transmit high byte
temp=c>>4;
LCD=temp<<4|0x02; //logical or with 0x02 since rs(rs=0) & en(en=1) are
LCD=0; //connected to p2.0 & p2.1 respectively
//transmit low byte
LCD=c<<4|0x02;
LCD=0;
delay_ms(2); //delay 2 milliseconds
}

//transmit a character to be displayed on lcd


void write_lcd(unsigned char c)
{
unsigned char temp;
//transmit high byte
temp=c>>4; //right shift operator
LCD=temp<<4|0x03; //logical or with 0x03 since rs(rs=1) & en(en=1) are
LCD=0; //connected to p2.0 & p2.1 respectively
//transmit low byte
LCD=c<<4|0x03; //left shift operator
LCD=0;
delay_ms(2); //delay 2 milliseconds
}

//transmit a string to be displayed on lcd


void display_lcd(unsigned char *s)
{
while(*s)

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 88
Exp 14: Interfacing LCD

write_lcd(*s++);
}

//generates delay in milli seconds


void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j<500;j++)
{
;
}
}
}

Result:
Observed the display on LCD.

Exercise:
1. Program to interface a LCD, LED’s & Switches to create a user selectable menu and
perform the specified operation on given number.
1st Set of Display: WELCOME TO
SPECTROCHEM LTD
2nd Set of Display: 1 INC 2 DEC
3 SET 4 RESET

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 89
Appx I Instruction set of 8086

I. INSTRUCTION SET OF 8086


Data transfer operations
Mnemonic Desription

MOV Mov byte /word to register or memory


IN , OUT Input byte/word from port output byte/word to port
LEA Load effective address
LDS, LES Load pointer using data segment, extra segment
PUSH, POP Push word onto stack, pop word off stack
XCHG Exchange byte/word
XLAT Translate byte using look – up table

Logical operations
Mnemonic Description

NOT Logical NOT of byte or word (1’s compliment)


AND Logical AND of byte or word
OR Logical OR of byte or word
XOR Logical XOR of byte or word
TEST TEST byte or word (AND without saving)

Shift and Rotate operations


Mnemonic Description

SHL, SHR Logical shift left, right byte or word by 1 or CL


SAL, SAR Arithmetic shift left, right byte or word by 1 or CL
ROL, ROR Rotate left, right byte or word by 1 or CL
RCL, RCR Rotate left, right through carry byte or word by 1 or CL
Arithmetic Operations
Mnemonic Description

ADD, SUB Add, subtract byte or word


ADC, SBB Add, subtract byte or word and carry (barrow)
INC, DEC Increment, decrement byte or word
NEG Negate byte or word (2’s compliment)
CMP Compare byte or word (Subtract without storing)
MUL, DIV Multiply, divide byte or word (unsigned)
IMUL, IDIV Integer multiply, divide byte or word (signed)
Convert byte to word, word to double word (useful before multiply,
CBW, CWD divide)

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 90
Appx I Instruction set of 8086

Adjustments after arithmetic operations

AAA, AAS, AAM, ASCII adjust for addition, subtraction, multiplication and division
AAD (ASCII codes 30-39)

DAA, DAS Decimal adjust for addition, subtraction

Transfer Operations
Mnemonic Description

Unconditional jump(short – 127/8, near – 32K,far between


JMP segments
Conditional Jumps
JA (JNBE) Jump if above (not below or equal)
JAE (JNB) Jump if above or equal (not below)
JB (JNAE) Jump if below (nor above or equal)
JBE (JNA) Jump if below or equal (not above)
JE (JZ) Jump if equal (Zero)
JG (JNLE) Jump if greater (not less or equal)
JGE (JNL) Jump if greater or equal (not less)
JL (JNGE) Jump if less (not greater or equal)
JLE (JNG) Jump if less or equal (not above)
JC, JNC Jump if carry set, carry not set
JO, JNO Jump if overflow, no overflow
JS, JNS Jump if sign, no sign
JNP (JPO) Jump if no parity (parity odd)
JP (JPE) Jump if parity (Parity even)

Loop control
LOOP Loop unconditional, count in CX, short jump to target address
LOOPE (LOOPZ) Loop if equal (Zero), count in CX, short jump to target address
LOOPNE Loop if not equal (not zero), count in CX, short jump to target
(LOOPNZ) address
JCXZ Jump if CX equal zero (used to skip code in loop)

Subroutine and Interrupt operations


Mnemonic Description

CALL, RET Call, return from procedure (inside or outside current segment)
INT, INTO Software interrupt, interrupt if overflow
IRET Return from interrupt

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 91
Appx I Instruction set of 8086

String Instructions
Mnemonic Description

MOVS Move byte or word string


MOVSB, MOVSW Move byte, word string
CMPS Compare byte or word strings
SCAS Scan byte or word strings (comparing to AL or AX)
LODS, STOS Load, store byte or word string to AL or AX
Repeat instructions placed in front of other string operations
REP Repeat
REPE, REPZ Repeat while equal, zero
REPNE, REPNZ Repeat while not equal, zero

Processor Control instructions


Mnemonic Description
Flag Manipulation
STC, CLC, CMC Set, clear, complement carry flag
STD, CLD Set, clear direction flag
STI, CLI Set, clear interrupt flag
LAHF, SAHF Load AH from flags, store AH into flags
PUSHF, POPF Push flags into stack, pop flags off stack

Co-processor , multiprocessor interface


ESC Escape to external processor interface
LOCK Lock bus during next instruction

Inactive states
NOP No operation
WAIT Wait for test pin activity
HALT Halt processor

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 92
Appx: II Instruction set of 8051

II INSTRUCTION SET OF 8051

Opcode Bytes Mnemonic Operands


00 1 NOP
01 2 AJMP addr11
02 3 LJMP addr16
03 1 RR A
04 1 INC A
05 2 INC direct
06 1 INC @R0
07 1 INC @R1
08 1 INC R0
09 1 INC R1
0A 1 INC R2
0B 1 INC R3
0C 1 INC R4
0D 1 INC R5
0E 1 INC R6
0F 1 INC R7
10 3 JBC bit, offset
11 2 ACALL addr11
12 3 LCALL addr16
13 1 RRC A
14 1 DEC A
15 2 DEC direct
16 1 DEC @R0
17 1 DEC @R1
18 1 DEC R0
19 1 DEC R1
1A 1 DEC R2
1B 1 DEC R3
1C 1 DEC R4
1D 1 DEC R5
1E 1 DEC R6
1F 1 DEC R7
20 3 JB bit, offset
21 2 AJMP addr11
22 1 RET
23 1 RL A
24 2 ADD A, #immed
25 2 ADD A, direct
26 1 ADD A, @R0
27 1 ADD A, @R1
28 1 ADD A, R0
29 1 ADD A, R1
2A 1 ADD A, R2
2B 1 ADD A, R3
2C 1 ADD A, R4
CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL
Page 93
Appx: II Instruction set of 8051

Opcode Bytes Mnemonic Operands


2D 1 ADD A, R5
2E 1 ADD A, R6
2F 1 ADD A, R7
30 3 JNB bit, offset
31 2 ACALL addr11
32 1 RETI
33 1 RLC A
34 2 ADDC A, #immed
35 2 ADDC A, direct
36 1 ADDC A, @R0
37 1 ADDC A, @R1
38 1 ADDC A, R0
39 1 ADDC A, R1
3A 1 ADDC A, R2
3B 1 ADDC A, R3
3C 1 ADDC A, R4
3D 1 ADDC A, R5
3E 1 ADDC A, R6
3F 1 ADDC A, R7
40 2 JC offset
41 2 AJMP addr11
42 2 ORL direct, A
43 3 ORL direct, #immed
44 2 ORL A, #immed
45 2 ORL A, direct
46 1 ORL A, @R0
47 1 ORL A, @R1
48 1 ORL A, R0
49 1 ORL A, R1
4A 1 ORL A, R2
4B 1 ORL A, R3
4C 1 ORL A, R4
4D 1 ORL A, R5
4E 1 ORL A, R6
4F 1 ORL A, R7
50 2 JNC offset
51 2 ACALL addr11
52 2 ANL direct, A
53 3 ANL direct, #immed
54 2 ANL A, #immed
55 2 ANL A, direct
56 1 ANL A, @R0
57 1 ANL A, @R1
58 1 ANL A, R0
59 1 ANL A, R1
5A 1 ANL A, R2
5B 1 ANL A, R3
CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL
Page 94
Appx: II Instruction set of 8051

Opcode Bytes Mnemonic Operands


5C 1 ANL A, R4
5D 1 ANL A, R5
5E 1 ANL A, R6
5F 1 ANL A, R7
60 2 JZ offset
61 2 AJMP addr11
62 2 XRL direct, A
63 3 XRL direct, #immed
64 2 XRL A, #immed
65 2 XRL A, direct
66 1 XRL A, @R0
67 1 XRL A, @R1
68 1 XRL A, R0
69 1 XRL A, R1
6A 1 XRL A, R2
6B 1 XRL A, R3
6C 1 XRL A, R4
6D 1 XRL A, R5
6E 1 XRL A, R6
6F 1 XRL A, R7
70 2 JNZ offset
71 2 ACALL addr11
72 2 ORL C, bit
73 1 JMP @A+DPTR
74 2 MOV A, #immed
75 3 MOV direct, #immed
76 2 MOV @R0, #immed
77 2 MOV @R1, #immed
78 2 MOV R0, #immed
79 2 MOV R1, #immed
7A 2 MOV R2, #immed
7B 2 MOV R3, #immed
7C 2 MOV R4, #immed
7D 2 MOV R5, #immed
7E 2 MOV R6, #immed
7F 2 MOV R7, #immed
80 2 SJMP offset
81 2 AJMP addr11
82 2 ANL C, bit
83 1 MOVC A, @A+PC
84 1 DIV AB
85 3 MOV direct, direct
86 2 MOV direct, @R0
87 2 MOV direct, @R1
88 2 MOV direct, R0
89 2 MOV direct, R1
8A 2 MOV direct, R2
CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL
Page 95
Appx: II Instruction set of 8051

Opcode Bytes Mnemonic Operands


8B 2 MOV direct, R3
8C 2 MOV direct, R4
8D 2 MOV direct, R5
8E 2 MOV direct, R6
8F 2 MOV direct, R7
90 3 MOV DPTR, #immed
91 2 ACALL addr11
92 2 MOV bit, C
93 1 MOVC A, @A+DPTR
94 2 SUBB A, #immed
95 2 SUBB A, direct
96 1 SUBB A, @R0
97 1 SUBB A, @R1
98 1 SUBB A, R0
99 1 SUBB A, R1
9A 1 SUBB A, R2
9B 1 SUBB A, R3
9C 1 SUBB A, R4
9D 1 SUBB A, R5
9E 1 SUBB A, R6
9F 1 SUBB A, R7
A0 2 ORL C, /bit
A1 2 AJMP addr11
A2 2 MOV C, bit
A3 1 INC DPTR
A4 1 MUL AB
A5 reserved
A6 2 MOV @R0, direct
A7 2 MOV @R1, direct
A8 2 MOV R0, direct
A9 2 MOV R1, direct
AA 2 MOV R2, direct
AB 2 MOV R3, direct
AC 2 MOV R4, direct
AD 2 MOV R5, direct
AE 2 MOV R6, direct
AF 2 MOV R7, direct
B0 2 ANL C, /bit
B1 2 ACALL addr11
B2 2 CPL bit
B3 1 CPL C
B4 3 CJNE A, #immed, offset
B5 3 CJNE A, direct, offset
B6 3 CJNE @R0, #immed, offset
B7 3 CJNE @R1, #immed, offset
B8 3 CJNE R0, #immed, offset
B9 3 CJNE R1, #immed, offset
CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL
Page 96
Appx: II Instruction set of 8051

Opcode Bytes Mnemonic Operands


BA 3 CJNE R2, #immed, offset
BB 3 CJNE R3, #immed, offset
BC 3 CJNE R4, #immed, offset
BD 3 CJNE R5, #immed, offset
BE 3 CJNE R6, #immed, offset
BF 3 CJNE R7, #immed, offset
C0 2 PUSH direct
C1 2 AJMP addr11
C2 2 CLR bit
C3 1 CLR C
C4 1 SWAP A
C5 2 XCH A, direct
C6 1 XCH A, @R0
C7 1 XCH A, @R1
C8 1 XCH A, R0
C9 1 XCH A, R1
CA 1 XCH A, R2
CB 1 XCH A, R3
CC 1 XCH A, R4
CD 1 XCH A, R5
CE 1 XCH A, R6
CF 1 XCH A, R7
D0 2 POP direct
D1 2 ACALL addr11
D2 2 SETB bit
D3 1 SETB C
D4 1 DA A
D5 3 DJNZ direct, offset
D6 1 XCHD A, @R0
D7 1 XCHD A, @R1
D8 2 DJNZ R0, offset
D9 2 DJNZ R1, offset
DA 2 DJNZ R2, offset
DB 2 DJNZ R3, offset
DC 2 DJNZ R4, offset
DD 2 DJNZ R5, offset
DE 2 DJNZ R6, offset
DF 2 DJNZ R7, offset
E0 1 MOVX A, @DPTR
E1 2 AJMP addr11
E2 1 MOVX A, @R0
E3 1 MOVX A, @R1
E4 1 CLR A
E5 2 MOV A, direct
E6 1 MOV A, @R0
E7 1 MOV A, @R1
E8 1 MOV A, R0
CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL
Page 97
Appx: II Instruction set of 8051

Opcode Bytes Mnemonic Operands


E9 1 MOV A, R1
EA 1 MOV A, R2
EB 1 MOV A, R3
EC 1 MOV A, R4
ED 1 MOV A, R5
EE 1 MOV A, R6
EF 1 MOV A, R7
F0 1 MOVX @DPTR, A
F1 2 ACALL addr11
F2 1 MOVX @R0, A
F3 1 MOVX @R1, A
F4 1 CPL A
F5 2 MOV direct, A
F6 1 MOV @R0, A
F7 1 MOV @R1, A
F8 1 MOV R0, A
F9 1 MOV R1, A
FA 1 MOV R2, A
FB 1 MOV R3, A
FC 1 MOV R4, A
FD 1 MOV R5, A
FE 1 MOV R6, A
FF 1 MOV R7, A

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 98
Appx. III. I/O Ports

III. I/O PORTS

J1 (8051 – PORT0 / AVR – PORTA) J2 (8051 – PORT1 / AVR –


1 2 3 4 5 6 7 8 9 10 PORTB)
Bit Bit X X 1 2 3 4 5 6 7 8 9 10
0 7 Bit Bit X X
0 7

J3 (8051 – PORT2 / AVR – PORTC) J4 (8051 – PORT2 / AVR –


1 2 3 4 5 6 7 8 9 10 PORTD)
Bit Bit X X 1 2 3 4 5 6 7 8 9 10
0 7 Bit Bit X X
J7 0 7
LED’S
1 2 3 4 5 6 7 8 9 10
LED1 LED2 LED3 LED4 LED5 LED6 LED7 LED8 X X

J8
Relay’s,SSRC,Buzzer
1 2 3 4 5 6 7 8 9 10

RELAY1 RELAY2 RELAY3 RELAY4 RELAY5 RELAY6 SSRC BUZZE X X


R

J9 Expanding I/P
Controls
1 2 3 4 5 6 7 8 9 10

LOAD CLK DATA X X X X X X X

J10 Expanding O/P


Controls
1 2 3 4 5 6 7 8 9 10
A B RESET CLK X X X X X X

J11 ADC
Data
1 2 3 4 5 6 7 8 9 10

ADC0 ADC7 X X

J12 ADC & DAC


Control
1 2 3 4 5 6 7 8 9 10
A0 A1 A2 START ALE EOC DAC G X X X

J13 DAC
Data
1 2 3 4 5 6 7 8 9 10
DACD0 DCA7 X X

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 99
Appx. III. I/O Ports

J14 Switches
1 2 3 4 5 6 7 8 9 10
SW1 SW2 SW3 SW4 SW5 SW6 SW7 X X X

J15 RC5
Remote
1 2 3 4 5 6 7 8 9 10
RC5 RXD RC5TX X X X X X X X X
D

J16 1-Wire &


I2C
1 2 3 4 5 6 7 8 9 10
1W1 1W2 1W3 X SCL SDA X X X X

J17
SPI
1 2 3 4 5 6 7 8 9 10
CS DIN CLK DOUT X X X X X X

J18 LCD 4-Bit


1 2 3 4 5 6 7 8 9 10
RS EN X X DB4 DB5 DB6 DB7 X X

J19 Graphic LCD Controls


1 2 3 4 5 6 7 8 9 10
WR/CS2 RD/CS CE/EN CD/RS RST RW X X X X
1

J20 LCD 8-
Bit
1 2 3 4 5 6 7 8 9 10
DB0 DB7 X X

JP1 POWER SUPPLY


1 2 3 4 5 6 7 8
+5V GND +12V GND -12V GND +5V GND

JP2 RS-232 TTL-1 JP3 GPS FASTRAX U TRACER


1 2 3 4 1 2 3 4 5 6 7 8
RXD0 TXD0 RXD1 TXD1 X 3.3 RXD2 X TXD X X GN
V 2 D
JP4 PWM JP6 IIC EXTENSION
1 2 3 4 1 2 3 4
PWM PWM PWM PWM VCC SCL SDA GND
1 2 3 4

JP7 RS-232 TTL2 JP9 TO ADC


1 2 1 2

RXD2 TXD2 0/P GND

CBIT1(AUTONOMOUS)
2 – ECE – MICRCONTROLLER LAB MANUAL
Page 100
Appx. III. I/O Ports

GND O/P JP11 RTC SQWO/P JP12


AUDIO I/P
1 2
I/P GND

JP13 AUDIO O/P JP14 RS-485 O/P


1 2 1 2 3
O/P GND A B GND

JP15 RS-485 I/P JP17 IR LED


1 2 3 1 2
DE DI R0 LED GND

JP4 2MM BERG


1 2 3 4 5 6 7 8 9 10 11 12

3.3V RRST GND R2IN X X GND R2OU X X GND X


T

JP5 2MM BERG


1 2 3 4 5 6 7 8 9 10 11 12

GND RD- RD+ GND TD- TD+ GND LED9 LED1 LED LED1 3.3V
0 1 2

JP19 LM324 SPARE


1 2 3 4 5 6 7 8 9

X1 X2 Y1 X3 X4 Y2 X5 X6 Y3

CON2 ANALOG CHANNELS


1 2 3 4 5 6 7 8 9

GND IN0 IN1 IN2 IN3 IN4 IN5 IN6 IN7

LM324 SPARE
1 2 3 4 5 6 7 8 9

X1 X2 Y1 X3 X4 Y2 X5 X6 Y3

DRIVER BOARD PORT MAPS:

CON1 MOTOR PHASES CON2 MOTOR SUPPLY


1 2 3 4 1 2 3 4
PH PH PH PH +12V +12V +12V +12V
1 2 3 4
CON3 BIPOLAR STEPPER CON4 DC MOTOR1 CON5 DC
1 2 3 4 MOTOR2
1 2
O/P1 O/P2 O/P3 O/P4
MT1A MTIB

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 101
Appx. III. I/O Ports

1 2
MT2A MT2B

CON6 PWM O/PS


1 2 3 4 5 6 7 8

MTR/VALV PWMOUT MTR/VALV PWMOUT MTR/VALV PWMOUT MTR/VALV PWMOUT


E 1 E 2 E 3 E 4

CON7 SERVO1 CON8 SERVO2


1 2 3 1 2 3
+5V SERVO1 GND +5V SERVO2 GND

CON9 SERVO3 CON10 SERVO4


1 2 3 1 2 3
+5V SERVO3 GND +5V SERVO4 GND

JP1 POWER SUPPLY


1 2 3 4 5 6 7 8
+5V GND +12V GND MTR/VALV GND +5V GND
E

J1 BIPOLAR STEPPER MOTOR CONTROLS


1 2 3 4 5 6 7 8 9 10
RST CLK ENABL CW/C CNTRL PWR X X X X
E W

J2 UNIPOLAR STEPPER MOTOR


1 2 3 4 5 6 7 8 9 10
PH-A PH-B PH-C PH-D X X X X X X

J3 PWM
CONTROLS
1 2 3 4 5 6 7 8 9 10
PWM1 PWM2 PWM3 PWM4 X X X X X X

J4
SERVOS
1 2 3 4 5 6 7 8 9 10
SERVO1 SERVO SERVO SERVO X X X X X X
2 3 4

J5 DC MOTORCONTROL
1 2 3 4 5 6 7 8 9 10
1A 2A 3A 4A 1,2 EN 3,4 EN X X X X

CBIT (AUTONOMOUS) – ECE – MICRCONTROLLER LAB MANUAL


Page 102

You might also like