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

MPMC Programs

Programs for ECE students
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

MPMC Programs

Programs for ECE students
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

SCITS ECE MICROCONTROLLER LAB

CYCLE -1
1. 16 bit Addition [immediate addressing mode]

AIM:-
To write an ALP for Addition operation of two 16-bit numbers using immediate
addressing mode

APPARATUS:-
MASM software

Program:-
.8086
.model small
.code
mov ax,1234h
mov bx,5678h
add ax,bx
mov ah,4ch
int 21h
end
Result:-

2. 16 bit Subtraction [immediate addressing mode]


AIM:-
To write an ALP for Subtraction operation of two 16-bit numbers using immediate
addressing mode

APPARATUS:-
MASM software

Program:-
.8086
.model small
.code
mov ax,5678h
mov bx,1234h
sub ax,bx
mov ah,4ch
int 21h
end

Result:-

1
3. 16 bit Multiplication [immediate addressing mode]

AIM:-
To write an ALP for Multiplication operation of two 16-bit numbers using immediate
addressing mode

APPARATUS:-
MASM software

Program:-
.8086
.model small
.code
mov ax,5000h
mov
bx,1100h mul
bx
mov ah,4ch
int 21h
end

Result:-

4. 16 bit Division [immediate addressing mode]


AIM:-
To write an ALP for Division operation of two 16-bit numbers using immediate
addressing mode
APPARATUS:-
MASM software

Program:-
.8086
.model small
.code
mov ax,5000h
mov bx,0000h
mov bx,0055h
div bx
mov ah,4ch
int 21h
end

Result:-

2
5. 16-bit Addition [direct addressing mode]
AIM:-
To write an ALP for Addition operation of two 16-bit numbers
using direct addressing mode
APPARATUS:-
MASM software
Program:-

.8086
.model small
.data
addend dw 1234h
augend dw 5678h
sumL dw?
sumH dw?
.code
mov ax,@data
mov ds,ax
mov ax,addend
mov bx,augend
add ax,bx
mov sumL,al
mov sumH,ah
mov ah,4ch
int 21h
end

RESULT:-

2
SCITS ECE MICROCONTROLLER LAB

6. 16-bit Subtraction [direct addressing mode]


AIM:-
To write an ALP for Subtraction operation of two 16-bit numbers
using direct addressing mode
APPARATUS:-
MASM software
Program:-

.8086
.model small
.data
subtrahend dw 5678h
minuend dw 1234h
diffL dw?
diffH dw?
.code
mov ax,@data
mov ds,ax
mov ax,subtrahend
mov bx,minuend
sub ax,bx
mov diffL,al
mov diffH,ah
mov ah,4ch
int 21h
end

RESULT:-

3
SCITS ECE MICROCONTROLLER LAB

7. 16-bit Multiplication [direct addressing mode]


AIM:-
To write an ALP for Multiplication operation of two 16-bit
numbers using direct addressing mode
APPARATUS:-
MASM software
Program:-

.8086
.model small
.data
multiplicand dw 5000h
multiplexer dw 1100h
productL dw?
productH dw?
.code
mov ax,@data
mov ds,ax
mov ax,mutliplicand
mov bx,mutliplexer
mul bx
mov productL,dx
mov productH,dx
mov ah,4ch
int 21h
end

RESULT:-

4
SCITS ECE MICROCONTROLLER LAB

8. 16-bit Division [direct addressing mode]


AIM:-
To write an ALP for Division operation of two 16-bit numbers
using direct addressing mode
APPARATUS:-
MASM software
Program:-

.8086
.model small
.data
dividend dw 5000h
division dw 0055h
quotient dw?
remainder dw?
.code
mov ax,@data
mov ds,dx
mov ax,dividend
mov dx,divison
div dx
mov quotient,ax
mov
remainder,dx
mov ah,4ch
int 21h
end

RESULT:-

5
SCITS ECE MICROCONTROLLER LAB

9. 16-bit Logical AND operation

AIM:-
To write an ALP for Logical AND operation of two 16-bit numbers.

APPARATUS:-
MASM software

Program:-
.8086
.model small
.code
mov ax,1234h
mov bx,5678h
AND ax,bx
mov ah,4ch
int 21h
end
Result:-

10. 16-bit Logical OR operation

AIM:-
To write an ALP for Logical OR operation of two 16-bit numbers.

APPARATUS:-
MASM software

Program:-
.8086
.model small
.code
mov ax,1234h
mov bx,5678h
OR ax,bx
mov ah,4ch
int 21h
end
Result:-

6
SCITS ECE MICROCONTROLLER LAB

11. 16-bit Logical EXCLUSIVE-OR operation

AIM:-
To write an ALP for Logical EXCLUSIVE-OR operation of two 16-bit numbers

APPARATUS:-
MASM software

Program:-
.8086
.model small
.code
mov ax,1234h
mov bx,5678h
XOR ax,bx
mov ah,4ch
int 21h
end

Result:-

12. 16-bit Logical NOT operation

AIM:-
To write an ALP for Logical NOT operation of two 16-bit numbers

APPARATUS:-
MASM software
Program:-
.8086
.model small
.code
mov ax,5678h
NOT ax
mov ah,4ch
int 21h
end

Result:-

7
SCITS ECE MICROCONTROLLER LAB

13. Program for String Manipulation 0f 8086


Interchange data

AIM:-
To Write an ALP for Interchange the data in the two locations

APPARATUS:-
MASM software
Program:-

.8086
.model small
.data
d1 db 01h,02h,03h,04h,05h
d2 db 11h,22h,33h,44h,55h
.code
mov ax,@data
mov ds,ax
mov si,offset d1
mov di,offset d2
up: mov al,[si]
mov bl,[di]
mov [si],bl
inc si
inc di
dec cl
jmp up
mov ah,4ch
int 21h
end

Result:-

8
SCITS ECE MICROCONTROLLER LAB

14. Length of the String

AIM:-
To Write an ALP for Length of the given String

APPARATUS:-
MASM software
Program:-

.8086
.model small
.data
d1 db ‘mpmc $’
len db?
.code
mov ax,@data
mov ds,ax
mov al, ’$’
mov cl,00h
mov si,offset d1
back: cmp al,[si]
jz go
inc cl
inc si
jmp back
go:mov len,cl
mov ax,4ch
int 21h
end

Result:-

9
SCITS ECE MICROCONTROLLER LAB

15.Display the given String

AIM:-
To Write an ALP for Display the given String

APPARATUS:-
MASM software

Program:-

.8086
.model small
.data
mystr db ‘prashanth’
.code
mov ax,@data
mov ds,ax
lea dx,mystr
mov ah,08h
int 21h
mov ah,4ch
int 21h
end

Result:-

10
SCITS ECE MICROCONTROLLER LAB

16. Reverse String

AIM:-
To Write an ALP for Interchange the data in the two locations

APPARATUS:-
MASM software
Program:-

.8086
.model small
.data
data1 db 1ch,2ch,3ch,4ch,5ch
data2 db 5dup(?)
.code
mov ax,@data
mov ds,ax
mov cl,05h
mov si,offset data1
mov di,offset
data2 add si,04h
up: mov al,[si]
mov [di],al
dec si
inc di
jnz up
mov ah,4ch
int 21h
end

Result:-

11
SCITS ECE MICROCONTROLLER LAB

17.Swap of Two Numbers

AIM:-
To Write an ALP for swapping of two 16-bit numbers

