HDL Manual Color
HDL Manual Color
HDL Manual Color
LIST OF PROGRAMMES
Write assembly language program to transfer the data from Internal RAM
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:
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
I/P:
O/P:
UP:
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
CJNE A,B,NEXT
CJNE A,B,NEXT
NEXT: JC CARRY
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
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
MOV R6,#03H
MOV R6,#03H
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,
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
REPEAT:
ACALL SEND
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
RET
CLR TI
RET
END
END
O/P:
O/P:
ORG 00H
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
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
DJNZ R1,BACK
CLR TR0
DJNZ R0,BACK
CLR TF0
RET
END
RET
END
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,
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
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
O/P:
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;
P0=i;
}
}
M.Tech,
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);
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);
}
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);
4. DAC Experiments
{
while(1)
{
P0=0x00;
P1=0x00;
delay(1);
P0=0xFF;
P1=0xFF;
delay(1);
}
}
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;
}
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;
}
}