HDL Manual Color

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 37

HDL LAB MANUAL

SUB CODE: 10ES-48


Semester: B.E. IV SEM
ELECTRONICS & COMMUNICATION ENGINEERING
DEPARTMENT

PROF. UDAY KALYANE


MR. SANJAY KULKARNI
BKIT BHALKI-585328

LIST OF PROGRAMMES

Write assembly language program to transfer 10-bytes data from one


RAM location to another Ram location (Internal memory).

Write assembly language program to transfer the data from Internal RAM

to external RAM location.


Write assembly language program to clear the external memory location
(10 bytes)
Write assembly language program to exchange the data from one
memory to another memory location.
Write assembly language program to arrange number in ascending order.
Write assembly language program to arrange number in descending
order.
Write assembly language program to find largest number in given series.
Write assembly language program to find smallest number in given
series.
Write assembly language program add two 16-bit number and store
result in the bank registers.
Write assembly language program to subtract two 16-bit numbers and
store result
in bank register.
Write assembly language program to multiply the two eight bit number
and store bank register.
Write assembly language program to division one eight bit number from
another 8-bit number.
Write assembly language program to square of given number
Write assembly language program to cube of given number
Write assembly language program to average of N-8bit number given
number
Write assembly language program to generate Fibonacci series
Write assembly language program to perform logical operation of AND
NAND, NOT.
Write assembly language program to find the of 0and 1s in the given
number
Write assembly language program to separate the positive and negative
numbers
Write assembly language program to compute sum=1+2+3+4+------ N
numbers
Write assembly language program to convert the given BCD to Excess-3
Write assembly language program to convert given packed BCD to
unpacked BC and vice versa
Write assembly language program to convert the given ASCII to packed
BCD
Write assembly language program to convert given Decimal to ASCII
number
Write assembly language program to generate time delay of 1 sec
Write a C program to generate a triangular wave from using DAC
interface
Write a C program to generate a square wave from using DAC interface
Write a C program to generate a sine wave from using DAC interface
Write a C program to generate a ramp wave from using DAC interface

BLOCK MOVE

BLOCK EXCHANGE

ORG 00H

ORG 00H

MOV R2,#04H

MOV R2,#04H

MOV R0,#20H

MOV R0,#20H

MOV R1,#30H

MOV R1,#30H

UP:

UP:

MOV A,@R0

MOV A,@R0

MOV @R1,A

XCH A,@R1

INC R0

MOV @R0,A

INC R1

INC R0

DJNZ R2,UP

INC R1

END

DJNZ R2,UP
END

I/P:
I/P:

O/P:

O/P:

ADDITION OF TWO 16-BIT NUMBER


(MULTIBYTE ADDITION)

SUBTRACTION OF TWO 16-BIT


NUMBER (MULTIBYTESUBTRACTION)

ORG 00H

ORG 00H

MOV R7,#02H

MOV R7,#02H

MOV R0,#20H

MOV R0,#20H

MOV R1,#40H

MOV R1,#40H

UP:
MOV A,@R0

MOV A,@R0

ADDC A,@R1

SUBB A,@R1

MOV @R1,A

MOV @R1,A

INC R0

INC R0

INC R1

INC R1

DJNZ R7,UP

DJNZ R7,UP

JNC NOCARRY

JNC NOCARRY

INC R2

INC R2

NOCARRY: MOV A,R2

I/P:

O/P:

UP:

NOCARRY: MOV A,R2

MOV @R1,A

MOV @R1,A

END

END
I/P:

O/P:

SMALLEST OF N NUMBER

LARGEST OF N NUMBER

ORG 00H

ORG 00H

MOV R3,#04H

MOV R3,#04H

MOV R0,#30H

MOV R0,#30H

MOV A,@R0

MOV A,@R0

INC R0

INC R0

UP: MOV B,@R0

UP: MOV B,@R0

CJNE A,B,NEXT

CJNE A,B,NEXT