APPARATUS:-
MASM software

Program:-

.8086
.model small
.data
num1 dw 1234h
num2 dw 5678h
.code
mov
ax,@data
mov ds,ax
mov ax,num1
mov bx,ax
mov ax,num2
mov num1,ax
mov num2,bx
mov ah,4ch
int 21h
end

Result:-

12
SCITS ECE MICROCONTROLLER LAB

18.Searching for a Character

AIM:-
To Write an ALP for searching for a character in the given string

APPARATUS:-
MASM software

Program:-

.8086
.model small
.data
d1 db ‘grace $’
slen EQU d1+1
letter db ‘a’
result db ‘a’
.code
mov ax,@data
mov ds,ax
mov al,letter
mov si,offset d1
mov bl,0000h
cld
mov cl,slen
count: repne scasb
jcxz display
inc bl
jmp count
display:mov result,bl
mov ah,4ch
int 21h

RESULT:-

13
SCITS ECE MICROCONTROLLER LAB

19. Rotate Left Operation [8-bit]

AIM:-
To Write an ALP for 8-bit Rotate Left Operation

APPARATUS:-
MASM Software
Program:-
.8086
.model small
.code
mov al,49h
mov cl,04h
ROL al,cl
mov ah,4ch
int 21h
end
Result:-

20.Rotate Right Operation [8-bit]

AIM:-
To Write an ALP for 8-bit Rotate Right Operation

APPARATUS:-
MASM Software
Program:-
.8086
.model small
.code
mov al,51h
mov cl,03h
ROR al,cl
mov ah,4ch
int 21h
end
Result:-

14
SCITS ECE MICROCONTROLLER LAB

21. Circular Rotate Left Operation [8-bit]

AIM:-
To Write an ALP for 8-bit Circular Rotate Left Operation

APPARATUS:-
MASM Software
Program:-
.8086
.model small
.code
mov al,28h
mov cl,04h
RCL al,cl
mov ah,4ch
int 21h
end
Result:-

22.Circular Rotate Right Operation [8-bit]

AIM:-
To Write an ALP for 8-bit Circular Rotate Right Operation

APPARATUS:-
MASM Software
Program:-
.8086
.model small
.code
mov al,87h
mov cl,03h
RCR al,cl
mov ah,4ch
int 21h
end
Result:-

15
SCITS ECE MICROCONTROLLER LAB

23. Shift Left Operation [8-bit]

AIM:-
To Write an ALP for 8-bit Shift Left Operation

APPARATUS:-
MASM Software
Program:-
.8086
.model small
.code
mov al,53h
mov cl,04h
SHL al,cl
mov ah,4ch
int 21h
end
Result:-

24.Shift Right Operation [8-bit]

AIM:-
To Write an ALP for 8-bit Shift Right Operation

APPARATUS:-
MASM Software
Program:-
.8086
.model small
.code
mov al,96h
mov cl,03h
SHR al,cl
mov ah,4ch
int 21h
end
Result:-

16
SCITS ECE MICROCONTROLLER LAB

PROCEDURE FOR 8051 MICROCONTROLLER


TRAINER KIT

 Switch on the micro controller 8051 trainer kit.


 The display will appear as ALS,SDA 8657A
 Press A
 Get the starting address 8000 and press ENTER
 8000 [ eg: mov ax,data ]
 8002 [ eg: mov bx,data ]
 8004 [ eg: add ax,bx ]
 8007 [ LCALL 03 ]
 Press ENTER 3 times.
 Display ADGMTS.
 Too compile press G and press ENTER.
 Display- PROGRAM EXECUTED.
 Press R & Press A.

17
SCITS ECE MICROCONTROLLER LAB

25. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( Addition)
AIM:-
To write an ALP for Addition operation of two 8-bit numbers using
8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-
Memory Opcode Mnemonics Comment
Location operand

8000 74 MOV A,#03h 03 is moved to A


8002 75 MOV B,#02h 02 is moved to B
8005 25 ADD A,B ADD A&B,The result is
stored in A
8007 12 LCALL 03 Break point

RESULT:-

26. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( Subtraction)
AIM:-
To write an ALP for Subtraction operation of two 8-bit numbers using
8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-
Memory Opcode Mnemonics Comment
Location operand

8000 74 MOV A,#0Fh 0F is moved to A


8002 75 MOV B,#05h 05 is moved to B
8005 95 SUBB A,B B is subtracted form A,
The result is stored
in A
8007 12 LCALL 03 Break point

RESULT:-

18
SCITS ECE MICROCONTROLLER LAB

27. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( Multiplication)
AIM:-
To write an ALP for Multiplication operation of two 8-bit numbers
using 8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-
Memory Opcode Mnemonics Comment
Location operand

8000 74 MOV A,#02h 02 is moved to A


8002 75 MOV 0F0,#05h 05 is moved to B
8005 A4 MUL AB MUL A & B, The result is
stored in A
8006 12 LCALL 03 Break point

RESULT:-

28. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( Division )
AIM:-
To write an ALP for Division operation of two 8-bit numbers using
8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-
Memory Opcode Mnemonics Comment
Location operand

8000 74 MOV A,#04h 04 is moved to A


8002 75 MOV 0F0,#02h 02 is moved to B
8005 84 DIV AB Div B with A,
The result is stored
in A
8006 12 LCALL 03 Break point

RESULT:-

19
SCITS ECE MICROCONTROLLER LAB

29. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( AND operation)
AIM:-
To write an ALP for AND operation of two 8-bit numbers using
8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-
Memory Opcode Mnemonics Comment
Location operand

8000 74 MOV A,#12h 12 is moved to A


8002 54 ANL A,#53h A is AND with 53
8003 12 LCALL 03 Break point

RESULT:-

30. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( OR operation )
AIM:-
To write an ALP for OR operation of two 8-bit numbers using 8051 Micro-
controller

Apparatus:- ASM-SDA-51-MEL

Program:-
Memory Opcode Mnemonics Comment
Location operand

8000 74 MOV A,#11h 11 is moved to A


8002 44 ORL A,#12h A is OR with 12
8003 12 LCALL 03 Break point

RESULT:-

20
SCITS ECE MICROCONTROLLER LAB

31. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( XOR operation)
AIM:-
To write an ALP for XOR operation of two 8-bit numbers using
8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-

Memory Opcode Mnemonics Comment


Location operand

8000 74 MOV A,#12h 12 is moved to A


8002 64 XRL A,#12h A is XOR with 12
8003 12 LCALL 03 Break point

RESULT:-

32. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( NOT operation )
AIM:-
To write an ALP for NOT operation of two 8-bit numbers using
8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-

Memory Opcode Mnemonics Comment


Location operand

8000 74 MOV A,#55h 55 is moved to A


8002 F4 CPL A A is
Complimented 8003 12 LCALL 03
Break point

RESULT:-

21
SCITS ECE MICROCONTROLLER LAB

33. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( Rotate Right
operation)
AIM:-
To write an ALP for Rotate Right operation of two 8-bit numbers using
8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-

Memory Opcode Mnemonics Comment


Location operand

8000 74 MOV A,#36h 36 is moved to A


8002 03 RR A Rotate Right content of A
8003 12 LCALL 03 Break point

RESULT:-

34. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( Rotate Left operation )
AIM:-
To write an ALP for Rotate Left operation of two 8-bit numbers using
8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-

Memory Opcode Mnemonics Comment


