Vous êtes sur la page 1sur 86

EX.

NO:1
ARITHMETIC OPERATION
DATE:

AIM:

To write an assembly language program for performing arithmetic operation using 8051 micro
controller.

APPARATUS REQUIRED:

• 8051 Microcontroller kit


• Power supply

ALGORITHM:

ADDITION:

Step 1: Start the process by initializing the starting address.


Step 2:Move the data from DPTR to accumulator and increment the address.
Step 3:Move the data from accumulator to B register.
Step 4:Move the data from address to accumulator and increment the DPTR.
Step 5:Add the data from B register to accumulator and the result stored into the
Accumulator.
Step 6:Move the result in accumulator to corresponding value.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOWCHART FOR ADDITION:

Start

Increment DPTR

Move the DPTR value to Areg

Add A and B

Store result in Areg

Increment DPTR

Move the value A to DPTR

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR ADDITION:

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 90
4101 45 Mov DPTR,#4500 Initialize the memory location
4102 00
Move the value from DPTR
4103 E0 Movx A,@DPTR
to A reg.
4104 A3 INC DPTR Increment DPTR
4105 F5 Move the value of B to A.
Mov B,A
4106 F0
Get the data and move to
4107 E0 Movx A,@DPTR
DPTR
4108 95
ADD A,B Add A and B
4109 F0
410A A3 INC DPTR Increment DPTR
410B F0 Movx @DPTR,A Move the result to DPTR
410C 80
410D HERE FE SJMP HERE Short jump to end

OUTPUT:

OPERATION ADDRESS DATA


INPUT 4500 10
4501 10
OUTPUT 4502 20

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
SUBTRACTION:

ALGORITHM:

Step 1:Start the process by initializing the starting address.


Step 2:Move the data from DPTR to accumulator and increment the address.
Step 3:Move the data from accumulator to B register.
Step 4:Move the data from address to accumulator and increment the DPTR.
Step 5:Subtract the data from B register to accumulator and the result stored into the
Accumulator.
Step 6:Move the result in accumulator to corresponding value.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOWCHART FOR SUBTRACTION:

Start

Move the data into DPTR

Move the DPTR value to Areg

Move the value of A to B

Increment DPTR

Move the DPTR value to A reg.

Subtract A and B

Store result in Areg

Increment DPTR

Move the value A to DPTR

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR SUBTRACTION

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 90
Initialize the memory
4101 45 Mov DPTR,#4500
location
4102 00
Mov the value from DPTR
4103 E0 Movx A,@DPTR
to A reg.
4104 A3 INC DPTR Increment DPTR
4105 F5
Mov B,A Move the value of B to A.
4106 F0
Get the data and move to
4107 E0 Movx A,@DPTR
DPTR
4108 95
SUBB A,B Subtract B from A
4109 F0
410A A3 INC DPTR Increment DPTR
410B F0 Movx @DPTR,A Move the result to DPTR
80
410C
HERE FE SJMP HERE Short jump to end
410D

OUTPUT:

OPERATION ADDRESS DATA


INPUT 4500 20
4501 10
OUTPUT 4502 10

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
MULTIPLICATION:

ALGORITHM:

Step 1:Start the process by initializing the starting address.

Step 2:Move the data from DPTR to accumulator and increment the address.

Step 3:Move the data from accumulator to B register.

Step 4:Move the data from address to accumulator and increment the DPTR.

Step 5:Multiply the data from B register to accumulator and the result stored into the
Accumulator.
Step 6:Move the result in accumulator to corresponding value.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOWCHART FOR MULTIPLICATION:

Start

Move the data into DPTR

Move the DPTR value to Areg

Move the value of A to B

Increment DPTR

Move the DPTR value to Areg

Multiply A and B

Store result in Areg

Increment DPTR

Move the value A to DPTR

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR MULTIPLICATION

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 90
4101 45 Mov DPTR,#4500 Initialize the memory location
4102 00
Mov the value from DPTR to
4103 E0 Movx A,@DPTR
A reg.
4104 A3 INC DPTR Increment DPTR
4105 F5
Mov B,A Move the value of B to A.
4106 F0
Get the data and move to
4107 E0 Movx A,@DPTR
DPTR
4108 A4 MUL A,B Multiply a and b
4109 A3 INC DPTR Increment DPTR
410A F0 Movx @DPTR,A Move the result to DPTR
80
410B
HERE FE SJMP HERE Short jump to end
410C

OUTPUT:

OPERATION ADDRESS DATA


INPUT 4500 14
4501 25
OUTPUT 4502 E4
4503 02

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
DIVISION:

ALGORITHM:

Step 1:Start the process by initializing the starting address.

Step 2:Move the data from DPTR to accumulator and increment the address.

Step 3:Move the data from accumulator to B register.

Step 4:Move the data from address to accumulator and increment the DPTR.

Step 5:Divide the data from B register to accumulator and the result stored into the
Accumulator.
Step 6:Move the result in accumulator to corresponding value.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOWCHART FOR DIVISION:

Start

Move the data into DPTR

Move the DPTR value to Areg

Move the value of A to B

Increment DPTR

Move the DPTR value to Areg

Divide A and B

Store result in Areg

Increment DPTR

Move the value A to DPTR

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR DIVISION:

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 90
4101 45 Mov DPTR,#4500 Initialize the memory location
4102 00
Mov the value from DPTR to A
4103 E0 Movx A,@DPTR
reg.
4104 A3 INC DPTR Increment DPTR
4105 F5
Mov B,A Move the value of B to A.
4106 F0
4107 E0 Movx A,DPTR Get the data and move to DPTR
4108 A4 DIV A,B Divide a by b
4109 A3 INC DPTR Increment DPTR
410A F0 Movx @DPTR,A Move the result to DPTR
80
410B
HERE FE SJMP HERE Short jump to end
410C

OUTPUT:

OPERATION ADDRESS DATA


INPUT 4500 06
4501 02
OUTPUT 4502 03

RESULT:

Thus the above program for Arithmetic Operations using 8051 Microcontroller was
successfully executed and Output was verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX.NO:2
LOGICAL OPERATION
DATE:

AIM:

To write an assembly language program for performing logical operation using 8051 micro
controller.

AND OPERATION:

ALGORITHM:

Step 1:Start the process by initializing the starting address.


Step 2:Move the data from DPTR to accumulator
Step 3:Perform AND operation with A and immediate data.
Step 4:Increment DPTR.
Step 5: Move the data from address to accumulator to DPTR.
Step 6:Stop the process.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOWCHART FOR AND OPERATION:

Start

Initializing DPTR

Move data from DPTR to acc

Perform AND operation A with


immediate data

Store the result

Increment DPTR

Move data A to DPTR

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR AND OPERATION

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 90
Initialize the memory
4101 45 Mov DPTR,#4500
location
4102 00
Mov the value from DPTR to
4103 E0 Movx A,@DPTR
A reg.
4104 54
ANL A,#20 Perform AND operation.
4105 20
4106 A3 INC DPTR Increment DPTR
4107 F0 Movx @DPTR,A Move the data A to DPTR
4108 80
HERE SJMP HERE Short jump here
4109 FE

OUTPUT:

OPERATION ADDRESS DATA

INPUT 4500 10

OUTPUT 4501 00

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
OR OPERATION:
ALGORITHM
Step 1:Start the process by initializing the starting address.
Step 2:Move the data from DPTR to accumulator

Step 3:Perform OR operation with A and immediate data.

Step 4:Increment DPTR.

Step 5: Move the data from address to accumulator to DPTR.

Step 6:Stop the process.

FLOWCHART FOR AND OPERATION:

Start

Initializing DPTR

Move data from DPTR to Acc

Perform OR operation A with


immediate data

Store the result

Increment DPTR