NEXT: JC CARRY

NEXT: JNC NOCARRY

MOV A,@R0

MOV A,@R0

CARRY: INC R0

I/P:

O/P:

NOCARRY: INC R0

DJNZ R3,UP

DJNZ R3,UP

MOV @R0,A

MOV @R0,A

END

END
I/P:

O/P:

Hexadecimal to BCD

BCD to Hexadecimal

ORG 00H

I/P:

O/P:

ORG 00H

MOV A,30H

MOV A,20H

MOV B,#0AH

MOV B,#10H

DIV AB

DIV AB

MOV 33H,B

MOV R2,B

MOV B,#0AH

MOV B,#0AH

DIV AB

MUL AB

MOV 32H,B

ADD A,R2

MOV 31H,A

MOV 21H,A

END

END
I/P:

O/P:

BCD to ASCII

ASCII to BCD

ORG 0000

ORG 0000H

MOV A,30H

MOV A,30H

ANL A,#0F0H

SUBB A,#30H

SWAP A

SWAP A

ADD A,#30H

MOV R2,A

MOV 31H,A

MOV A,31H

MOV A,30H

SUBB A,#30H

ANL A,#0FH

ADD A,R2

ADD A,#30H

MOV 32H,A

MOV 32H,A

END

END

I/P:

I/P:

O/P:
O/P:

LOGIC GATES
AND, NAND, OR & NOR

HALF ADDER

ORG 00H

ORG 00H

MOV C,P1.7

MOV C,P1.7

ANL C,P1.6

ANL C,/P1.6

MOV P1.5,C

MOV P1.5,C

CPL C

MOV C,P1.7

MOV P1.4,C

CPL C

MOV C,P1.7

ANL C,P1.6

ORL C,P1.6

MOV P1.4,C

MOV P1.3,C

ORL C,P1.5

CPL C

MOV P1.3,C

MOV P1.2,C

MOV C,P1.7

END

ANL C,P1.6
MOV P1.2,C
END

I/O:

I/O:

A B

Y=AB

Y=AB

Y=A+B

Y=(A+B)

A B

C=AB

S=AB + AB

XOR GATE

XOR NOR GATE


ORG 00H

ORG 00H

MOV C,P1.7

MOV C,P1.7

CPL C

ANL C,/P1.6

ANL C,/P1.6

MOV P1.5,C

MOV P1.5,C

MOV C,P1.7

MOV C,P1.7

CPL C

ANL C,P1.6

ANL C,P1.6

MOV P1.4,C

MOV P1.4,C

ORL C,P1.5

ORL C,P1.5

MOV P1.3,C

MOV P1.3,C

END

END
I/O:
I/O:

B S=AB + AB
0

S=AB + AB

ASCENDING

DESCENDING

ORG 00H

ORG 00H

MOV R7,#03H

MOV R7,#03H

MAIN: MOV R0,#30H

MAIN: MOV R0,#30H

MOV R6,#03H

MOV R6,#03H

UP: MOV A,@R0

UP: MOV A,@R0

INC R0

INC R0

MOV B,@R0

MOV B,@R0

CJNE A,B,NEXT

CJNE A,B,NEXT

NEXT:
JC NOEXCHANGE

JNC NOEXCHANGE

MOV @R0,A

MOV @R0,A

DEC R0

DEC R0

MOV @R0,B

MOV @R0,B

INC R0

INC R0

NOEXCHANGE:

I/P:

NEXT:

NOEXCHANGE:

DJNZ R6,UP

DJNZ R6,UP

DJNZ R7,MAIN

DJNZ R7,MAIN

END

END
I/P:

O/P:

O/P:

M.Tech,

Lecturer in E&CE Dept. S.T.J.I.T, Ranebennur.

SERIAL COMMUNICATION

SERIAL COMMUNICATION

ORG 00H

ORG 00h

MOV TMOD,#20H

MOV TMOD,#20h