Location operand

8000 74 MOV A,#72h 72 is moved to A


8002 23 RL A Rotate Left contents of A
8003 12 LCALL 03 Break point

RESULT:-

22
SCITS ECE MICROCONTROLLER LAB

35. Programming using Arithmetic logic and bit


manipulation instruction of 8051 ( Rotate Left through
Carry operation)
AIM:-
To write an ALP for Rotate Left through carry operation of two 8-bit
numbers using 8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-
Memory Operand Mnemonics Comment
Location operand

8000 74 MOV A,#72h 72 is moved to A


8002 03 RLC A Rotate Left with carry A
8003 12 LCALL 03 Break point

RESULT:-

36. Programming using Arithmetic logic and bit manipulation


instruction of 8051 ( Rotate Right through carry operation
)
AIM:-
To write an ALP for Rotate Right through carry operation of two 8-bit
numbers using 8051 Micro-controller

Apparatus:- ASM-SDA-51-MEL

Program:-
Memory Operand Mnemonics Comment
Location operand

8000 74 MOV A,#36h 36 is moved to A


8002 13 RRC A Rotate Right with carry A
8003 12 LCALL 03 Break point

RESULT:-

23
SCITS ECE MICROCONTROLLER LAB

CYCLE -2

2 .Time delay generation using Timers of 8051.

Adress Opcode Label Mnemonics Comments

8000 75,89,10 Mov ; Load 10H in TMOD


8003 75,8B,00 Again: TMOD,#10H ;Load 00 in TL1
8006 75,8D,D MovTL1,#00 ;Load DCH inTH1
8009 C Mov TH1,#DCH ;Set bit TR1
800B D2,8E Back: Set B,TR1 ;Jump if addressed bit is
800E 30,8F,00 JNB TF1,back not set
8010 C2,8E CLR TR1 ;Clear bit TR1
8012 B2.90 CPL P1.0 ;Complement P1
8014 C2,8F CLR TF1 ;Clear bit TF1
8016 80,ED SJMP Again ;Short Jump
02,0F,00 LJMP ;End

Addres Opcode Label Mnemonics Comments


s
8000 75,89,20 Mov ; Load 20H in TMOD
8003 75,8D,05 TMOD,#20H ;Load 05 in TH1
8006 D2,8E Mov TH1,#05H ;Set bit TR1
8008 30,8F,00 Back: Set B,TR1 ;Jump if addressed bit is
800B B2.90 JNB TF1,Back not set
800D C2,8F CPL P1.0 ;Complement P1
800F 80,F7 CLR TF1 ;Clear bit TF1
8011 02,0F,00 SJMP Back ;Short Jump
LJMP ;End

Timer in different mode: (mode1)


TF1 TR1 TF0 TR0 IE1 IT1 IE0
IT0
8F 8E 8D 8C 8B 8A 89 88
TCO
N
TIMER1 TIMER0
0 0 0 1 0 0
0 0
GATE C/T M1 M0 GATE C/T M1 M0

24
SCITS ECE MICROCONTROLLER LAB

TIMER1 TIMER0
TMOD

Timer in different mode: (mode2)


TF1 TR1 TF0 TR0 IE1 IT1 IE0
IT0
8F 8E 8D 8C 8B 8A 89 88
TCO
N
TIMER1 TIMER0
0 0 1 0 0 0
0 0
GATE C/T M1 M0 GATE C/T M1 M0
TIMER1 TIMER0
TMOD

RESULT: With the help of Timer1 we can generate different time delays in
mode1 and mode 2 configurations.

3. Serial communication from /to/from I/O devices

ORG 0x0000
MOV TMOD, #20H ; Timer1 mode2 (8-bit auto-reload) for baud rate
generation
MOV TH1, #0FDH ; Load Timer1 for 9600 baudrate
SETB TR1 ; Start Timer1
MOV SCON, #50H ; Mode1, 8-bit UART, enable receiver

MAIN:
; Send data from microcontroller to external device (Arduino IDE serial
monitor)
MOV A, #65 ; Example: ASCII 'A'
MOV SBUF, A ; Send data over serial
ACALL WAIT_FOR_TX_COMPLETE
25
SCITS ECE MICROCONTROLLER LAB

; Receive data from external device (Arduino IDE serial monitor)


ACALL WAIT_FOR_RX_COMPLETE
MOV A, SBUF ; Read received data
; Process received data here
; For example, echo the received data back to the Arduino IDE serial monitor
MOV SBUF, A ; Send received data back
ACALL WAIT_FOR_TX_COMPLETE

SJMP MAIN ; Repeat indefinitely

WAIT_FOR_TX_COMPLETE: ; Wait for transmission to complete


JNB TI, WAIT_FOR_TX_COMPLETE
CLR TI
RET

WAIT_FOR_RX_COMPLETE: ; Wait for reception to complete


JNB RI, WAIT_FOR_RX_COMPLETE
CLR RI
RET

ORG 0x0030
SJMP MAIN ; Jump to main program

END
UART operation in 8051
Transmit mode:
1.Give power supply to ESA 51E kit Transmitter module
2. In ESA 51E kit make DIP switches 5 and 8 ON and short the 2 and 3 pins of
jumpers J2,J6 and J8 to work kit in serial mode.
3.Select My computer on windows right click on it select properties in that select
Hard ware in that select Device manager click on ports verify USB Serial port
(com6/com5)
4. Press RESET key on ESA 51E module ,”SERIAL” will be display on ESA 51E
kit
6. Click START on windows and select Term 51E
5. Press RESET key on ESA 51 E module kit then ESA 51E serial monitor v1.1
will be displayed on PC monitor.
6.Select Settings from the toolbar a window will be display in that verify Baud rate
9600 ,Data bits 8,stop bits 1,parity bits none and select port com6
7. Select download from tool bar Browse for the file SEND.hex click on open
{Down load Browse communication between 2 kitsESA51ESEND.hex}
8. A small window will be displayed in that at memory [P] [D] double click on ‘P’
program will be down loaded from 8000 memory location

26
SCITS ECE MICROCONTROLLER LAB

9.Make DIP switch 5 OFF then press RESET .ESA-51E will be displayed on kit
display.
10.Short the 1 and 2 pins of Jumpers J2,J6,J8 for keyboard mode.
11. Connect the keyboard to the ESA 51E trainer kit.
12. For execution press G8000 from keyboard press ENTER key .
Receive mode:
1.Give power supply to ESA 51E kit Receiver module
2. In ESA 51E kit make DIP switches 5 and 8 ON and short the 2 and 3 pins of
jumpers J2,J6 and J8 to work kit in serial mode.
3.Select My computer on windows right click on it select properties in that select
Hard ware in that select Device manager click on ports verify USB Serial port
(com5)
{My computer properties
HardwareDevice ManagerPortsUSB Serial
port(com5)}
4. Press RESET key on ESA 51E module ,”SERIAL” will be display on ESA 51E
kit
6. Click START on windows and select Term 51E
5. Press RESET key on ESA 51 E module kit then ESA 51E serial monitor v1.1
will be displayed on PC monitor.
6.Select Settings from the toolbar a window will be display in that verify Baud rate
9600 ,Data bits 8,stop bits 1,parity bits none and select port com5
7. Select download from tool bar Browse for the file RECIEVE.hex click on open
{Down load Browse
Communication between 2
kitsESA51ERECIEVE.hex}
8. A small window will be displayed in that at memory [P] [D] double click on ‘P’
program will be down loaded from 8000 memory location
9.Make DIP switch 5 OFF then press RESET .ESA-51E will be displayed on
ESA51E kit display.
10.Short the 1 and 2 pins of Jumpers J2,J6,J8 for keyboard mode.
11. Connect the keyboard to the ESA 51E trainer kit.
12. For execution press G8000 from keyboard press ENTER key .
13. Remove keyboard plug from ESA51E kit.
Communication:
14. Connect RS232 cable between ESA51E transmitter and Receiver.
15. Type any character on the keyboard key will be displayed on ESA51E
Receiver display.