Move data A to DPTR

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR OR OPERATION

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 90
Initialize the memory
4101 45 Mov DPTR,#4500
location
4102 00
Mov the value from
4103 E0 Movx A,@DPTR
DPTR to A reg.
4104 54
ORL A,#20 Perform OR operation.
4105 20
4106 A3 INC DPTR Increment DPTR
Move the data A to
4107 F0 Movx @DPTR,A
DPTR
4108 80
HERE SJMP HERE Short jump here
4109 FE

OUTPUT:

OPERATION ADDRESS DATA

INPUT
4500 10
OUTPUT 4501 30

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
X-OR OPERATION:

ALGORITHM:

Step 1:Start the process by initializing the starting address.


Step 2:Move the data from DPTR to accumulator
Step 3:Perform X-OR operation with A and immediate data.
Step 4:Increment DPTR.
Step 5: Move the data from address to accumulator toDPTR.
Step 6:Stop the process.

FLOWCHART FOR AND OPERATION:

Start

Initializing DPTR

Move data from DPTR to Acc

Perform X-OR operation A with


immediate data

Store the result

Increment DPTR

Move data A to DPTR

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR X-OR OPERATION

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 90
Initialize the memory
4101 45 Mov DPTR,#4500
location
4102 00
Mov the value from DPTR
4103 E0 Movx A,@DPTR
to A reg.
4104 54
XRL A,#20 Perform XRL operation.
4105 20
4106 A3 INC DPTR Increment DPTR
4107 F0 Movx @DPTR,A Move the data A to DPTR
4108 80
HERE SJMP HERE Short jump here
4109 FE

OUTPUT:

OPERATION ADDRESS DATA

INPUT 4500 10

OUTPUT 4501 30

RESULT:

Thus the above program for Logical Operations using 8051 Microcontroller was
successfully executed and Output was verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX.NO:3
SQUARE& CUBE OF A NUMBER
DATE:

AIM:

To write an assembly language program to find square and cube of a number using 8051
micro controller.

APPARATUS REQUIRED:

• 8051microcontroller.
• Power supply

SQUARE OF A NUMBER

ALGORITHM:

Step 1:Start the process by initializing the starting address.

Step 2:Transfer the data to ax register.

Step 3:Store the data from ax register to data segment.

Step 4:Transfer the data to source in a register.

Step 5:Move the no of cl register.

Step 6:Multiply BL with ax value

Step 7:Move the data in Al register to source center.

Step 8:Decrement cl.

Step 9: Stop the process.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOWCHART FOR SQUARE OF A NUMBER:

Start

Move the data to DPTR

Move the DPTR value of A

R to Acc

Move the content of A & B

Multiply the two values

Increment DPTR

Move the A register value of DPTR

Move the data from B register from A


DPTR

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
ADDRESS LABEL OPCODE MNEMONICS COMMENT
4100 90
4101 45 MOV DPTR,#4500 Move 4500 to DPTR
4102 00
MOVE THE CONTROL AT
4103 E0 MOVX A,@DPTR
DPTR TO A
4104 A3
INC DPTR INCREMENT DPTR

4105 F5
MOV B,A MOVE A TO B
4106 F0
4107
A4 MUL AB MULTIPLY A&B

MOVE THE VALUE OF A


4108 F0 MOVX@DPTR,A
&DPTR
4109 A3 INC DPTR INCREMENT DPTR
410A E5
MOV A,B MOVE B TO A
410B F0
F0 MOVE THE VALUE AT A OF
411C MOVX@DPTR,A
DPTR
411D 80
HERE SJMP HERE Short jump here
411E FE

OUTPUT

OPERATION ADDRESS8 DATA


INPUT 4500 02
OUTPUT 4501 04

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
CUBE OF A NUMBER

ALGORITHM:

Step 1:Start the process by initializing the starting address.


Step 2:Move the data from DPTR to ac.
Step 3:Move the data from accumulator to b reg.
Step 4:Multiply data & data2 and store the value.
Step 5:Move the data from accumulator data to a reg.
Step 6:Move the data from DPTR to register.
Step 7:Move the data from register.
Step 8: Multiply data1 and data2 store the value, IncrementDPTR, Mov A register to DPTR,
Stop the process.

FLOW CHART FOR CUBE OF A NUMBER:

Start

Move the data to DPTR

To find a square of a number

Move the data to DPTR

Multiply with square of a number

Move the value to DPTR

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
Address Label Opcode Mnemonics comment
4100 90
4101 45 MOV DPTR,#4500 Move 4500 to DPTR
4102 00
MOVE THE CONTROL AT
4103 E0 MOVX A,@DPTR
DPTR TO A
4104 F5
MOV B,A Move A TO B

4105 F0
MUL AB MULTIPLY A AND B
4106 A4
4107 F8
MOV R0,A Move A TO R0

4108 E0 MOVE THE VALUE DPTR TO


MOVX A,@DPTR
A
4109
F5
MOV B,A MOV A VALUE TO B

410A F0
MOV A,R0 MOVE R0 TO A

410B
E8 MUL AB MULTIPLY A AND B

410C
A4 INC DPTR INCREMENT DPTR

410D
A3 MOVE THE VALUE A TO
410E MOVE @DPTR,A
F0 DPTR

410F HERE 80 SJMP HERE SJMP HERE

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
OUTPUT

OPERATION ADDRESS DATA


INPUT 4500 02
OUTPUT 4501 08

RESULT

Thus the above program for square and cube of a number using 8051 was executed
successfully and output verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX.NO:4
1’s AND 2’s COMPLEMENT
DATE:

AIM:

To write an assembly language program to find 1’s and 2’s complement of a given
numbers by using 8051 microcontroller.

APPARTUS REQUIRED:

• 8051 Micro controller kit.


• Power supply

ALGORITHM: 2’s COMPLEMENT


Step 1: start the process.
Step 2: move the value from DPTR to accumulator.
Step 3: Take complement of the given number.
Step 4: add 1 to the above result
Step 5: stop the process

FLOW CHART FOR 2’s COMPLEMENT:

Start

Move the data to DPTR

Take Complement of a Number

Add 1 to the above result

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR 2’s COMPLEMENT

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 90
4101 45 MOV DPTR,#4500 Move 4500 to DPTR
4102 00
Move the content at DPTR
4103 E0 MOVX A,@ DPTR
to A
4104 F4 CPL A Complement The value of a
4105 24A
ADD A,# 01 Add o1 with AL
4106 01
4107 A3 INC DPTR Increment DPTR
Move the value of A at
4108 F0 Movx @DPTR,A
DPTR
4109 80
HERE SJMP HERE Short jumb here
410A FE

OUTPUT:

OPERATION ADDRESS DATE


INPUT 4500 02
OUTPUT 4501 FE

1’S COMPLEMENT

ALGORITHM:

Step 1:start the process.


Step 2: move the value from DPTR to accumulator.
Step 3: Take complement of the given number.
Step 4: stop the process

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOW CHART FOR 1’s COMPLEMENT:

Start

Move the data to DPTR

Take Complement of a Number

Add 1 to the above result

Stop

PROGRAM FOR 1’s COMPLEMENT

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 90
4101 45 Initialize the locater
MOV DPTR,# 4500
4102 00
4103 E0 MOVX A,@ DPTR Get the data accumulator
4104 F4 CPL A Take compliment of the number
A3
4105 INC DPTR Increment DPTR

4106 F0 MOVX @DPTR,A Get the data in accumulator


80
4107 HERE SJMP HERE Short jump here
FE

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
OUTPUT:

OPERATION ADDRESS DATE


INPUT 4500 03
OUTPUT 4501 FC

RESULT:

Thus the above program for 1’s and 2’s complement was successfully executed and
output verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX.NO:5
SORTING OF AN ARRAY
DATE:

AIM:
To write an assembly language program to find the largest and smallest number using
8051 microcontroller kit

APPARATUS REQUIRED:
• 8051microcontroller.
• Power supply

LARGEST NUMBER

ALGORITHM:
Step1:Start the program.

Step2: Move the content from DPTR to the location 5000.

Step 3: Move the content from DPTR accumulator,

Step4: Increment from DPTR.

Step5: Carry jump not equal to the accumulator.