MOV TH1,#-3

MOV TH1,#-3

MOV SCON,#50H

MOV SCON,#50h

SETB TR1

SETB TR1

UP: MOV A, #'S'

REPEAT:

ACALL SEND

MOV DPTR, #msg

MOV A, #'T'

UP: CLR A

ACALL SEND

MOVC A,@A+DPTR

MOV A, #'J'

JZ REPEAT

ACALL SEND

ACALL SEND

MOV A, #'I'

INC DPTR

ACALL SEND
MOV A, #'T'

SJMP UP

ACALL SEND

SEND:

SJMP UP

MOV SBUF,A
HERE: JNB TI, HERE
CLR TI

SEND : MOV SBUF, A

RET

HERE: JNB TI, HERE


msg: db "STJIT",0

CLR TI
RET

END

END
O/P:

O/P:

TIMER DELAY PROGRAM

TIMER DELAY PROGRAM


ORG 00H

ORG 00H

MOV TMOD, #01H


AGAIN:

MOV TMOD, #01H

AGAIN:
MOV TL0,#00H

MOV TL0,#3EH

MOV TH0,#00H

MOV TH0,#0B8H

CPL P1.7

CPL P1.7

ACALL DELAY

ACALL DELAY

SJMP AGAIN

SJMP AGAIN

DELAY:
DELAY:
SETB TR0
HERE: JNB TF0, HERE

SETB TR0

HERE: JNB TF0, HERE


CLR TR0

CLR TR0

CLR TF0

CLR TF0

RET

RET

END

END

O/P:
O/P:

COUNTERS

HEX-UP COUNTER

HEX-UP COUNTER

ORG 00H
UP:

ORG 00H
UP:

MOV P1,A

MOV P1,A

INC A

INC A

ACALL DELAY

ACALL DELAY

SJMP UP

SJMP UP

DELAY:

DELAY:
MOV R0,#60H

MOV TL0,#00H

MOV R1,#0FFH

MOV TH0,#00H

MOV R2,#0FFH
BACK:
DJNZ R2,BACK

SETB TR0
HERE: JNB TF0,HERE

DJNZ R1,BACK

CLR TR0

DJNZ R0,BACK
RET

CLR TF0

END

RET
END

HEX-DOWN COUNTER
ORG 00H
MOV A,#0FFH
UP:

HEX-DOWN COUNTER
ORG 00H
MOV A,#0FFH
UP:

MOV P1,A

MOV P1,A

DEC A

DEC A

ACALL DELAY

ACALL DELAY

SJMP UP

SJMP UP

DELAY:

DELAY:
MOV R0,#60H

MOV TL0,#00H

MOV R1,#0FFH

MOV TH0,#00H

MOV R2,#0FFH
BACK:
DJNZ R2,BACK

SETB TR0
HERE: JNB TF0,HERE

DJNZ R1,BACK

CLR TR0

DJNZ R0,BACK
RET

CLR TF0

END

RET
END

DECIMAL-UP COUNTER
ORG 00H
UP:

DECIMAL-UP COUNTER
ORG 00H
UP:

MOV P1,A

MOV P1,A

ADD A,#01H

ADD A,#01H

DA A

DA A

ACALL DELAY

ACALL DELAY

SJMP UP

SJMP UP

DELAY:

DELAY:
MOV R0,#60H

MOV TL0,#00H

MOV R1,#0FFH

MOV TH0,#00H

MOV R2,#0FFH
BACK:
DJNZ R2,BACK

SETB TR0
HERE: JNB TF0,HERE

DJNZ R1,BACK

CLR TR0

DJNZ R0,BACK
RET

CLR TF0

END

RET
END

DECIMAL-DOWN COUNTER

DECIMAL-DOWN COUNTER

ORG 00H

ORG 00H

MOV A,#99H

MOV A,#99H

UP:

UP:

MOV P1,A

MOV P1,A

ADD A,#99H