RESULT: We can observe ESA 51E serial monitor v1.1 on monitor.

27
SCITS ECE MICROCONTROLLER LAB

4. Program using Interrupts to Generate Square wave 10kHZ Frequency on


P2.1 using timer 0 8051 in 8 bit auto reload mode and connect a 1kHz Pulse to
INT1 pin and Display on Port 0.assume crystal frequency as 11.0592 MHZ

1. Connect kit to CPU using RS-232 cable


2. Go to start in computer
3. Go to programs.
4. Go to Accessories.
5. Select communication in that Hyper Terminal give name example XX then
select comport then OK
6. Select stop bits :2 then press OK
7. Using kit keyboard Enter ‘R’ then press Enter key.
8. ANSHUMAN is displayed on the monitor.
9. Press ‘I’ from system keyboard.
10. SERIAL ? will be displayed on the kit.
11. Press Enter
12. PRTY will be displayed
13. Press any key from system keyboard
14. NOPR will be displayed on the monitor.
15.Pree Enter, HEX will be displayed on the monitor
16.Press Enter ,STRT will be displayed on the monitor.
17.Enter starting address of the program 6360
Address Opcode Label Mnemonic Comments
6000 74,00 MOV ; ACC=00H
6002 F5,90 A,#00 ; OUTPUT DATA ON PORT 1
6004 79,03 MOV 90,A ;R1=03H
6006 7A,FF MOV ;R2=FFH
6008 12,01,14 R1,#03 ;CALL DELAY
600B F4 MOV ;COMPLEMENT ACC
600C F5,90 R2,#FF ;OUTPUT DATA OF ACC ON PORT 1
600E 80,F4 LCALL ;CONTINUE IT BY JUMPING ON
0114 6004 LOCATION
CPL A
MOV 90,A
SJMP F4

RESULT: We observe square wave with 10KHZ frequency on CRO.

28
SCITS ECE MICROCONTROLLER LAB

Using 8051 Microcontroller Kit


1. Assemply Language Progrms to perform Arithmetic (Both Signed and
unsigned) 16 Bit data operations (byte and bit level operations),Logical
operations ,Rotate ,shift ,swap and branch instructions.
16 Arithmetic operations Microcontroller

 ADDITION
N1:4555H
N2:6575H
Address Opcode Label Mnemonics Comments
8000 74,55 MOV A,#55H ; Load 55H in A
8002 24,75 ADD A,#75H ;add 75H with A
8004 F5,41 MOV 41,A ; Load A in 41
8006 74,45 MOV A,#45 ; Load 45H in A
8008 34,65 ADD C,#65 ; ADD 65H with C
800A F5,42 MOV 42,A ; Load A in 42
808E 02,0f,00 LJMP ;Long jump

RESULT:
41: CAH
42: AAH

 SUBTRACTION
Address Opcode Label Mnemonics Comments
8000 74,55 MOV A,#55H ; Load 55H in A
8002 94,75 SUBB A,#75H ;sub 75H with A
8004 F5,41 MOV 41,A ; Load A in 41
8006 74,45 MOV A,#45 ; Load 45H in A
8008 94,65 SUBB C,#65 ; sub 65H in A
800A F5,42 MOV 42,A ; Load A in 42
808E 02,0f,00 LJMP ;Long jump
N1:4555H
N2:6575H

RESULT:
41: EOH 42: DFH

29
SCITS ECE MICROCONTROLLER LAB

 MULTIPLICATION:
Address Opcode Label Mnemonics Comments
8000 74,02 MOV A,#02H ; Load 02h in A
8002 75,F0,04 MOV B,#04H ; Load 04h in B
8005 A4 MUL AB ;Multiply A and B
8006 F5,41 MOV 41,A ;Move content of A into 40 location
8008 E5,F0 MOV A,B ;Move the content of B into A
800A F5,42 MOV 42,A ;Move the content A into 42
800C 74,03 MOV A,#03H location
800E 75,F0,04 MOV B,#04H ; Load 03h in A
8011 A4 MUL AB ; Load 04h in B
8012 25,42 ADD A,42 ; Multiply A and B
8014 F5,42 MOV 42,A ;Add A with content of 42 location
8016 50,02 JNC L ; Move content of A into 42
8018 05,F0 INC B location
801A E5,F0 L: MOV A,B :Jump if No carry
801C F5,43 MOV 43,A ;Increment B
801E 74,02 MOV A,#02H ; Move the content of B into A
8021 75,F0,05 MOV B,#05H ; Move content of A into 43
8024 A4 MUL AB location
8025 25,42 ADD A,42H ;Load 02h in A
8027 F5,42 MOV 42,A ; Load 05h in B
8029 50,02 JNC L1 ; Multiply A and B
802B 05,F0 INC B ; Add A with content of 42 location
802D E5,F0 L1: MOV A,B ; Move content of A into 42
802F F5,43 MOV 43,A location
8032 74,03 MOV A,#03 ; Jump if no carry
8034 75,F0,05 MOV B,#05 ;Increment B
8037 A4 MUL AB ; Move the content of B into A
8038 25,43 ADD A,43 ; Move content of A into 43
803A F5,43 MOV 43,A location
803C 50,02 JNC L2 ;Load 03h in A
803E 05,F0 INC B ; Load 05h in B
8031 E5,FO L2: MOV A,B ; Multiply A and B
8033 F5,44 MOV44,A ; Add A with content of 43 location
8035 02,0F,00 LJMP ; Move content of A into 43
location
; Jump if no carry
;Increment B
; Move the content of B into A
; Move content of A into 44
location
;Long Jump
30
SCITS ECE MICROCONTROLLER LAB

Result:
41 42 43 44
08 16 0F 00

 AND OPERATION:
Address Opcode Label Mnemonic Comments
8000 90,12,34 MOV ;DPTR-1234
8003 E5,83 DPTR,#1234 ;Move lower data into A
8005 54,FF MOVA,DPH ;A register data anded with FF
8007 F5,83 ANL A,#FFH ;Move result into DPH
8009 E5,82 MOV DPH,A ;Move DPL data into A
800A 54,00 MOV A,DPL ; A register data andede with FF
800C F5,82 ANL A,#00H ;Move the result into DPL
800E 02,0F,00 MOV DPL,A :End
LJMP

RESULT: DPTR(82,83) :1200H

 OR Operation
Address Opcode Label Mnemonic Comments
8000 90,12,34 MOV ;DPTR-1234
8003 E5,83 DPTR,#1234 ;Move lower data into A
8005 54,FF MOVA,DPH ;A register data OR with FF
8007 F5,83 ORL A,#FFH ;Move result into DPH
8009 E5,82 MOV DPH,A ;Move DPL data into A
800A 54,00 MOV A,DPL ; A register data andede with FF
800C F5,82 ORL A,#00H ;Move the result into DPL
800E 02,0F,00 MOV DPL,A :End
LJMP