Step6: Decrement jump not equal from register to the up.

Step7: Stop the process

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOW CHART FOR LARGEST NUMBER:

Start

Move the content the location

Move the content register r2

Move the content from the DPTR to


accumulator

Increment DPTR

Move the DPTR

Carry jump not event from directory

Move the content from the directory

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR LARGEST NUMBER
ADDRESS LABEL OP CODE MNEMONICS COMMENT
4100 90
4101 45 MOV DPTR,#5000 Move 5000 to DPTR
4102 50
4103 C3 CLR C Clear carry
4104 7a
MOV r2,#03h Move r2
4105 2q
MOV a content of
4106 E0 MOVX a,@ DPTR
DPTR
4107 F5 Move the content
MOV 30h,a
4108 30 From a to 30 l1
Increment DPTR
4109 A3 INC DPTR
Move the content
410a E0 MOVX a,@ DPTR
DPTR
410b 85
Compare Jumb not
410c 30 CJNE,30h
Equal to
410d FD
410e 04 SJMP NEXT Start jump & next
4110 F4
DN JC NEXT Jump if carry to next
4111 Fe
4112 F5
MOV 30h,a Move a to 30
4113 36
4114 DA Decrement jump
DJNI R1,up
4115 F3 Set to zero
4116 A3 INC DPTR Increment DPTR
4117 E5 Move the content of
MOV A,30h
4118 30 30h to A
4119 F0 MOVX @ DPTR ,a Move A to DPTR
411A 80
SJMP HERE Short jump here
411B FE

OUTPUT:
OPERATION ADDRESS DATA
5000 05
5001 FA
INPUT
5002 91
5003 B2
5004
OUTPUT FA

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
SMALLEST NUMBER
ALGORITHM:
Step1:Start the program.
Step2: Move the content fromDPTR to the location 5000.
Step 3: Move the content from DPTR accumulator,
Step4: Increment from DPTR.
Step5: Carry jump not equal to the accumulator.
Step6: Decrement jump not equal from register to the up.
Step7: Stop the process

FLOW CHART FOR SMALLEST NUMBER

Start

Move the content the location

Move the content register r2

Move the content from the DPTR to


accumulator

Increment DPTR

Move the DPTR

Carry jump not event from directory

Move the content from the directory

Prepared
Start by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR SMALLEST NUMBER
ADDRESS LABEL OP CODE MNEMONICS COMMENT
4100 90
4101 45 MOV DPTR,#5000 Move 5000 to DPTR
4102 50
4103 C3 CLR C Clear carry
4104 7a
MOV r2,#03h Move r2
4105 2q
MOV a content of
4106 E0 MOVX a,@ DPTR
DPTR
4107 F5 Move the content
MOV 30h,a
4108 30 From a to 30 l1
Increment DPTR
4109 A3 INC DPTR
Move the content
410a E0 MOVX a,@ DPTR
DPTR
410b 85
Compare Jumb Not
410c 30 CJNE,30h
Equal to
410d FD
410e 04 SJMP NEXT Start jump & next
4110 F4 Jump if carry is zero
DN JNC NEXT
4111 Fe next
4112 F5
MOV 30h,a Move a to 30
4113 36
4114 DA Decrement jump
DJNI R1,up
4115 F3 Set to zero
4116 A3 INC DPTR Increment DPTR
4117 E5 Move the content of
MOV A,30h
4118 30 30h to A
4119 F0 MOVX @ DPTR ,a Move A to DPTR
411A 80
SJMP HERE Short jump here
411B FE

OUTPUT:
OPERATION ADDRESS DATA
5000 05
5001 FA
INPUT
5002 91
5003 B2
OUTPUT 5004 05
RESULT:
Thus the above program for largest and smallest number was successfully executed and
the output was verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX NO:6 SORTING
DATE :

AIM

To arrange the numbers in ascending order using 8051 micro controller kit.

APPARTUS REQUIRD

• 8051Microcontroller kit.
• Power supply

ASSENDING ORDER

ALGORITHM

Step 1:Start the process


Step 2:Enter the input values to DPTR.
Step 3:Using 2 looping statements to arrange the input values to ascending order.
Step 4:Execute the program to arrange input number.
Step 5:Stop the process.

FLOW CHART FOR ASSENDING ORDER

Start

Enter input values to DPTR

Using 2 loops to arrange the input values

Execute the program

Prepared by
Mr. J. Stop
Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR ASSENDING ORDER

ADDERS LABEL OPCODE MNEMONICS COMMENTS


4100 7C
MOV R4,#04 move immediate value 04 to r4
4101 04
4102 7B
AGAIN MOV R3,#04 move immediate value 04 to r3
4103 04
4104 96
move immediate value 4500 to
4105 45 MOV DPTR,#4500
DPTR
4106 00
4107 C3 CLRC clear carry
4108 E0 MOVX A,@DPTR move DPTR to a
4109 EA MOV R1,A move value a to r1
410A A3 INC DPTR increment DPTR
410B E0 MOVX A,@DPTR move DPTR to a
410C 99 SUBB A,R1 subtract a,r1
410D 50
JNC SKIP jump on not carry
410E FE
410F E0 MOVX A,@DPTR move DPTR value
4110 F8 SUB A,R1 subtract a,r1
4111 15
INC SKIP jump on next
4112 82
4113 E0 MOVX A,@DPTR move DPTR to a
4114 08 XCH A,R0 exchange a,r0
4115 F0 MOVX @DPTR,A move a to DPTR
4116 05
INC DPL increment DPTR
4117 82
4118 E8 MOV A,R0 move r0 to a
4119 F0 MOV X @DPTR,A move a to DPTR
411A DC
SKIP DJNZ R3,UP decrement jump non zero
411B FC
411D DC decrement jump
DJNZ R4,AGAIN
411E E4 non zero
80
411F HERE SJMP HERE start jump here
FE

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
OUTPUT

OPERATION ADDRESS DATA


4500 06
4501 04
INPUT 4502 08
4503 03
4504 09
4500 03
4501 04
OUTPUT 4502 06
4503 08
4504 09

DESCENDING ORDER
ALGORITHM
Step 1:Start the process
Step 2:Enter the input values to DPTR.
Step 3:Using 2 looping statements to arrange the input values to descending order.
Step 4:Stop the process.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOW CHART FOR DECENDING ORDER
Start

Enter input values to DPTR

Using 2 loops to arrange the input values

Execute the program

Stop

PROGRAM FOR DECENDING ORDER

ADDERS LABEL OPCODE MNEMONICS COMMENTS


4100 7C move immediate
MOV R4,#04
4101 04 value 04 to r4
4102 7B move immediate
AGAIN MOV R3,#04
4103 04 value 04 to r3
4104 96 move immediate
4105 45 MOV DPTR,#4500 value 4500 to
4106 00 DPTR
4107 C3 CLRC clear carry
4108 E0 MOVX A,@DPTR move DPTR to A
4109 EA MOV R1,A move value A to R1
410A A3 INC DPTR increment DPTR
410B E0 MOVX A,@DPTR move DPTR to A
410C 99 SUBB A,R1 subtract A,R1
410D 50
JC SKIP jump on not carry
410E FE
move DPTR value
410F E0 MOVX A,@DPTR
to A
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
4110 F8 MOV R0,A move A to R1
4111 15
DEC DPL decrement DPL
4112 82
4113 E0 MOVX A,@DPTR move DPTR to a
4114 08 XCH A,R0 exchange a,r0
4115 F0 MOVX @DPTR,A move a to DPTR
4116 05
INC DPTR increment DPL
4117 82
4118 E8 MOV A,R0 move R0 to a
4119 F0 MOV X @DPTR,A move a to DPTR
411A DC decrement jump non
SKIP DJNZ R3,UP
411B FC zero
411D DC decrement jump
DJNZ R4,AGAIN
411E E4 non zero
80
411F HERE SJMP HERE start jump here
FE

OUTPUT

OPERATION ADDRESS DATA