ADD A,#99H

DA A

DA A

ACALL DELAY

ACALL DELAY

SJMP UP

SJMP UP

DELAY:

DELAY:
MOV R0,#60H

MOV TL0,#00H

MOV R1,#0FFH

MOV TH0,#00H

MOV R2,#0FFH
BACK:

SETB TR0

DJNZ R2,BACK

HERE: JNB TF0,HERE

DJNZ R1,BACK

CLR TR0

DJNZ R0,BACK

CLR TF0

RET
END

RET
END

SQUARE OF A GIVEN NUMBER

CUBE OF A GIVEN NUMBER


ORG 00H

ORG 00H
MOV A,20H
MOV B,A
MUL AB
MOV 21H,B

MOV 22H,A

MOV A,20H
MOV B,A
MUL AB

MOV 21H,A
MOV 22H,B
MOV A,20H

END

MOV B,21H

I/P:

MUL AB
MOV 23H,A
MOV 24H,B
MOV A,20H
MOV B,22H

O/P:

MUL AB
MOV 25H,A
MOV 26H,B
MOV 32H,23H
MOV A,24H
ADD A,25H

Cube I/O:

MOV 31H,A
MOV A,26H

I/P:

ADDC A,#00H
MOV 30H,A
END

O/P:

M.Tech,

Lecturer in E&CE Dept. S.T.J.I.T, Ranebennur.


16-BIT MULTIPLICATION

MOV A,33H
ORG 00H

ADD A, R0

MOV A,20H

JNC go2

MOV B,22H

INC R1 go2:

MUL AB

ADD A,35H

MOV 30H,A

JNC go3

MOV 31H,B

INC R1

MOV A,20H
MOV B,23H

go3: ADD A,36H

MUL AB

JNC go4

MOV 32H,A
MOV 33H,B
MOV A,21H

INC R1
go4: MOV 41H,A

MOV B,22H

MOV A,37H

MUL AB

ADD A,R1

MOV 34H,A

MOV 40H,A

MOV 35H,B

END

MOV A,21H
MOV B,23H
MUL AB

I/P:

MOV 36H,A
MOV 37H,B
MOV 43H,30H
MOV A,31H
ADD A,32H

Intermediate O/P:

JNC go
INC R0
go: ADD A,34H
JNC GO1
INC R0

go1: MOV 42H,A

O/P:

BYTE LEVEL LOGICAL


OPERATION
ORG 00H
MOV A,20H
ANL A,21H
MOV 32H,A
MOV A,20H
ORL A,21H
MOV 33H,A
MOV A,20H
XRL A,21H
MOV 34H,A
MOV A,20H
CPL A
MOV 35H,A
MOV A,20H
CLR A
MOV 36H,A
MOV A,20H
SWAP A
MOV 37H,A
MOV A,20H
RR A
MOV 38H,A
MOV A,20H
RL A
MOV 39H,A
END

HARDWARE EXPERIMENTS
Speed control of DC Motor
#include<REG51XD2.H>
sbit incr=P3^2;

sbit decr=P3^3;
void main()
{
unsigned int i=0x80;
P0=i;

//to rotate motor with Half Speed (full speed=ff)


while (1)
{
if (incr==0)
{
if(i>10)
i=i-10;
}
if (decr==0)
{
if(i<0xf0)
i=i+10;
}

P0=i;
}
}

M.Tech,

Lecturer in E&CE Dept. S.T.J.I.T, Ranebennur.

Stepper Motor

1. To rotate motor in clkwise direction and anticlockwise direction for infinite number of
times.