RESULT: DPTR (82, 83) :FF34H

31
SCITS ECE MICROCONTROLLER LAB

 XOR Operation
Address Opcode Label Mnemonic Comments
8000 90,12,34 MOV ;DPTR-1234
8003 E5,83 DPTR,#1234 ;Move lower data into A
8005 54,FF MOVA,DPH ;A register data anded with FF
8007 F5,83 XRL A,#FFH ;Move result into DPH
8009 E5,82 MOV DPH,A ;Move DPL data into A
800A 54,00 MOV A,DPL ; A register data andede with FF
800C F5,82 XRL A,#00H ;Move the result into DPL
800E 02,0F,00 MOV DPL,A :End
LJMP

RESULT: DPTR (82, 83) :ED34 H

 Rotate and shift operation


Rote right or right shift
Address Opcode Label Mnemonic Comments
8000 90,12,34 MOV ;DPTR-1234
8003 E5,82 DPTR,#1234 ;Move lower data into A
8005 03 MOV A,DPL ;Rotate right operation on A
8006 F5,82 RR A ;Move A content into DPL
8008 E5,83 MOV DPL,A ;Move DPH data into A
800A 13 MOV A,DPH ; Rotate right through carry
800B F5,83 RRC A ;Move the result into DPH
800D 02,0F,00 MOV DPH,A :End
LJMP

RESULT: DPTR (82, 83): 091AH


Rotate left
Address Opcode Label Mnemonic Comments
8000 90,12,34 MOV ; DPTR-1234
8003 E5,82 DPTR,#1234 ; Move lower data into A
8005 23 MOV A,DPL ;Rotate left operation on A
8006 F5,82 RL A ;Move A content into DPL
8008 E5,83 MOV DPL,A ;Move DPH data into A
800A 33 MOV A,DPH ; Rotate left through carry
800B F5,83 RLC A ;Move the result into DPH
800D 02,0F,00 MOV DPH,A :End
LJMP

RESULT: DPTR (82, 83) : 2468H

32
SCITS ECE MICROCONTROLLER LAB

SWAP OPERATION

Address Opcode Label Mnemonic Comments


8000 90,12,34 MOV ;DPTR-1234
8003 E5,83 DPTR,#1234 ;Move DPH data into A
8005 F9 MOVA,DPH ;Move result into R1
8006 E5,82 MOV R1,A ;Move DPL data into A
8008 F5,83 MOV A,DPL ; Move the A content into DPH
800A 89,82 MOV DPH,A ;Move the R1 content into DPL
800C 02,0F,00 MOV DPL,R1 ;End
LJMP

RESULT: DPTR (82,83) :3412H

33
SCITS ECE MICROCONTROLLER LAB

CYCLE – 3

PROCEDURE
1) OPEN KEIL UVISION3
2) CLICK ON PROJECT
3) SELECT NEW UVISION PROJECT
4) SAVE WITH PROGRAM NAME
5) CLICK ON FILE
6) SELECT NEW
7) WRITTEN THE PROGRAM
8) SAVE THE PROGRAM WITH ASM EXTENTION
9) TARGET CREATED
10) CLICK ON SOURCE PROJECT
11) ADD FILES TO SOURCE
12) SAVE ALL AND BUILD ALL
13) RIGHT CLICK ON TARGET
14) ADD SOURCE TO TARGET
15) CLICK ON OUTPUT
16) CLICK ON HEX FILE
17) MAKE CONNECTIONS ON 8051 MICRO CONTROLLER KIT
18) SELECT NUVOTON SOFTWARE
19) SELECT BY IC
20) SELECT PORT
21) LOAD FILE( HEX FILE)
22) UPDATE CHIP
23) CLICK ON RESET BUTTON
24) FAIL CLICK K
25) SUCCESS CLICK OK

34
SCITS ECE MICROCONTROLLER LAB

1. 7 SEGMENT DISPLAY TO 8051

AIM: WRITE A ALP PROGRAMME TO INTERFACING 7 SEGMENT


DISPLAY TO 8051

APPARATUES REQUIRED:
i) 8051 microcontroller
ii) keil 3 software
iii) Nuvoton software

PROGRAM:
;P2.0-P2.3 CONNECT TO ROW--> O/P
;P2.4-P2.7 CONNECT TO COLUMNS --> I/O
/*
Port P1 to P5
Port P2 to P6
Port P4 to P7
*/
ORG 0000H
MOV P0,#00H
MOV P1,#00H

SETB P2.4
SETB P2.5
SETB P2.6
SETB P2.7
K1: MOV P2,#0F0H ;MAKE PORT 2 AN OUTPUT PORT
MOV A,P2 ;READ ALL COL.ENSURE ALL KEY ARE
OPEN
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#1111000B,K2 ;CHECK TILL ALL KEYS RELEASED

K2: ACALL DELAY ;CALL 20ms DELAY


MOV A,P2 ;SEE ANY KEY PRESSED
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,OVER ;KEY PRESSED,AWAIT CLOSURE
SJMP K2 ;CHECK KEY IS PRESSED

OVER: ;ACALL DELAY ;CALL 20ms


DELAY
MOV A,P2 ;CHECK KEY CLOSURE
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,OVER1 ;KEY PRESSED,FIND ROW
SJMP K2 ;IF NO KEY ,KEEP PULLING

35
SCITS ECE MICROCONTROLLER LAB

;CHECK ONE BY ONE ROW TO KEY PRESS OR NOT


OVER1: MOV P2,#11111110B ;GROUND ROW 0
MOV A,P2 ;READ ALL COLUMNS
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,ROW_0 ;KEY ROW 0,FIND THE COL.
MOV P2,#11111101B ;GROUND ROW 1
MOV A,P2 ;READ ALL COLUMNS
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,ROW_1 ;KEY ROW 1,FIND THE COL.
MOV P2,#11111011B ;GROUND ROW 2
MOV A,P2 ;READ ALL COLUMNS
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,ROW_2 ;KEY ROW 2,FIND THE COL.
MOV P2,#11110111B ;GROUND ROW 3
MOV A,P2 ;READ ALL COLUMNS
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,ROW_3 ;KEY ROW 3,FIND THE COL.

ROW_0: MOV DPTR,#KCODE0 ;SET DPTR=START OF ROW 0


SJMP FIND ;FIND COL.KEY BELONGS TO
ROW_1: MOV DPTR,#KCODE1 ;SET DPTR=START OF ROW 1
SJMP FIND ;FIND COL.KEY BELONGS TO
ROW_2: MOV DPTR,#KCODE2 ;SET DPTR=START OF ROW 2
SJMP FIND ;FIND COL.KEY BELONGS TO
ROW_3: MOV DPTR,#KCODE3 ;SET DPTR=START OF ROW 3
SJMP FIND ;FIND COL.KEY BELONGS TO

FIND: RR A ;GET UPPER NIBLE TO LOWER NOBLE


RR A
RR A
RR A
NEXT: RRC A ;SEE IF ANY CARRY BIT IS LOW
JNC MATCH ;IF ZERO GET SEVEN SEGMENT CODE
INC DPTR ;POINT TO NEXT COL. ADDRESS
SJMP NEXT ;KEEP SERCHING

MATCH: CLR A ;SET A=0


MOVC A,@A+DPTR ;GET 7-SEGMENT CODE FROM TABLE
MOV P1,A ;DISPLAY PRESSED KEY
LJMP K1