4500 05
4501 07
INPUT 4502 06
4503 08
4504 09
4500 09
4501 08
OUTPUT 4502 07
4503 06
4504 05
RESULT

Thus the above program for ascending order and descending order was executed
successfully and the output was verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX.NO:7
MATRIX AND ADDITION AND SUBTRACTION
DATE:

AIM:

To write an assembly language program for matrix addition and subtraction using 8051
micro controller.

APPARATUS REQUIRED:

• 8051microcontroller.
• Power supply

MATRIX ADDITION

ALGORITHM:

Step1: Start the program.

Step2: Declare the value for the data pointer for higher and lower bit.

Step 3:Get the value in address 4500 and move to the accumulator,

Step4: Move the value in 4500 to r0.

Step5: Get the value in address 4600 and move the value to the accumulator.

Step6: Add the value in R0 and accumulator.

Step7: Store the value in the address 4700

Step8: Increment DPL.

Step 9:Stop the process

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOW CHART FOR MATRIX ADDITION:

Start

Get input values on matrix 1

Get input values on matrix 2

Add Matrix 1 & Matrix 2

Store result in Matrix 3

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR MATRIX ADDITION:

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 7A Move the value
MOV R2,#09
4101 09 09 to R2
4102 75
Move the value
4103 82 MOV DPL,#00
00 to DPL
4104 00
4105 75
Move the value
4106 83 MOV DPH,#45
45 to DPH
4107 45
Move DPTR
4108 E0 MOV A,@DPTR
value into A
4109 F8 MOV R0,A Move A to R0
410A 75
Move the value
410B 83 MOV DPH#46
46 to DPH
410C 46
Move DPTR
410D E0 MOVX A,@DPTR
value into A
410E 28 ADD A,R0 Addition A&R0
410F 75
Move the value
4110 83 MOV DPH,#47
47 to DPH
4111 47
Move the value
4112 F0 MOVX @DPTR,A
A to DPTR
4113 05
INC DPL Increment DPL
4114 82
4115 DA Decrement Jump
DJNZ R2,SKIP
4116 EE Non Zero in R2
4117 80
HERE SJMP HERE Start Jump Here
4118 FE

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
OUTPUT

OPERATION ADDRESS DATA


4500 02
4501 02
4502 02
4503 02
INPUT 4504 02
(Matrix 1) 4505 02
4506 02
4507 02
4508 02
4600 02
4601 02
4602 02
4603 02
(Matrix 2) 4604 02
4605 02
4606 02
4607 02
4608 02
4700 04
4701 04
4702 04
4703 04
OUTPUT 4704 04
(Matrix 3) 4705 04
4706 04
4707 04
4708 04

MATRIX SUBTRACTION

ALGORITHM:
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
Step1: start the program.

Step2: declare the value for the data pointer for higher and lower bit.

Step 3:get the value in address 4500 and move to the accumulator,

Step4: move the value in 4500 to r0.

Step5: get the value in address 4600 and move the value to the accumulator.

Step6: subtract the value in R0 and accumulator.

Step7: store the value in the address 4700

Step8: increment DPL.

Step 9: stop the process

FLOW CHART FOR MATRIX SUBTRACTION:

Start

Get input values on matrix 1

Get input values on matrix 2

Subtract Matrix 1 & Matrix 2

Store result in Matrix 3

Stop

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR MATRIX SUBTRACTION:

ADDRESS LABEL OPCODE MNEMONICS COMMENT


4100 7A Move the value 09
MOV R2,#09
4101 09 to R2
4102 75
Move the value 00
4103 82 MOV DPL,#00
to DPL
4104 00
4105 75
Move the value 45
4106 83 MOV DPH,#45
to DPH
4107 45
Move DPTR value
4108 E0 MOV A,@DPTR
into A
4109 F8 MOV R0,A Move A to R0
410A 75
Move the value 46
410B 83 MOV DPH#46
to DPH
410C 46
Move DPTR value
410D E0 MOVX A,@DPTR
into A
410E 98 SUBB A,R0 Subtraction
410F 75
Move the value 47
4110 83 MOV DPH,#47
to DPH
4111 47
Move the value A to
4112 F0 MOVX @DPTR,A
DPTR
4113 05
INC DPL Increment DPL
4114 82
4115 DA Decrement Jump
DJNZ R2,SKIP
4116 EE Non Zero in R2
4117 80
HERE SJMP HERE Start Jump Here
4118 FE
OUTPUT
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
OPERATION ADDRESS DATA
4500 02
4501 02
4502 02
4503 02
INPUT 4504 02
(Matrix 1) 4505 02
4506 02
4507 02
4508 02
4600 01
4601 01
4602 01
4603 01
4604 01
(Matrix 2) 4605 01
4606 01
4607 01
4608 01
4700 01
4701 01
4702 01
4703 01
OUTPUT 4704 01
(Matrix 3) 4705 01
4706 01
4707 01
4708 01

RESULT:

Thus the above program for matrix addition and subtraction using 8051 microcontroller
was successfully executed and output was verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX: NO: 8

DATE: STEPPER MOTOR

AIM

To write assembly language Program to initialize stepper motor with 8051


microcontroller to run motor at different speed.

APPARATUS REQUIRED

• Stepper motor
• 8051 microcontroller.

ALGORITHM

Step 1: Start the process

Step 2: initialize the value in DPTR pointer

Step 3: initialize delay for rotation

Step 4: Repeat the program till the counter value becomes zero

Step 5: stop the process

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
FLOWCHART FOR STEPPER MOTOR

START

INITIALIZE DPTR

INITIALIZE COUNT VALUE

INITIALIZE DELAY

CHECK REPEAT THE


FOR 0 PROCESS

YES

INCREMENT DPTR

NO
DECREMENT RO, LOOP

STOP

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR STEPPER MOTOR INTERFACE

LABEL OP CODE MNEMONICS


ADDRESS
4100 90
4101 45
START MOV DPTR, #4500
4102 00
4103 78
MOV R0, #044
4104 04
4105 JO EO MOVX A, @DPTR
4106 FC MOV R4, A
4107 CO
PUSH DPH
4108 83
4109 CO
PUSH DPL
410A 82
410B 90
410C FF MOV DPTR, #FFCOh
410D CO
410E FO MOVY @DPTR, A
410F 12
4110 41 LCALL DELAY
4111 23
4112 90
4113 FF .
MOV DPTR, #FFC8h
4114 C8
4115 EC MOV A1 R4
4116 FO MOVX @DPTR, A
4117 12
4118 41 LCALL DELAY
4119 23
411A DO
POP DPL
411B 82
411C DO
POP DPH
411D 83
411E A3 INC DPTR
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
411F D8
DJNZ R0,J0
4120 E4
4121 80
SJMP START
4122 DD
4123 DELAY 7A MOV R2,#04h
4124 04
4125 79
L0 MOV R1, #FFh
4126 FF
4127 7B
L1 MOV R1, #FFh
4128 FF
4129 DB
L2 DJNZ R3,L2
412A FE
412B D9
DJNZ R1,L1
412C FA
412D DA
DJNZ R2,L0
412E F6
412F 22 RET
4130 80
HERE SJMP HERE
4131 FE

LOOK UP TABEL

ADDRESS DATA IN CLOCKWISE DATA OUT ANTICLOCKWISE


4500 09 0A
4501 05 06
4502 06 05
4503 0A 09

In order to increase the speed of motor delay has to be decreases and in order to decrease the
speed the delay has to be increased

RESULT

Thus the above program stepper motor interface control was successfully executed and
output verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX: NO: 9
DATE : BLINKING OF OF LED’s CONNECTED THROUGH PORTS

AIM

To develop a ‘C’ program to make the LED blink (including delay routine).Upon change
in the delay program the speed should vary.

APPARATUS REQUIRED

• VSK-SCM4 Development board


• IAR IDE software
• Flash Loader Demonstrator

THEORY