#include <REG51xD2.H>
void delay (unsigned char
); sbit SW=P3^3;
void main()
{
while(1)
{
if(SW==0)
{
P0=0x11;
delay(1);
P0=0x22;
delay(1);
P0=0x44;
delay(1);
P0=0x88;
delay(1);
}
else
{
P0=0x88;
delay(1);
P0=0x44;
delay(1);
P0=0x22;

delay(1);
P0=0x11;
}

delay(1);

void delay(unsigned int count)


{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}

2. To rotate motor in clkwise direction or anticlockwise direction for an angle of 360 degree.

#include <REG51xD2.H>
void delay (unsigned char
); sbit SW=P3^3;
void main()
{
unsigned char i;
for(i=0;i<50;i++)
{
if(SW==0)
{
P0=0x11;
delay(1);
P0=0x22;
delay(1);
P0=0x44;
delay(1);

P0=0x88;
delay(1);
}
else
{
P0=0x88;
delay(1);
P0=0x44;
delay(1);
P0=0x22;
delay(1);
P0=0x11;
delay(1);
}

void delay(unsigned int count)


{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}

3. To rotate motor in clkwise direction or anticlockwise direction for an angle of 180 degree.

#include <REG51xD2.H>
void delay (unsigned char
); sbit SW=P3^3;
void main()
{
unsigned char i;
for(i=0;i<25;i++)
{
if(SW==0)
{
P0=0x11;
delay(1);
P0=0x22;
delay(1);
P0=0x44;
delay(1);
P0=0x88;
delay(1);
}
else
{
P0=0x88;
delay(1);
P0=0x44;
delay(1);
P0=0x22;
delay(1);
P0=0x11;

delay(1);

void delay(unsigned int count)


{
unsigned int i,j;
for(i=0;i<count;i++)
for(j=0;j<1275;j++);
}

4. DAC Experiments

Simple Square Wave


#include<REG51xD2.H>
void delay(unsigned int);
void main()

{
while(1)
{
P0=0x00;
P1=0x00;
delay(1);

P0=0xFF;
P1=0xFF;
delay(1);
}
}

void delay(unsigned int count)


{
unsigned int i,j;
for(i=0; i<count; i++)
for(j=0; j< 100; j++);
}

SINEWAVE GENERATION

#include<REG51xD2.H>
void main()

{
unsigned char table[]={128,192,238,255,238,192,128,64,17,0,17,64,128};
unsigned char i;

while(1)
{
for(i=0;i<13;i=i++)
P0=table[i];
}
}

Angles in

Sin

Vout=5v+(5x Sin )

128

30

0.5

7.5

192

60

0.866

9.33

238

90

10

255

120

0.866

9.33

238

150

0.5

7.5

192

180

128

210

-0.5

2.5

64

240

-0.866

0.699

17

270

-1

300

-0.866

0.699

17

330

-0.5

2.5

64

360

128

SAWTOOTH WAVEFORM

#include<REG51x
D2.H> void main()

{
unsigned
cha
r i;
whi
le(
1)

{
for(i=0x00;i<0xff;i++)
P0=i;
}

Decimal Values sent to DAC

degree

Voutx25.6

#include<REG51xD2.H>
void main()

{
unsigned char i;
while(1)

{
for(i=0xff;i>0x00;i--)
}

P0=i;

TRIANGULAR WAVE
#include<REG51xD2.H>
void main()
{
unsigned char i;
while(1)

{
for(i=0;i<0xff;i++)
P0=i;
for(i=0xff;i>0;i--)
P0=i;
}
}

STAIRCASE WAVEFORM
#include<REG51xD2.H>
void main()

{
unsigned char i;
while(1)

{
for(i=0;i<0xff;i=i+0x33)
P0=i;
}
}

#include<REG51xD2.H>
void main()

{
unsigned char i;
while(1)

{
for(i=0;i<0xff;i=i+0x1F)
P0=i;
}
}

#include<REG51xD2.H>
void main()

{
unsigned char i;
while(1)

{
for(i=0;i<0xff;i=i+0x3F)
P0=i;
}
}

#include<REG51xD2.H>
void main()

{
unsigned char i;
while(1)

{
for(i=0XFF;i>0;i=i-0x3F)
P0=i;
}
}

You might also like