DELAY:
MOV R5,#0

36
SCITS ECE MICROCONTROLLER LAB

HERE1: MOV R4,#1


HERE2: MOV R3,#255
HERE3: DJNZ R3,HERE3
DJNZ R4,HERE2
DJNZ R2,HERE1
RET

;7-SEGMENT LOOK UP TABLE FOR EACH ROW


ORG 0300H

KCODE0: DB 06H,5BH,4FH,77H ;ROW 0


KCODE1: DB 66H,6DH,7DH,7CH ;ROW 1
KCODE2: DB 07H,7FH,6FH,39H ;ROW 2
KCODE3: DB 5EH,3FH,79H,71H ;ROW 3

END

RESULT:

2. MATRIX KEYPAD TO 8051

AIM: WRITE A ALP PROGRAMME TO INTERFACING MATRIX KEYPAD


TO 8051 MICROCONTROLLER

APPARATUES REQUIRED:
i) 8051 microcontroller
ii) keil 3 software
iii) Nuvoton software

PROGRAM:
;P2.0-P2.3 CONNECT TO ROW--> O/P
;P2.4-P2.7 CONNECT TO COLUMNS --> I/O
/*
Port P1 to P5
Port P2 to P6
Port P4 to P7
*/
ORG 0000H
MOV P0,#00H
MOV P1,#00H

37
SCITS ECE MICROCONTROLLER LAB

SETB P2.4
SETB P2.5
SETB P2.6
SETB P2.7
K1: MOV P2,#0F0H ;MAKE PORT 2 AN OUTPUT PORT
MOV A,P2 ;READ ALL COL.ENSURE ALL KEY ARE
OPEN
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#1111000B,K2 ;CHECK TILL ALL KEYS RELEASED

K2: ACALL DELAY ;CALL 20ms DELAY


MOV A,P2 ;SEE ANY KEY PRESSED
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,OVER ;KEY PRESSED,AWAIT CLOSURE
SJMP K2 ;CHECK KEY IS PRESSED

OVER: ;ACALL DELAY ;CALL 20ms


DELAY
MOV A,P2 ;CHECK KEY CLOSURE
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,OVER1 ;KEY PRESSED,FIND ROW
SJMP K2 ;IF NO KEY ,KEEP PULLING

;cHECK ONE BY ONE ROW TO KEY PRESS OR NOT


OVER1: MOV P2,#11111110B ;GROUND ROW 0
MOV A,P2 ;READ ALL COLUMNS
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,ROW_0 ;KEY ROW 0,FIND THE COL.
MOV P2,#11111101B ;GROUND ROW 1
MOV A,P2 ;READ ALL COLUMNS
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,ROW_1 ;KEY ROW 1,FIND THE COL.
MOV P2,#11111011B ;GROUND ROW 2
MOV A,P2 ;READ ALL COLUMNS
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,ROW_2 ;KEY ROW 2,FIND THE COL.
MOV P2,#11110111B ;GROUND ROW 3
MOV A,P2 ;READ ALL COLUMNS
ANL A,#11110000B ;MASKED UNUSED BITS
CJNE A,#11110000B,ROW_3 ;KEY ROW 3,FIND THE COL.

ROW_0: MOV DPTR,#KCODE0 ;SET DPTR=START OF ROW 0


SJMP FIND ;FIND COL.KEY BELONGS TO
ROW_1: MOV DPTR,#KCODE1 ;SET DPTR=START OF ROW 1

38
SCITS ECE MICROCONTROLLER LAB

SJMP FIND ;FIND COL.KEY BELONGS TO


ROW_2: MOV DPTR,#KCODE2 ;SET DPTR=START OF ROW 2
SJMP FIND ;FIND COL.KEY BELONGS TO
ROW_3: MOV DPTR,#KCODE3 ;SET DPTR=START OF ROW 3
SJMP FIND ;FIND COL.KEY BELONGS TO

FIND: RR A ;GET UPPER NIBLE TO LOWER NOBLE


RR A
RR A
RR A
NEXT: RRC A ;SEE IF ANY CARRY BIT IS LOW
JNC MATCH ;IF ZERO GET SEVEN SEGMENT CODE
INC DPTR ;POINT TO NEXT COL. ADDRESS
SJMP NEXT ;KEEP SERCHING

MATCH: CLR A ;SET A=0


MOVC A,@A+DPTR ;GET 7-SEGMENT CODE FROM TABLE
MOV P1,A ;DISPLAY PRESSED KEY
LJMP K1

DELAY:
MOV R5,#0
HERE1: MOV R4,#1
HERE2: MOV R3,#255
HERE3: DJNZ R3,HERE3
DJNZ R4,HERE2
DJNZ R2,HERE1
RET

;7-SEGMENT LOOK UP TABLE FOR EACH ROW


ORG 0300H

KCODE0: DB 06H,5BH,4FH,77H ;ROW 0


KCODE1: DB 66H,6DH,7DH,7CH ;ROW 1
KCODE2: DB 07H,7FH,6FH,39H ;ROW 2
KCODE3: DB 5EH,3FH,79H,71H ;ROW 3

END

RESULT:

39
SCITS ECE MICROCONTROLLER LAB

3. SEQUENCE GENERATOR USING SERIAL INTERFACE IN 8051

AIM: Write a ALP programme to interfacing sequence generator using serial


interface with 8051

APPARATUES REQUIRED:
i) 8051 microcontroller
ii) keil 3 software
iii) Nuvoton software

PROGRAM:

ORG 0x0000

MOV TMOD, #20H ; Timer1 mode2 (8-bit auto-reload) for baud rate
generation
MOV TH1, #0FDH ; Load Timer1 for 9600 baudrate
SETB TR1 ; Start Timer1
MOV SCON, #50H ; Mode1, 8-bit UART, enable receiver

MAIN:
MOV R1, #0 ; Initialize counter

SEND_SEQUENCE:
MOV A, R1 ; Load counter value to accumulator
ADD A, #30H ; Convert counter value to ASCII
MOV SBUF, A ; Send ASCII character over serial
ACALL DELAY ; Delay for a while
INC R1 ; Increment counter
CJNE R1, #10, SEND_SEQUENCE ; Repeat until counter reaches 10

ACALL DELAY_5_SECONDS ; Delay for 5 seconds


MOV R1, #0 ; Reset counter to 0
SJMP MAIN ; Jump back to main loop

DELAY: ; Delay subroutine


MOV R2, #250
D_LOOP:
DJNZ R2, D_LOOP
RET

DELAY_5_SECONDS: ; Delay subroutine for 5 seconds


MOV R3, #50
DELAY_LOOP:

40
SCITS ECE MICROCONTROLLER LAB

MOV R2, #250


D_LOOP_5S:
DJNZ R2, D_LOOP_5S
DJNZ R3, DELAY_LOOP
RET

ORG 0x0030
SJMP MAIN ; Jump to main program

END

RESULT

4. 8 BIT ADC TO 8051

AIM: WRITE A ALP PROGRAMME TO INTERFACING 8 BIT ADC WITH


8051

APPARATUES REQUIRED:
i) 8051 microcontroller
ii) keil 3 software
iii) Nuvoton software

PROGRAM:

;INTERFACING OF LIQUID CRYSTAL DISPLAY


;PLEASE READ THE MANUAL FOR HARDWARE DETAILS
/*
Port P1 to P15
Port P2 to P6
Port P4 to P9
*/