LEDs are based on the semiconductor diode. When the diode is forward biased (switched
on), electrons are able to recombine with holes and energy is released in the form of light. This
effect is called electroluminescence and the color of the light is determined by the energy gap of
the semiconductor.

PROCEDURE

5. Follow the steps 1 of How to create a New project

6. Type the below code and save it with the name (anyname.c)

7. Follow the steps 2 to 6 of Howto create a New Project to add the necessary file , compile
and built the program

8. Follow the procedures in How to Download a Code to Our Controller to download your
code

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR BLINKING LED

#include "stm32f4xx.h"

#include <stdio.h>

#include "stm32f4xx_rcc.h"

voidLED_init();

/* delay function */

void delay(long int a)

longintb,c;

for(b=0;b<a;b++)

for(c=0;c<a;c++);

/*main function starts here */

void main()

LED_init(); //LED initialization

while(1)

GPIOD->ODR =0x00000F00; //leds turns ON

delay(3000); //delay

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
GPIOD->ODR =0x00000000; //leds turns OFF

delay(3000); //delay

voidLED_init()

RCC->AHB1ENR = 1 <<3; //enable the clock to port D

GPIOD->MODER = 0x55555555; //select all pins as output mode

GPIOD->OTYPER =0x00000000; //push-pull type

GPIOD->OSPEEDR =0xAAAAAAAA; //50MHz speed

GPIOD->PUPDR =0x00000000; //no pull-up no pull down

PROCEDURE TO VIEW THE RESULT

1. Set your board to the execution mode and reset it.

2.The four LEDs on the board will toggle with a delay.

RESULT

The C-Language program to make the LED blink was developed and output was verified.
Upon change in the delay program the speed variation was verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX.NO:10
INTERFACING LED AND PWM
DATE:

AIM:

To write a C program to generate a PMW and to vary the brightness of the LED
depending on the duty cycle.

APPARATUS & SOFTWARE REQUIRED

• VSK_SCM4 Development board.


• IAR IDE software.
• Flash Loader Demonstrator.
• CRO.
• LED board setup.

THEORY

The PMW is the based on the standard timer block and inherits all of its features. The
timer is designed to count cycles of the peripheral clock (PCLK) and optionally generate
interrupts or perform other actions when specified timer values occur, based on seven match
registers. The PWM function is also based on match register event

PROCEDURE

1. Follow the steps 1 of How to create a New project


2. Type the below code and save it with the name (anyname.c)
3. Follow the steps 2 to 6 of how to create a New project to add the necessary file, compile
and build the program.
4. Follow the procedures in How to Download a code to Our Controller to download your
code.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM FOR LED AND PWM:

/* Includes ------------------------------------------------------------------*/
#include "stm32f4xx.h"
#include <stdio.h>
uint16_tPrescalerValue = 0;
staticintduty_cycle =1 ;
int duty;
/* Private function prototypes -----------------------------------------------*/
void TIM10_Config(void);
void TIM11_Config(void);
void TIM3_Config(void);
void delay(int delay);
intswitch_read();
voidmx_pinout_config(void);
void USART2_config();
/* main functions ---------------------------------------------------------*/
int main(void)
{
USART2_config();
TIM3_Config();
while(1)
{
duty = switch_read(); //receive switch value
/* for debug purpose */
// printf("\n duty =%d",duty);
/* Compute the prescaler value */
PrescalerValue = (uint16_t) ((SystemCoreClock /2) / 21000000) - 1; //21MHZ timer/counter
clock
TIM3->ARR =0x348;//25khz
TIM3->PSC =PrescalerValue;
TIM3->CR1 = 0<<8|0<<9;

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
TIM3->CCMR1 = 1<<4|1<<5|1<<6;
TIM3->CCER |= 1<<0|1<<1; //enable capture/compare2
TIM3->CCR1 = duty; // apply duty cycle
TIM3->CCMR1 = 1<<3; //enable channel1 preload register
TIM3->CCMR1 = 1<<12|1<<13|1<<14;
TIM3->CCER |= 1<<4|1<<5; //enable capture/compare2
TIM3->CCR2 = duty; // apply duty cycle
TIM3->CCMR1 = 1<<11; //enable channel2 preload register
/* TIM10 enable counter */
TIM3->CR1 =1<<0;
}
}
void TIM3_Config(void)
{
RCC->APB1ENR |=1<<1;
RCC->AHB1ENR |=1<<2;
GPIOC->MODER |=0x0000A000;
GPIOC->AFR[0]|=0x22000000;
}
intswitch_read()
{
intval;
mx_pinout_config();
val = ((GPIOE->IDR)&0x14);
if(val == 0x04)
{
if(duty_cycle<= 0)
{
duty_cycle =1;
}
duty_cycle--; //variable decrement
delay(250);
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
}
else if(val == 0x10)
{
duty_cycle++; //variable increment
delay(250);
if(duty >= 1500)
{
duty =1500;
}
}

return(duty_cycle);
}
intputchar(int data)
{
USART2->DR = (data & 0x01FF);
/* Loop until the end of transmission */
while((USART2->SR & 0x40) ==0)
{}
return data;
}
voidmx_pinout_config(void)
{
/*Enable or disable the AHB1 peripheral clock */
RCC->AHB1ENR |= 1<<3; // enable the clock to portD
RCC->AHB1ENR |= 1<<4; //enable clock to portE
GPIOE->MODER |=0x00000000; //set portE as i/p mode,other pins are input moode
GPIOE->OTYPER =0x00000000;
GPIOE->PUPDR = 0x00000000;
GPIOE->OSPEEDR =0xAAAAAAAA;
}
void USART2_config()
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
{
RCC->AHB1ENR |= 1 << 0; //clock to PORTA
RCC->APB1ENR |= 1 <<17; //clock to USART2
GPIOA->MODER |= 0x000000A0; //AF mode
GPIOA->AFR[0] |= 0x00007700; //USART2 AF
USART2->BRR = 0x16D;//115200 baud rate
USART2->CR3 = 0x0000;
USART2->CR2 = 0x000;
USART2->CR1 = 0x200C;
}
void delay(int delay)
{
int d1,d2;
for(d1=0;d1<delay;d1++)
for(d2=0;d2<delay;d2++);
}

PROCEDURE TO SEE OUTPUT:

1.Set your board to the execution mode and reset it.

2. Connect the +ve terminal of the LED board to the connector and – ve terminal to GND.

3. On varying the duty cycle of the PWM, the intensity of the LEDs will vary.

4. To increase the duty cycle press SW2 and to decrease, SW5.

RESULT:

The C program to vary the intensity of the LED depending on the duty cycle of the PWM
has been developed and is verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX.NO:11
RELAY CONTROL
DATE:

AIM:

To write a C program to generate a relay signal and to vary the sound duration depending
on the duty cycle.

APPARATUS & SOFTWARE REQUIRED

• VSK_SCM4 Development board.


• IAR IDE software.
• Flash Loader Demonstrator.
• CRO.
• RELAY board setup.

THEORY

The PMW is the based on the standard timer block and inherits all of its features. The
timer is designed to count cycles of the peripheral clock (PCLK) and optionally generate
interrupts or perform other actions when specified timer values occur, based on seven match
registers. The PWM function is also based on match register event

PROCEDURE

5. Follow the steps 1 of How to create a New project


6. Type the below code and save it with the name (anyname.c)
7. Follow the steps 2 to 6 of how to create a New project to add the necessary file, compile
and build the program.
8. Follow the procedures in How to Download a code to Our Controller to download your
code.

PROGRAM FOR RELAY CONTROL:


Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
#include "stm32f4xx.h"

#include "stm32f4xx_usart.h"

#include "stm32f4xx_syscfg.h"

#include "stm32f4xx_gpio.h"

#include "misc.h"

#include <stdio.h>

unsigned char d1[] = {" WELCOME "};

unsigned char d2[] = {" Press any Key"};

inti,val;

enum { high =1,low = !high };

uint32_ttmp;

unsigned char r1_char[];

void USART2_config()

NVIC_InitTypeDefNVIC_InitStructure;

RCC->AHB1ENR |= high << 0;

RCC->APB1ENR |= high <<17;

GPIOA->MODER |= 0x000000A0;

GPIOA->AFR[0] |= 0x00007700;

//USART2->BRR = 0x16D; //115200

USART2->BRR = 0x1117; //9600 XBEE ONLY

USART2->CR3 = 0x0000;
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
USART2->CR2 = 0x000;

USART2->CR1 = 0x200C;

USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure); }

void delay(int a)

inti,j;

for(i=0;i<a;i++)

for(j=0;j<a;j++);

voidbusy_check()

delay(200);

GPIOE->BSRRH = 0x0020; //low the RS pin

GPIOE->BSRRH = 0x0040; //low RW pin

voidcommand_write(intcomm)

busy_check();

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
GPIOE->BSRRH = 0x0020; //low RS pin

GPIOE->ODR = (comm<<8)|(0<<5); //write the data from 8th bit.(i.E) PG8 to PG15

GPIOE->BSRRL = 0x0080; //enable pin high

delay(200);

GPIOE->BSRRH = 0x0080; //enable pin low

/*LCD initial commands */

voidlcd_init()

command_write(0x38);

command_write(0x01);

command_write(0x0f);

command_write(0xC0);

command_write(0x06);

voidlcd_out(unsigned char a)

busy_check();

GPIOE->BSRRL = 0x0020; //high RS pin

GPIOE->ODR = (a<<8)|(1<<5); //write the data from 8th bit.(i.E) PG8 to PG15

GPIOE->BSRRL = 0x0080;//enable pin high

delay(200);
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
GPIOE->BSRRH = 0x0080;//enable pin low

voidlcd_stringout(unsigned char *gk)

int i;

busy_check();

GPIOE->BSRRL = 0x0020; //high RS pin

for(i=0;gk[i] !='\0';i++)

GPIOE->ODR =(gk[i]<<8)|(1<<5); //write the data from 8th bit.(i.E) PG8 to PG15

GPIOE->BSRRL = 0x0080;//enable pin high

delay(200);

GPIOE->BSRRH = 0x0080;//enable pin low

voidmx_pinout_config(void)

RCC->AHB1ENR |= 1<<3; // enable the clock to portF

RCC->AHB1ENR |= 1<<4; //enable clock to portB,C,G

RCC->AHB1ENR |= 1<<2; //enable clock to portB,C,G

RCC->AHB1ENR |= 1<<1; //Enable clock to portB

GPIOD->MODER |=0x00550055; //set port D0-D3 as o/p mode,other pins are input moode
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
GPIOD->OTYPER =0x00000000;

GPIOD->PUPDR = 0x00000000;

GPIOD->OSPEEDR =0xAAAAAAAA;

GPIOB->MODER = 0x55555555;

GPIOB->OSPEEDR = 0xFFFFFFFF;

GPIOC->MODER = 0x00050000; //PC9 as o/p mode

GPIOC->PUPDR = 0xAAAAAAAA; //no pull-up,pull-down

GPIOC->OSPEEDR = 0xAAAAAAAA; //spedd is 50MHZ

GPIOE->MODER = 0X55555555; // lcd_pins OUTPUT MODE SELECT

GPIOE->OTYPER = 0x00000000;

GPIOE->PUPDR = 0x00000000;

GPIOE->OSPEEDR = 0xAAAAAAAA;

GPIOE->ODR = 0x00000000;

voidxbee_tx()

/////////////////////////// 1 Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

GPIOD->BSRRH = 0x0001; //high PD0

GPIOD->BSRRL = 0x000E; //low PD1 to PD3

val = (GPIOD->IDR)&0xF0; //status of D4 to D7

if(val == 0xE0) //1st column

{
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("C");

USART2->DR = 0x43;

while((USART2->SR & 0x40)==0);

else if(val== 0xD0) //2nd column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("D");

USART2->DR = 0x44;

while((USART2->SR & 0x40)==0);

else if(val== 0xB0) //3rd column


Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
{

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("E");

USART2->DR = 0x45;

while((USART2->SR & 0x40)==0);

else if(val== 0x70) //4th column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("F");

USART2->DR = 0x46;

while((USART2->SR & 0x40)==0);

}
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
/////////////////////////// 2 Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

GPIOD->BSRRH = 0x0002; //low PD0

GPIOD->BSRRL = 0x000D; //low PD0

val = (GPIOD->IDR)&0xF0; //status of D4 to D7

if(val == 0xE0) //1st column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("8");

USART2->DR = 0x38;

while((USART2->SR & 0x40)==0);

else if(val== 0xD0) //2nd column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
command_write(0xc8);

lcd_stringout("9");

USART2->DR = 0x39;

while((USART2->SR & 0x40)==0);

else if(val== 0xB0) //3rd column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("A");

USART2->DR = 0x41;

while((USART2->SR & 0x40)==0);

else if(val== 0x70) //4th column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
delay(4000);

command_write(0xc8);

lcd_stringout("B");

USART2->DR = 0x42;

while((USART2->SR & 0x40)==0);

/////////////////////////// 3 Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

GPIOD->BSRRH = 0x0004; //low PD0

GPIOD->BSRRL = 0x000B; //low PD0

val = (GPIOD->IDR)&0xF0; //status of D4 to D7

if(val == 0xE0) //1st column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000)

command_write(0xc8);

lcd_stringout("4");

USART2->DR = 0x34;

while((USART2->SR & 0x40)==0);

}
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
else if(val== 0xD0) //2nd column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("5");

USART2->DR = 0x35;

while((USART2->SR & 0x40)==0);

else if(val== 0xB0) //3rd column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("6");

USART2->DR = 0x36;

while((USART2->SR & 0x40)==0);

}
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
else if(val== 0x70) //4th column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("7");

USART2->DR = 0x37;

while((USART2->SR & 0x40)==0);

/////////////////////////// 4 Row \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

GPIOD->BSRRH = 0x0008; //low PD0

GPIOD->BSRRL = 0x0007; //low PD0

val = (GPIOD->IDR)&0xF0; //status of D4 to D7

if(val == 0xE0) //1st column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
lcd_stringout("0");

USART2->DR = 0x30;

while((USART2->SR & 0x40)==0);

else if(val== 0xD0) //2nd column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("1");

USART2->DR = 0x31;

while((USART2->SR & 0x40)==0);

else if(val== 0xB0) //3rd column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
lcd_stringout("2");

USART2->DR = 0x32;

while((USART2->SR & 0x40)==0);

else if(val== 0x70) //4th column

command_write(0x01);

command_write(0x80);

lcd_stringout("Xbee Transmit");

delay(4000);

command_write(0xc8);

lcd_stringout("3");

USART2->DR = 0x33;

while((USART2->SR & 0x40)==0);

////////////////////// MAIN \\\\\\\\\\\\\\\\\\\\\\\\\\

void main()

USART2_config();

mx_pinout_config();
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
lcd_init(); //send initial commands

command_write(0x80);

lcd_stringout(d1);

command_write(0xC0);

lcd_stringout(d2);

delay(100);

lcd_stringout("Relay ON");

while(1)

xbee_tx();

GPIOD->ODR = 0x0<<8;

command_write(0x01);

command_write(0x80);

lcd_stringout("Relay ON");

GPIOC->ODR = 0x0200; //relay on

delay(5000);

command_write(0x01);

command_write(0x80);

lcd_stringout("Relay OFF");

GPIOC->ODR = 0x0000; //relay off

delay(5000);
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
}

PROCEDURE TO SEE OUTPUT:

1.Set your board to the execution mode and reset it.

2. Connect the +ve terminal of the LED board to the connector and – ve terminal to GND.

3. On varying the duty cycle of the PWM, the intensity of the LEDs will vary.

4. To increase the duty cycle press SW2 and to decrease, SW5.

RESULT:

The C program to vary the intensity of the LED depending on the duty cycle of the PWM
has been developed and is verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
EX. NO: 12

DATE: MAIL BOX