ORG 000H
RS BIT P0.4;RS=P0.4
RW BIT P0.5 ;RW=P0.5
E BIT P0.6 ;E=P0.6

BACK_LIGHT BIT P0.7


LCD_DATABUS EQU P1 ;LCD_DATABUS EQU P1
URD4 p1
ADC_DATABUS EQU P2 ;ADC_DATABUS EQU P2
URD4 P2

41
SCITS ECE MICROCONTROLLER LAB

MOV A,#38H ;INIT. LCD 2 LINES,5X7 MATRIX


ACALL COMMAND
MOV A,#0EH ;LCD ON CURSOL ON
ACALL COMMAND
MOV A,#01H ;CLEAR LCD COMMAND
ACALL COMMAND
MOV A,#06H ;SHIFT CURSOR RIGHT
ACALL COMMAND
SETB BACK_LIGHT

MOV A,#81H ;CURSOR LINE 1,POSITION 3


ACALL COMMAND

MOV A,#'A';DISPLAY LATTER


ACALL DATA_DISPLAY
MOV A,#'/' ;DISPLAY LATTER
ACALL DATA_DISPLAY
MOV A,#'D';DISPLAY LATTER
ACALL DATA_DISPLAY
MOV A,#' ' ;DISPLAY LATTER
ACALL DATA_DISPLAY
MOV A,#'C';DISPLAY LATTER
ACALL DATA_DISPLAY
MOV A,#'o' ;DISPLAY LATTER
ACALL DATA_DISPLAY
MOV A,#'n' ;DISPLAY LATTER
ACALL DATA_DISPLAY
MOV A,#'v' ;DISPLAY LATTER
ACALL DATA_DISPLAY
MOV A,#'e'
ACALL DATA_DISPLAY
MOV A,#'r' ;DISPLAY LATTER
ACALL DATA_DISPLAY
MOV A,#'t'
ACALL DATA_DISPLAY
MOV A,#'i'
ACALL DATA_DISPLAY
MOV A,#'o' ;DISPLAY LATTER
ACALL DATA_DISPLAY
MOV A,#'n'
ACALL DATA_DISPLAY

HERE:

42
SCITS ECE MICROCONTROLLER LAB

MOV A,#0C6H ;CURSOR LINE 2,POSITION 5


ACALL COMMAND

ACALL READ_ADC
ACALL DATA_CONVERTION
MOV A,42H
ADD A,#30H
ACALL DATA_DISPLAY
MOV A,41H
ADD A,#30H
ACALL DATA_DISPLAY
MOV A,40H
ADD A,#30H
ACALL DATA_DISPLAY

ACALL DELAY ;GIVE LCD SOME TIME


ACALL DELAY ;GIVE LCD SOME TIME
ACALL DELAY ;GIVE LCD SOME TIME

SJMP HERE ;STAY HERE

COMMAND:
MOV LCD_DATABUS,A ;ISSUE COMMAND CODE
CLR RS ;RS=0,FOR COMMAND
CLR RW ;RW=0,TO WRITE THE LCD
SETB E ;E=1,FOR H-L PULSE
ACALL DELAY ;GIVE LCD SOME TIME
NOP
CLR E ;E=0,LATCH IN
RET

DATA_DISPLAY:
MOV LCD_DATABUS,A ;ISSUE DATA
SETB RS ;RS=1 FOR DATA
CLR RW ;R/W=0,TO WRITE TO LCD
SETB E ;E=1 FOR H-L PULSE
ACALL DELAY1 ;GIVE LCD SOME TIME
CLR E ;E=0,LATCH IN
RET

READ_ADC:
MOV 30H,ADC_DATABUS
RET

43
SCITS ECE MICROCONTROLLER LAB

DATA_CONVERTION:
MOV A,30H
MOV B,#10
DIV AB
MOV 40H,B ;LSB BIT
MOV B,#10
DIV AB
MOV 41H,B
MOV 42H,A
RET

DELAY:
MOV R3,#250 ;R3=250
HERE2: MOV R4,#255 ;R4=255
HERE1: DJNZ R4,HERE1 ;STAY UNTIL R4 BECOME 0
DJNZ R3,HERE2
RET ;RETURN TO MAIN PROGRAM

DELAY1:
MOV R1,#50 ;R3=50
HERE4: MOV R2,#55 ;R4=55
HERE3: DJNZ R2,HERE3 ;STAY UNTIL R4 BECOME 0
DJNZ R1,HERE4
RET ;RETURN TO MAIN PROGRAM

END ;TERMINATE THE PROGRAM

RESULT:

5. TRAINGULAR WAVE GENERATOR THROUGH DAC


INTERFACES TO 8051

AIM : WRITE A ALP PROGRAMME TO INTERFACING DAC TO 8051


MICROCONTROLLER FOR GENERATING TRAINGULAR WAVE

APPARATUS REQUIRED:
i) 8051 microcontroller
ii) keil 3 software
iii) Nuvoton software
PROGRAM:

44
SCITS ECE MICROCONTROLLER LAB

;connect P1 to P10 and P4 to P12


;INTRFACING OF DAC TO GERATE NEGATIVE RAM WAVE
;PLEASE READ THE MANUAL FOR HARDWARE DETAILS
ORG 0000H ;START AT LOCATION 0000H
LED BIT P2.1 ;INDICATION LED LED L5 for Tringle
MOV A,#00H
MOV P0,A
MOV P2,A ; LED L5 for Tringle
SETB LED

START: MOV A,#00H ;LOAD STARTING VALUE


BACK: MOV P1,A ;GIVE INPUT TO DAC
ACALL DELAY ;CALLING DELAY
INC A ;INCREMENTING THE ACC.
CJNE A,#0FFH,BACK ;GENARATE THE POSITIVE RAMP
BACK1: MOV P1,A ;GIVE INPUT TO DAC
ACALL DELAY ;CALLING DELAY
DEC A ;DECREMENTING THE ACC.
CJNE A,#00H,BACK1 ;GENARATE THE POSITIVE RAMP
SJMP START ;REPET THE PROCESS

;------This is the delay subroutine


DELAY:
MOV R2,#0AH ;R2=255
HERE: DJNZ R2,HERE ;stay here until r2 becomes 0
RET ;Return to caller

END ;End of asm source file

RESULT:

CYCLE -4

45
SCITS ECE MICROCONTROLLER LAB

Procedure

1) Connect power supply to cortex processer kit


2) Open flash magic
3) Set baud rate 9600
4) Select device LPC1768
5) Interface with None ISP
6) Select com port by using device manager
7) Create correseponding program hex file
8) Select oscillator frequency 12Mhz
9) Browse for hex file and upload
10) Before start dumping make proper connections on kit
11) To make isp mode of kit frst click on ISP button hold it and press on reset
button ,release reset button then release ISP button
12) Start dumping and press on reset button again .

46
SCITS ECE MICROCONTROLLER LAB

1) BLINK AN LED WITH SOFTWARE DELAY ,DELAY GENERATED


USING THE SYS TICK TIMER

AIM : WRITE A C PROGRAMME TO DELAY GENERATED USING THE


SYS TICK TIMER CARRIED OUT ON CORTEX M3
DEVELOVEMENT BOARD S