AIM:
To develop a ‘C’ code to create a mailbox and to understand the RTOS functions.

APPARATUS AND SOFTWARE REQUIRED:


• VSK-SCM4 Development board
• IAR IDE software
• Flash Loader demonstrator

THEORY:
Real time and embedded systems operate in constrained environments in which computer
memory and processing power are limited .They often need to provide their services within strict
time deadlines to their users and to the surrounding world.it is these memory ,speed and timing
constraints that dictate the use of real-time operating systems in embedded software.

The “kernel” of a real-time operating system (“RTOS”) provides an “abstraction layer”


that hides from application software the hardware details of the processor(or set of processors)
upon which software will run.

Application
software

RTOS

HARDWARE

In providing this “abstraction layer” the RTOS kernel supplies five main categories of
basic services to application software.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
The most basic category of kernel services is Task management .This set of services
allows application software developers to design their software as a number of separate “chunks”
of software –each handling a distinct topic, a distinct goal, and perhaps its own real-time
deadline. Each separate “chunk” of software is called a “task”. The main RTOS service in this
category is the scheduling of tasks in the embedded system is in operation.

The second category of kernel services is inter-task Communication and synchronization.


These services make it possible for tasks to pass information from one to moths, without danger
of that information ever being damaged. They also make it possible for tasks to coordinate. So
that they can productively corporate with one another. Without the help of these RTOS services,
tasks might well communicate corrupted information otherwise interfere with each other.

Since many embedded systems have stringent timing requirements. Most RTOS kernels
also provide acute basic Tuner services. Such a task delays and time-outs.

Many (but not all) RTOS kernels provide Dynamic Memory Allocation services. This
category of services allows tasks to borrow chunks of RAM memory for temporary use in
application software. Often these chunks of memory are then passed from task to task. As a
means of quickly communicating large amount of data between tasks. Some very small RTOS
kernels that are intended for tightly memory-limited environments, do not offer Dynamic
memory allocation.

May (but not all) RTOS kernels also provide a “Device I/0 Supervisor" category of services.
These services, “available provide a uniform framework for organizing and accessing the many
hardware device drivers that are typical often embedded system.

PROCEDURE
1. Follow the steps 1 of how to create a New project

2. Type the below code and save it with the name (any name. c)

3. Follow the steps 2-6 of how to create a new project to add the necessary file, compile
and build the program.

4. Follow the procedures in how to download a code to our controller to download your
code.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
PROGRAM
#include”ucos_ii.h”

#include”bsp.h”

#define TASK_STK_SIZE 128

OS_STK AppStk_send[TASK_STK_SIZE];

OS_STK_AppStk_recv[TASK_STK_SIZE];

Static voidbMailbox_App_Tx(void*p_arg);

Static voidbMailbox_App_Rx(void*p_arg);

OS_EVENT*pmailbox;

int main(void)

BSP_IntDisAll();

/*disable all interrupts until we are ready to accept them*/

RCC_ClocksTypesDefrec_clocks;

RCC_GetClocksFreq(&rec_clocks);

SysTick_Config(rec_clocks.HCLK_Freuency/OS_TICKS_PER_SEC);

OSInit();/*ucosii initialization*/

BSP_Init();/*board support package initialization*/

OSStatInit();/*Determine CPU capacity*/

/*TODO:create application tasks here*/

OSTaskCreate(Mailbox_App_Tx,NULL,(OS_STK*)&AppStk_send[TASK_STK_SIZE-
1],(INT8U)10);/*sending task*/

OSTaskCreate(Mailbox_App_Rx,NULL,(OS_STK*)&AppStk_recv[TASK_STK_SIZE-
1],(INT8U)30);/*receiving task*/

OSStart();/*start os here*/

Printf(“\n\r NEVER ARRIVES HERE”);

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
RETURN 0;

/*Post data to mailbox*/

voidMailbox_App_Tx(void*p_arg)

INT8U i,err,*buffer[5];

buffer[0]=”1.RCC”;

buffer[1]=”2.DMA”;

buffer[2]=”3.NVIC”;

buffer[3]=”3.FPU”;

//buffer[4]=”5.FSMC”;

p_arg=p_arg;

pmailbox=OSMboxCreate(NULL);

for(i=0;i<5;)

{If((err=OSMbpxPost(pmailbox,buffer[i]))==NO_ERROR_GK)/*if success*/

Printf(“/n/r This is sender \n\t the mailbox has data, data is--> %s”,pmailbox->OSEventPtr);

Else/*other errors occurred*/

Printf(“\n\r other error”);

OSTimeDlyHMSM(0,0,5,0);}

OSTimeDlyHMSM(0,0,5,0);

OSMboxDel(pmailbox,OS_DEL_NO_PEND,&err);

If(err==OS_ERR_TASK_WAITING_GK) /*another task waiting error*/

Printf(“\n\rSome task waiting for this Mailbox”);}

/*Get data from mailbox */

Void Mailbox_App_Rx(void*p_arg)
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
{

INTU8 err;

INT16U timeout=100;

INT8U *buffer;

p_arg = p_arg;

for(;;)

Buffer = OSMboxPend(pmailbox,timeout,&err);

Printf(“\n\rThis is receiver\n\t get data from mailbox data is -->%s”,buffer);

Else if(err==TIMEOUT_ERROR_GK)/*if unmatched event occurred*/

{Printf(“\n\rThis is receiver\n\t err is OS_ERR_EVENT_TYPE”);Break;

Else

Break;

OSTimeDlyHMSM(0,0,6,0);}}

PROCEDURE TO VIEW THE RESULT


1. Follow the steps of how to view the result in Win X talk.
2. Set your board to the execution mode and reset it.
3. The data that is transmitted from the task 1 is received by the task 2 and is displayed.

RESULT
The c-language program to create a mailbox and to understand about the RTOS functions
is developed and is verified.

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
VIVA QUESTIONS & ANSWERS

1. Define Embedded System. What are the components of embedded system?


An Embedded system is one that has computer hardware with software embedded in it as one of its most
important component.
The three main components of an embedded system are
1. Hardware
2. Main application software
3. RTOS
OR
An embedded system employs a combination of hardware & software (a "computational engine") to
perform a specific function; is part of a larger system that may not be a "computer"; works in a reactive
and time-constrained environment

2. In what ways CISC and RISC processors differ?


CISC RISC
1. It provides number of addressing modes It provides very few number of addressing modes
2. It has a micro programmed unit with a It has a hard wired unit without a control memory
control memory
3. An easy compiler design Complex compiler design
4. Provides precise and intensive calculations Provides precise and intensive calculations faster
slower than a RISC than a RISC

3. Define system on chip (SOC) with an example.


Embedded systems are being designed on a single silicon chip called system on chip. SOC is a new
design innovation for embedded system
Ex. Mobile phone.

4. Give any two uses of VLSI designed circuits


A VLSI chip can embed IPs for the specific application besides the ASIP or a GPP core. A system on a
VLSI chip that has all of needed analog as well as digital circuits.
Eg. Mobile phone.

5. List the important considerations when selecting a processor.


• Instruction set
• Maximum bits in an operand
• Clock frequency
• Processor ability
6. What are the types of embedded system?
• Small scale embedded systems
• Medium scale embedded systems
• Sophisticated embedded systems
7. Classify the processors in embedded system?
a). General purpose processor
• Microprocessor
• Microcontroller
• Embedded processor
• Digital signal processor
• Media processor
b).Application specific system processor
Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
c). Multiprocessor system using GPP and ASSP GPP core or ASIP core integrated into either an ASIC or
a VLSI circuit or an FPGA core integrated with processor unit in a VLSI chip.

8. What are the important embedded processor chips?


• ARM 7 and ARM 9
• i 960
• AMD 29050

9. Name some DSP used in embedded systems?


• TMS320Cxx
• SHARC
• 5600xx

10. Name some of the hardware parts of embedded systems?


• Power source
• Clock oscillator circuit
• Timers
• Memory units
• DAC and ADC
• LCD and LED displays
• Keyboard/Keypad

11. What are the various types of memory in embedded systems?


• RAM (internal External)
• ROM/PROM/EEPROM/Flash
• Cache memory

12. What are the points to be considered while connecting power supply rails with embedded
system?
• A processor may have more than two pins of Vdd and Vss
• Supply should separately power the external I/O driving ports, timers, and clock
• From the supply there should be separate interconnections for pairs of Vdd and Vss pins analog
ground analog reference and analog input voltage lines.

13. What is watch dog timer?


Watch dog timer is a timing device that resets after a predefined timeout.

14. What are the two essential units of a processor on a embedded system?
• Program Flow control Unit
• Execution Unit

15. What does the execution unit of a processor in an embedded system do?
The EU includes the ALU and also the circuits that execute instructions for a program control task. The
EU has circuits that implement the instructions pertaining to data transfer operations and data conversion
from one form to another.

16. Give examples for general purpose processor.


• Microcontroller
• Microprocessor

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
17. Define microprocessor.
A microprocessor is a single VLSI chip that has a CPU and may also have some other units for example
floating point processing arithmetic unit pipelining and super scaling units for faster processing of
instruction.

18. Define Real Time Clock (RTC)?


Real time clock is a clock which once the system stats does not stop and cant be reset and its
count value cannot be reloaded.

19. Define Time-out or Time Overflow?


A state in which the number of count inputs exceeded the last acquirable value and on reaching
that state, an interrupt can be generated.

20. Why do we need at least one timer in an ES?


The embedded system needs at least on timer device. It is used as a system clock.

21. What is a PIC?


PIC refers to Programmable Intelligent Computer. PIC is microprocessor lies inside a personal
computer but significantly simpler, smaller and cheaper. It can be used for operating relays,
measuring sensors etc.

22. What are the main elements inside a PIC?


• Processing engine,
• Program memory,
• Data memory and
• Input / Output.

23. What are the types of program memory in a PIC?


• Read-only,
• EPROM and
• EEPROM,
• Flash

24. Define a System.


A way of doing one or more tasks according to a program.

25. What are the typical characteristics of an embedded system? Typical characteristics:
Perform a single or tightly knit set of functions; Increasingly high-performance & real-time
constrained; Power, cost and reliability are often important attributes That influence design;
Application specific processor design can be a significant component of some embedded systems.
Other characteristics:
• Application specific
• Digital signal processing in ECS
• Reactive
• Real-time
• Distributed

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
26. What are the advantages and disadvantages of embedded system?
Advantages: Customization yields lower area, power, cost.
Disadvantages: Higher HW/software development overhead design, compilers, debuggers, etc., may
result in delayed time to market.

27. What are the applications of an embedded system? Embedded Systems: Applications:
• Consumer electronics, e.g., cameras, camcorders, etc.,
• Consumer products, e.g., washers, microwave ovens, etc.,
• Automobiles (anti-lock braking, engine control, etc.,)
• Industrial process controllers & avionics/defense applications
• Computer/Communication products, e.g., printers, FAX machines, etc.,
• Emerging multimedia applications & consumer electronics

28. What are the complicating factors in embedded design?


Complicating factors in the design of embedded systems
• Many of the subtasks in design are intertwined.
• Allocation depends on the partitioning, and scheduling presumes a certain allocation.
• Predicting the time for implementing the modules in hardware or software is not very
easy, particularly for tasks that have not been performed before.
29. What are the real-time requirements of an embedded system?
Hard-real time systems: where there is a high penalty for missing a deadline e.g., control
systems for aircraft/space probes/nuclear reactors; refresh rates for video, or DRAM. Soft real
time systems: where there is a steadily increasing penalty if a deadline is missed.
e.g., laser printer: rated by pages-per-minute, but can take differing times to print a page
(depending on the \"complexity\" of the page) without harming the machine or the customer.
30. What are the functional requirements of embedded system?
• Data Collection
• Sensor requirements
• Signal conditioning
• Alarm monitoring
• Direct Digital Control
• Actuators
• Man-Machine Interaction informs the operator of the current state of the controlled object
assists the operator in controlling the system.

31. What are the main components of an embedded system? Three main components of
embedded systems:
1. The Hardware
2. Application Software
3. RTOS

32. Define embedded microcontroller.


An embedded microcontroller is particularly suited for embedded applications to perform
dedicated task or operation.
Example: 68HC11xx, 8051, PIC, 16F877, etc.,

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
33. Explain digital signal processing in embedded system continued digitization of signals
increasing the role of DSP in ES.
• Signals are represented digitally as sequence of "samples"
• ADC’s are moving closer to signals

34. What are the various classifications of embedded systems?


a. Small scale embedded systems
b. Medium scale embedded systems
c. Sophisticated embedded systems

35. What are the two essential units of a processor on an embedded system?
a. Program flow control unit (CU)
b. Execution unit (EU)

36. What does the execution unit of a processor in an embedded system do?
The execution unit implements data transfer and data conversion. It includes ALU and
circuits that execute instruction for jump, interrupt, etc.,

37. Give examples for general purpose processor.


• Microprocessor
• Microcontroller
• Embedded processor
• Digital Signal Processor
• Media Processor

38. Define microprocessor.


A microprocessor fetches and processes the set of general-purpose instructions such as data
transfer, ALU operations, stack operations, I/O operations and other program control
operations.

39. When is Application Specific System processors (ASSPs) used in an embedded system?
An ASSP is dedicated to real-time video processing applications such as video conferencing,
video compression and decompression systems. It is used as an additional processing unit for
running application specific tasks in the place of processing using embeddedsoftware.

40. What is the need for LCD and LED displays?


Uses of LCD and LED display:
a. It is used for displaying and messaging.
b. Example: Traffic light status indicator, remote controls,signals, etc.,
c. The system must provide necessary circuit and software for the output to LCD
controller.
41. Define ROM image.
ROM image in a system memory consists of:
Boot-up program, stack address pointer, program counter address pointer, application
tasks, ISRs, input data, RTOS and vector addresses.
Bytes at each address must be defined to create ROM image.

42. Define device driver.


Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET
A device driver is software for controlling, reading, sending a byte of stream of bytes from/to the
device.

43. Give some examples :


small scale embedded systems : 68HC05, PIC 16F8x, 8051.
medium scale embedded systems : 80251, 80x86, 80196,68HC11xx .
sophisticated embedded systems : ARM7, Power PC, Intel 80960.

44. What are the various embedded system requirements Types of requirements imposed by
embedded applications:
Functional requirements
Temporal requirements
Dependability requirements

45. What are the temporal requirements?


Tasks may have deadlines
Minimal latency jitter
Minimal error detection latency
Timing requirements due to tight software control loops
Human interface requirements.

46. Give the classification of embedded system.


Multi-dimensional classifications
Hard versus software systems

47. Define FPGAs


Field Programmable Gate Arrays (FPGAs) can be used to implement just about any hardware design.
One common use is to prototype a lump of hardware that will eventually find its way into an ASIC.

48. Define PLDs


At the low end of the spectrum are the original Programmable Logic Devices (PLDs). These were the
first chips that could be used to implement a flexible digital logic design in hardware. In other words, you
could remove a couple of the 7400-series TTL parts (ANDs, ORs, and NOTs) from your board and
replace them with a single PLD. Other names you might encounter for this class of device are
Programmable Logic Array (PLA), Programmable Array Logic (PAL), and Generic Array Logic (GAL).

49. Define bus.


Buses: The exchange of information. Information is transferred between units of the microcomputer
by collections of conductors called buses. There will be one conductor for each bit of information to be
passed, e.g., 16 lines for a 16 bit address bus. There will be address, control, and data buses

50. What are the classifications of I/O devices?


• Synchronous serial input and output
• Asynchronous serial UART input and output
• Parallel one bit input and output
• Parallel port input and output

Prepared by
Mr. J. Satheesh Kumar,
AP / ECE / HICET

Vous aimerez peut-être aussi