APPARATUS REQUIRED :
1) LPC1768 cortex M3 Development Board.
2) Female to Female Jumper wires.
3) 12v/1.2 Ah Adaptor.
4) RS232 to USB converter for programming Cortex M3.
5) Power Jack.
6) KEIL 4 SOFTWARE
7) FLASH MAGIC

PROGRAMME:

#include <LPC17xx.h>

/* Systick Register address, refer datasheet for more info */


#define STCTRL (*( ( volatile unsigned long *) 0xE000E010 ))
#define STRELOAD (*( ( volatile unsigned long *) 0xE000E014 ))
#define STCURR (*( ( volatile unsigned long *) 0xE000E018 ))

/*******STCTRL bits*******/
#define SBIT_ENABLE 0
#define SBIT_TICKINT 1
#define SBIT_CLKSOURCE 2

/* 100000000Mhz * 1ms = 1000000 - 1 */


#define RELOAD_VALUE 99999

#define LED 0 //P2_0

int main (void)


{
SystemInit();

47
SCITS ECE MICROCONTROLLER LAB

STRELOAD = RELOAD_VALUE; // Reload value for 1ms tick

/* Enable the Systick, Systick Interrup and select CPU Clock Source */
STCTRL = (1<<SBIT_ENABLE) | (1<<SBIT_TICKINT) |
(1<<SBIT_CLKSOURCE);

LPC_GPIO2->FIODIR = (1<<LED); /* Configure the Led Pin as Output


*/

while(1)
{
//do nothing
}
}

void SysTick_Handler(void)
{
LPC_GPIO2->FIOPIN ^= (1<<LED); /* Toggle the LED1 (P2_0) */
}

RESULT:

2) SYSTEM CLOCK REAL TIME ALTERATION USING THE PLL


MODULES

AIM: WRITE A C PROGRAMME TO SYSTEM CLOCK REAL TIME


ALTERATION USING THE PLL MODULES CARRIEDOUT ON
CORTEX M3 PROCESSOR

APPARATUS REQUIRED :
1) LPC1768 cortex M3 Development Board.
2) Female to Female Jumper wires.
3) 12v/1.2 Ah Adaptor.
4) RS232 to USB converter for programming Cortex M3.
5) Power Jack.
6) KEIL 4 SOFTWARE
7) FLASH MAGIC

48
SCITS ECE MICROCONTROLLER LAB

PROGRAMME:
#include "uart.h"
#include "rtc.h"
#include "delay.h"

/* bit position of CCR register */


#define SBIT_CLKEN 0 /* RTC Clock Enable*/
#define SBIT_CTCRST 1 /* RTC Clock Reset */
#define SBIT_CCALEN 4 /* RTC Calibration counter enable */

int main()
{
uint16_t year;
uint8_t hour, min, sec, date, month;

SystemInit();

/* Initialize All the Four UARTs with different Baud rate */


UART0_Init(9600);
PLLinit();
/*
// Set Date 1 March 2024
LPC_RTC->DOM = 10; // Update date value
LPC_RTC->MONTH = 03; // Update month value
LPC_RTC->YEAR = 2024; // Update year value

// Set Time 10:40:25 AM


LPC_RTC->HOUR = 04; // Update hour value
LPC_RTC->MIN = 57; // Update min value
LPC_RTC->SEC = 00; // Update sec value */

while(1)
{
/* Read Time */
hour = LPC_RTC->HOUR;
min = LPC_RTC->MIN;
sec = LPC_RTC->SEC;

/* Read Date */
date = LPC_RTC->DOM;
month = LPC_RTC->MONTH;

49
SCITS ECE MICROCONTROLLER LAB

year = LPC_RTC->YEAR;
/*UARTx_Printf, where suffix "x" specifies the UART channel(0-3)*/
UART0_Printf("Time: %2d:%2d:%2d",hour,min,sec);
UART0_Printf(" Date: %2d/%2d/%4u",date,month,year);
DELAY_ms(1000);
UART_TxChar(0,0x0D); // Carriage return
UART_TxChar(0,0x0A); // New line
}
}

RESULT:

3) CONTROL INTENSITY OF AN LED USING PWM IMPLEMENTED


IN SOFTWARE AND HARDWARE

AIM : WRITE A C PROGRAMME TO CONTROL INTENSITY OF LED


WITH CORTEX PROCESSOR
APPARATUS REQUIRED :
1) LPC1768 cortex M3 Development Board.
2) Female to Female Jumper wires.
3) 12v/1.2 Ah Adaptor.
4) RS232 to USB converter for programming Cortex M3.
5) Power Jack.
6) KEIL 4 SOFTWARE
7) FLASH MAGIC

PROGRAMME:

#include <lpc17xx.h>
#include "pwm.h"
#include "delay.h"

#define CYCLE_TIME 255

/* start the main program */


int main()
{
int dutyCycle;
SystemInit(); /* Clock and PLL configuration */
PWM_Init(CYCLE_TIME); /* Initialize the PWM module and the Cycle
time(Ton+Toff) is set to 255(similar to arduino)*/

50
SCITS ECE MICROCONTROLLER LAB

PWM_Start(PWM_1); /* Enable PWM output on PWM_1-PWM_4 (P2_0 -


P2_3) */

while(1)
{
for(dutyCycle=0;dutyCycle<CYCLE_TIME;dutyCycle++) /* Increase the
Brightness of the Leds */
{
PWM_SetDutyCycle(PWM_1,dutyCycle); //P2_0
DELAY_ms(30);
}
DELAY_ms(2000);
for(dutyCycle=CYCLE_TIME;dutyCycle>0;dutyCycle--) /* Decrease the
Brightness of the Leds */
{
PWM_SetDutyCycle(PWM_1,dutyCycle); //P2_0
DELAY_ms(30);
}
DELAY_ms(2000);
}
}

RESULT:

4) CONTROL LED USING INTERRUPT METHOD AND FLASH THE


LED ONCE EVERY FIVE SWITCH PRESSES

AIM: WRITE A C PROGRAMME TO CONTROL THE LED BY INTERRUPT


METHOD

APPARATUS REQUIRED :
1) LPC1768 cortex M3 Development Board.
2) Female to Female Jumper wires.
3) 12v/1.2 Ah Adaptor.
4) RS232 to USB converter for programming Cortex M3.
5) Power Jack.
6) KEIL 4 SOFTWARE
7) FLASH MAGIC

51
SCITS ECE MICROCONTROLLER LAB

PROGRAM:

#include <lpc17xx.h>
#include "stdutils.h"
#include "gpio.h"
#include "extintr.h"

#define LED1 P2_0


#define LED2 P2_1

void myExtIntrIsr_0(void)
{
GPIO_PinToggle(LED1); /* Toggle the LED1 (P2_0) */
}

void myExtIntrIsr_1(void)
{
GPIO_PinToggle(LED2); /* Toggle the LED2 (P2_1) */
}

int main (void)


{
SystemInit();

GPIO_PinDirection(LED1,OUTPUT); /* Configure the pins as Output to


blink the Leds*/
GPIO_PinDirection(LED2,OUTPUT);

EINT_AttachInterrupt(EINT0,myExtIntrIsr_0,FALLING); /* myExtIntrIsr_0
will be called by EINT0_IRQHandler */
EINT_AttachInterrupt(EINT1,myExtIntrIsr_1,FALLING); /* myExtIntrIsr_1
will be called by EINT1_IRQHandler */

while(1)
{
//do nothing
}
}

RESULT:

52
SCITS ECE MICROCONTROLLER LAB

53

You might also like