Microcontroller Programs
Microcontroller Programs
Microcontroller Programs
Microcontrollers Lab
2012-13
10ESL47
Microcontrollers Lab
Let N = 05h,
A: 30h
B: 40h
mov r0,#30h
//source address
mov r1,#40h
//destination address
mov r7,#05h
end
Result:
Before Execution:
After Execution:
2012-13
10ESL47
Let N = 05h,
Microcontrollers Lab
A: 30h,
mov r0,#30h
mov r1,#40h
mov r7,#05h
back: mov a,@r0
mov r4,a
mov a,@r1
mov @r0,a
mov a,r4
mov @r1,a
inc r0
inc r1
djnz r7,back
end
Result:
B: 40h
//source address
//destination address
//count, the number of data to be exchanged
Before Execution:
After Execution:
2012-13
10ESL47
Microcontrollers Lab
Let N = 06h
mov r3,#6
mov dptr,#4000H
movx a,@dptr
mov r1,a
nextbyte: inc dptr
movx a,@dptr
clr c
mov r2,a
subb a,r1
jc skip
mov a,r2
mov r1,a
skip: djnz r3,nextbyte
mov dptr, #4062H
mov a,r1
movx @dptr,a
end
Result:
Before Execution:
After Execution:
2012-13
10ESL47
Microcontrollers Lab
Let N = 06h
mov R0,#05H
loop1:mov dptr, #9000h
mov r1,#05h
loop2:movx a, @dptr
mov b, a
inc dptr
movx a, @dptr
clr c
mov r2, a
subb A, b
jnc noexchg
mov a,b
movx @dptr,a
dec dpl
mov a,r2
movx @dptr,a
inc dptr
noexchg: djnz r1,loop2
djnz r0,loop1
end
//count (N-1)
array size = N
//array stored from address 9000h
//initialize exchange counter
//get number from array and store in B register
//next number in the array
//reset borrow flag
//store in R2
//2nd-1st No.,since no compare instruction in 8051
// JC - FOR DESCENDING ORDER
//exhange the 2 noes in the array
//DEC DPTR - instruction not present
Result:
Before Execution:
Note :
Analyze the bubble sort algorithm for the given data. Also try with different sorting
algorithms.
5. Write an assembly language program to perform the addition of two 16-bit
numbers.
mov r0,#34h //lower nibble of No.1
Dept. of ECE, B.I.T., Mangalore
1234
2012-13
10ESL47
mov r1,#12h
mov r2,#0dch
mov r3,#0feh
clr c
mov a,r0
add a,r2
mov 22h,a
mov a,r1
addc a,r3
mov 21h,a
mov 00h,c
end
Microcontrollers Lab
//higher nibble of No.1
//lower nibble of No.2
//higher nibble of No.2
//
+f e d c
----------11110
-----------
Result:
16-
f edc
-1 2 3 4
2012-13
10ESL47
Microcontrollers Lab
-----------ec a8
-------------
Result:
Note: Try with different data. Ex: (Smaller number) (larger number).
// 5678*1234
2012-13
10ESL47
Microcontrollers Lab
mov r3,#56h
mov a,r0
mov b,r2
mul ab
mov 33h,a
mov r4,b
mov a,r0
mov b,r3
mul ab
add a,r4
mov r5,a
mov a,b
addc A,#00h
mov r6,a
mov a,r1
mov b,r2
mul ab
add a,r5
mov 32h,a
mov a,b
addc a,r6
mov 00h,c
mov r7,a
mov a,r3
mov b,r1
mul ab
add a,r7
mov 31h,a
mov a,b
addc A,20h
mov 30h,a
end
Result:
Note: Write the logic of the program. Try with some other logic.
8. Write an assembly language program to find the square of a given number N.
Let N = 05
mov a,#05
mov b,a
// a=N=05
2012-13
10ESL47
Microcontrollers Lab
mul ab
mov 30h,a
mov 31h,b
end
Result:
Input:
Output:
Result:
Input:
Output:
10. Write an ALP to compare two eight bit numbers NUM1 and NUM2 stored in
external memory locations 8000h and 8001h respectively. Reflect your result
as: If NUM1<NUM2, SET LSB of data RAM location 2FH (bit address 78H).
If NUM1>NUM2, SET MSB of location 2FH (bit address 7FH). If
NUM1 = NUM2, then Clear both LSB & MSB of bit addressable memory
location 2FH.
mov dptr,#8000h
Dept. of ECE, B.I.T., Mangalore
2012-13
10ESL47
Microcontrollers Lab
movx a,@dptr
mov r0,a
inc dptr
movx a,@dptr
clr c
subb a,r0
jz equal
jnc small
setb 7fh
sjmp end1
small:setb 78h
sjmp end1
equal: clr 78h
clr 7fh
end1:
end
Result:
1) Before Execution: X: 8000h =
After Execution: D: 02FH =
2) Before Execution: X: 8000h =
After Execution: D: 02FH =
3) Before Execution: X: 8000h =
After Execution: D: 02FH =
&
X: 8001 =
&
X: 8001 =
&
X: 8001 =
11. Write an assembly language program to count number of ones and zeros in a
eight bit number.
mov r1,#00h
mov r2,#00h
mov r7,#08h
mov a,#97h
again: rlc a
jc next
inc r1
sjmp here
next: inc r2
here: djnz r7,again
end
]
Result:
Input:
// to count number of 0s
// to count number of 1s
// counter for 8-bits
// data to count number of 1s and 0s
12. Write an assembly language program to find whether given eight bit number
is odd or even. If odd store 00h in accumulator. If even store FFh in
accumulator.**
mov a,20h
jb acc.0, odd
10
2012-13
10ESL47
Microcontrollers Lab
mov a,#0FFh
sjmp ext
odd: mov a,#00h
ext: end
Result:
Input:
Output:
a:
20h:
Result:
1) Before Execution: D: 21H =
After Execution:
22H =
D: 030H =
//AND operation
D: 031H =
//OR operation
D: 032H =
//XRL operation
11
2012-13
10ESL47
Microcontrollers Lab
12
2012-13
10ESL47
Microcontrollers Lab
acall ascii
mov a,r0
acall ascii
sjmp $
ascii: anl a,#0fh
add a,#30h
movx @dptr,a
inc dptr
ret
end
Result:
Result:
Input: 9000h:
Output: 50h:
Result:
Input:
Output:
18. a. Write an assembly language program to convert a binary (hex) number
into decimal.
mov a,#0feh
mov b,#0ah
div ab
13
2012-13
10ESL47
Microcontrollers Lab
mov r0,b
mov b,#0ah
div ab
mov 30h,a
mov a,b
swap A
orl a,r0
mov 31h,A
end
Result:
Input:
Output:
Result:
Input:
Output:
14
2012-13
10ESL47
Microcontrollers Lab
Note: To use result of this program, after selecting DEBUG session in the main menu
use View-> serial window #1. On running & halting the program, the data is seen in
the serial window.
mov tmod,#20h
mov scon,#70h
mov th1,#-3
setb tr1
again: mov r0,#03h
mov dptr,#8000h
nextchar: movx a,@dptr
acall transfer
inc dptr
djnz r0,nextchar
sjmp again
transfer: mov sbuf,a
wait: jnb ti,wait
clr ti
ret
end
RESULT:
MICROCONTROLLERS LAB BIT is printed on the serial window each
time the program is executed.
Theory:
In serial transmission as opposed to parallel transmission, one bit at a time is
transmitted. In serial asynchronous transmission, the data consists of a Start bit (high),
followed by 8 bits of data to be transmitted and finally the stop bit. The byte character
to be transmitted is written into the SBUF register. It transmits the start bit. The 8-bit
character is transferred one bit at a time. The stop bit is transferred. After the
transmission, the TI flag = 1 indicating the completion of transmission. Hence in the
subroutine wait until TI is set. Later clear the TI flag and continue with transmission
of the next byte by writing into the SBUF register. (The program can also be written
in interrupt mode). The speed of the serial transmission is set by the baud rate which
is done with the help of timer 1. Timer1 must be programmed in mode 2 (that is, 8-bit,
auto reload).
Baud rate Calculation: Crystal freq/ (12*32) = (11.0592MHz)/(12*32) = 28800.
Serial communication circuitry divides the machine cycle frequency (11.0592MHz)/
(12) by 32 before it is being used by the timer to set the baud rate.
To get 9600, 28800/3 is obtained by loading timer1 with -3 (i.e., FF 3 = FD) for
further clock division. For 2400 baud rate, 28800/12 => -12 = F4 in TH1.
20. Conduct an experiment to generate 1second delay continuously using on chip
timer.
15
2012-13
10ESL47
Microcontrollers Lab
mov tmod,#02h
mov th0,#00h
clr P1.0
clr a
setb tr0
again: mov r7,#0ffh
loop: mov r6,#14d
wait: jnb tf0, wait
clr tf0
djnz r6,wait
djnz r7,loop
cpl P1.0
sjmp again
end
RESULT:
Accumulator A is incremented in binary from 00, 01,0209,0A, 0B, , 0F,
10, 11, FF every 1 second (for 33MHz clock setting & every 3 seconds for
11.0598MHz)
16
2012-13
10ESL47
Microcontrollers Lab
21. Write an assembly language program to transfer N = ___ bytes of data from
location A:_______h to location B:_______h (without overlap).
17
2012-13
10ESL47
Microcontrollers Lab
Output:
18
2012-13
10ESL47
Microcontrollers Lab
Output:
23. Write an assembly language program to perform the addition of two 32-bit
numbers.
19
2012-13
10ESL47
Microcontrollers Lab
#include "msp430.h"
; #define controlled include file
NAME main
; module name
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
MOV.W #0X9000,R4
MOV.W #0XFFFF,R7
ADD.W R4,R7
MOV.W #0XFFFF,R5
MOV.W #0XFFFF,R6
ADDC R5,R6
JMP $
END
//NUM1:FFFF9000
//NUM2:FFFFFFFF
Result:
Input:
Output:
32-
#include "msp430.h"
; #define controlled include file
NAME main
; module name
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
MOV.W #0X9000,R4
MOV.W #0XFFFF,R7
SUB.W R4,R7
MOV.W #0XFFFF,R5
MOV.W #0XFFFF,R6
SUBC R5,R6
JMP $
END
Result:
Input:
Output:
25. Write an assembly language program to perform the multiplication of two
16-bit numbers.
20
2012-13
10ESL47
Microcontrollers Lab
#include "msp430.h"
; #define controlled include file
NAME main
; module name
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
MOV.W #0XFFFF, R4
MOV.W R4, R8
MOV.W #0X1234, R7
MOV.W #00, R5
MOV.W #00, R10
MOV.W #00, R9
CLRC
INC.W R5
UP:
ADD.W R4, R8
JNC COPY
INC.W R9
COPY:INC.W R5
CLRC
CMP.W R5, R7
JNE UP
MOV.W R8, R10
JMP $
END
; R4= FFFF
; R7= 1234, (FFFF x 1234)
; PRODUCT LOWER 16 BIT (DB98)
; PRODUCT UPPER 16 BIT (1233)
; SUCCESSIVE ADDITION
(endless loop)
Result:
Input:
Output:
Note: For square of a number give both the numbers same value.
Assignment: Find the cube of a number.
26. Write an assembly language program to perform the division of two 16-bit
numbers.
21
2012-13
10ESL47
Microcontrollers Lab
#include "msp430.h"
; #define controlled include file
NAME main
; module name
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
UP:
COPY:
DONE:
MOV.W #0XFFFF, R4
MOV.W #0XAA01, R7
MOV.W #00, R5
MOV.W #00, R9
CLRC
MOV.W R4, R10
SUB.W R7, R4
JNC DONE
INC.W R9
CMP.W R5, R4
JNZ UP
JMP $
END
; 16 BIT DIVIDEND
; 16 BIT DIVISOR (FFFF/AA01)
; R9 IS QUOTIENT
; Clear Carry Flag
; R10 IS REMAINDER
; SUCCESSIVE SUBSTRACTION
; (endless loop)
Result:
Input:
Output:
22
2012-13
10ESL47
Microcontrollers Lab
#include "msp430.h"
; #define controlled include file
NAME main
; module name
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
MOV.W #04,R4
UP:
MOV.W #0x9000,R10
MOV.W #00,R11
MOV.W R4, R5
REPEAT:
MOV.W @R10+, R6
MOV.W R6, R8
MOV.W @R10, R7
MOV.W R7, R9
SUB.W R7, R6
JNC NOEXCHG
MOV.W R8, 0(R10)
DEC.W R10
DEC.W R10
MOV.W R9, 0(R10)
INCD.W R10
NOEXCHG: DEC.W R5
CMP.W R11, R5
JNE REPEAT
DEC.W R4
CMP.W R11, R4
JNE UP
JMP $
END
; (endless loop)
Note: For smallest number take the first element in the ascending order sorted array
and for largest number take the first element in the descending order sorted array
23
2012-13
10ESL47
Microcontrollers Lab
#include "msp430.h"
; #define controlled include file
NAME main
; module name
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
AGAIN: MOV.W #0X0000,R5
REP: CALL #DELAY
ADD.W #0X0001,R5
JNZ REP
JMP AGAIN
JMP $
DELAY:
MOV.W #0X50,R6
LOOP1: MOV.W #0X50,R7
LOOP: DEC R7
JNZ LOOP
DEC R6
JNZ LOOP1
RET
END
RESULT: R5 is incremented in binary from 0000, 0001,00020009,000A, 000B,
,000F,0010,0011,FFFF,0000,0001, .
24
2012-13
10ESL47
Microcontrollers Lab
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
AGAIN: MOV.W #0X9999,R5
REP: CALL #DELAY
CLRC
DADD.W #0X9999,R5
JNZ REP
JMP AGAIN
JMP $
DELAY:
MOV.W #0X50,R6
LOOP1: MOV.W #0X50,R7
LOOP: DEC R7
JNZ LOOP
DEC R6
JNZ LOOP1
RET
END
RESULT:
R5 is decremented in BCD from 9999, 9998, , 0000, 9999, 9998
30. Write an assembly language program to convert a 8-bit BCD number into
ASCII.
#include "msp430.h"
25
2012-13
10ESL47
Microcontrollers Lab
NAME main
; module name
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
MOV.B #0X12, R5
MOV.B R5,R6
AND.B #0X0F,R6
ADD.B #0X30,R6
AND.B #0XF0,R5
RRA.B R5
RRA.B R5
RRA.B R5
RRA.B R5
ADD.B #0X30,R5
MOV.B R5,R7
JMP $
END
Result:
Input:
Output:
26
2012-13
10ESL47
Microcontrollers Lab
NAME main
; module name
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
MOV.B #0X35, R5
SUB.B #0X30,R5
MOV.B R5,R6
JMP $
END
Result:
Input:
Output:
Output:
27
2012-13
10ESL47
Microcontrollers Lab
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
MOV.B #0XFE,R5
MOV.B #0X0A,R6
CALL #AA
MOV.B R5,R9
MOV.B R7,R5
CALL #AA
AND.W #0X00FF,R7
SWPB R7
RLA.B R5
RLA.B R5
RLA.B R5
RLA.B R5
ADD.W R5,R7
ADD.W R9,R7
JMP $
AA:
MOV.B #0XFF,R7
LOOP: INC R7
SUB.B R6,R5
JC LOOP
ADD.W #0x0A,R5
RET
END
Result:
Input:
Output:
28
2012-13
10ESL47
Microcontrollers Lab
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
MOV.B #0X99,R5
MOV.B #0X10,R6
MOV.B #0XFF,R7
LOOP: INC R7
SUB.B R6,R5
JC LOOP
ADD.B #0x10,R5
AND.W #0X00FF,R7
MOV.B #0X00,R8
AGAIN:ADD.B #0X0A,R8
DEC R7
JNZ AGAIN
ADD.B R5,R8
JMP $
END
Result:
Input:
Output:
2012-13
10ESL47
Microcontrollers Lab
NAME main
; module name
PUBLIC main
; make the main label visible outside this module
ORG 0FFFEh
DC16 init
; set reset vector to 'init' label
RSEG CSTACK
; pre-declaration of segment
RSEG CODE
; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP
; set up stack
main: NOP
; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
MOV.W #0X1234, R5
MOV.W #0XABCD,R6
MOV.W R6,R7
MOV.W R6,R8
AND.W R5,R6
XOR.W R5,R7
INV.W R8
INV.W R5
AND.W R8,R5
INV.W R5
JMP $
END
//R6=R5 AND R6
//R7=R5 XOR R7
//R8=NOT R8
//R5=R8 OR R5
30
2012-13
10ESL47
Microcontrollers Lab
III. Interfacing
31
2012-13
10ESL47
Microcontrollers Lab
8
0
5
1
P0.0
.
.
P0.7
B1
.
.
B8
DAC
0800
out
CRO
U3
P1.0
.
.
P1.7
B1
.
.
B8
32
DAC
0800
Ch1
Yout
Ch2
2012-13
10ESL47
Microcontrollers Lab
Program:
#include <REG51xD2.H>
void delay(unsigned int x)
{
for(;x>0;x--);
}
/* delay routine */
main()
{
unsigned char on = 0x7f,off=0x00;
unsigned int fre = 230;
while(1)
{
P0=P1=on;
delay(fre);
P0=P1=off;
delay(fre);
}
}
DESIGN:
Let f = 2 kHz, Therefore T = 1/f= 0.5msec,
Count value for the delay is (T/ 1clock cycle period) = 0.5 x 10-3sec/1.085 x 10-6sec
Hence Count value is =460. Hence for 50% Duty cycle the Count value is half of the
Count value=230.
Note: Delay produced by the program will depend on the microcontroller you are
using, so frequency of the waveform generated may not match with the given
frequency.
34. b. Write a C program to generate ramp wave of amplitude ___ V using DAC.
Display the waveform on the CRO.
Program:
#include <REG51xD2.H>
main()
{
unsigned char amp = 0xff;
unsigned char i=0;
P0=P1=0x00;
while(1)
{
{
for(i=0;i<amp;i++)
P0=P1=i;
}
}
/* P0 as Output port */
/* Generate ON pulse */
}
Dept. of ECE, B.I.T., Mangalore
33
2012-13
10ESL47
Microcontrollers Lab
/* P0 as Output port */
/* Generate ON pulse */
/* Generate OFF pulse */
}
34.d
To generate a sine wave, we first need a table whose values represent the
magnitude of the sine of angles between 0 360 degrees. The values for the sine
function vary form -1.0 to +1.0 for 0- to 360- degree angles. Therefore, the table
values are integer numbers representing the voltage magnitude for the sine of theta.
This method ensures that only integer numbers are output to the DAC by the 8051
microcontroller. Table below shows the angles, the sine values, the voltage
magnitudes, and the integer values representing the voltage magnitude for each angle.
To generate table, we assumed the full-scale voltage of 10 V for DAC output. Fullscale output of the DAC is achieved when all the data inputs of the DAC are high.
Therefore, to achieve the full-scale 10 V output, we use following equation.
Vout=5V+(5V*Sin)
Angle
in degrees
0
10
.
.
.
.
.
.
.
350
360
Sin
Vout=5V+(5V*Sin)
34
Values sent to
DAC(decimal) Vout*25.6
2012-13
10ESL47
Microcontrollers Lab
Program:
#include <REG51xD2.H>
void main()
{
unsigned char i,
wave[36]={128,148,171,192,209,225,238,245,253,255,253,
245,238,225,209,192,171,128,104,82,64,43,28,15,07,01,00,0
1,07,15,28,43,64,82,104};
P0 = 0x00;
while(1)
{
for (i=0; i<36; i++)
P0=P1=wave[i];
}
}
35
2012-13
10ESL47
Microcontrollers Lab
8
0
5
1
P 0.0
P 0.7
Stepper
Motor
Driver circuit
Stepper
Motor
Theory:
Stepper motor is an electromechanical device which converts electrical pulses
into discrete mechanical movements. The shaft or spindle of a stepper motor rotates in
discrete step increments when electrical command pulses are applied to it in the
proper sequence. The motors rotation has several direct relationships to these applied
input pulses. The sequence of the applied pulses is directly related to the direction of
motor shafts rotation. The speed of the motor shafts rotation is directly related to the
frequency of the input pulses and the length of rotation is directly related to the
number of input pulses applied.
Stepper Motor Advantages:
1. The rotation angle of the motor is proportional to the input pulse.
2. The motor has full torque at standstill (if the windings are energized)
3. Precise positioning and repeatability of movement since good stepper motors have
an accuracy of 3 5% of a step and this error is non cumulative from one step to
the next.
4. Excellent response to starting/stopping/reversing.
5. Very reliable since there are no contact brushes in the motor. Therefore the life of
the motor is simply dependant on the life of the bearing.
6. The motors response to digital input pulses provides open-loop control, making the
motor simpler and less costly to control.
1. It is possible to achieve very low speed synchronous rotation with a load that is
directly coupled to the shaft.
2. A wide range of rotational speeds can be realized as the speed is proportional to
the frequency of the input pulses.
Stepper Motor Disadvantages:
1. Resonances can occur if not properly controlled.
2. Not easy to operate at extremely high speeds.
Open Loop Operation:
One of the most significant advantages of a stepper motor is its ability to be
accurately controlled in an open loop system. Open loop control means no feedback
information about position is needed. This type of control eliminates the need for
expensive sensing and feedback devices such as optical encoders. Your position is
known simply by keeping track of the input step pulses.
Stepper Motor Types:
Variable-reluctance
Permanent-magnet
36
Hybrid
2012-13
10ESL47
Microcontrollers Lab
/* Delay Routine */
Motor Specifications:
Step Angle = 1.8 degrees
Step angle accuracy = 5%
Holding Torque = 40Ncm
Rotor Inertia = 115grcm2
Weight = 0.5Kg
Insulation = Class B
37
2012-13
10ESL47
Microcontrollers Lab
8
0
5
1
P1.0
.
.
P1.7
LCD
KEY
BOARD
P2
P0
Keyboard:
HEX
CODE
LABLE ON THE
KEYTOP
HEX
CODE
0
1
2
3
4
5
6
7
8
9
.
+
0
1
2
3
4
5
6
7
8
9
0A
0B
*
/
%
AC
CE
CHK
=
MC
MR
M
M+
0C
0D
0E
0F
10
11
12
13
14
15
16
17
38
2012-13
10ESL47
Microcontrollers Lab
39
2012-13
10ESL47
Microcontrollers Lab
Additional Programs
1. Program to check whether given number is palindrome or not.
mov 30h,#81h
mov r0,30h
mov r1,#08h
mov 31h,#00h
clr c
back: mov a,30h
rlc a
mov 30h,a
mov a,31h
rrc a
mov 31h,a
djnz r1,back
cjne a,00h,npal
mov a,#0ffh
sjmp next
npal: mov a,#00h
next: sjmp $
end
2. Program to find the average of N eight-bit numbers.
Mov dptr, #9000h
Mov r0, #04h
Mov r1, #00h
Mov r2, #00h
Clr c
Mov r4, #04h
Back: mov a, @dptr
Mov r3, a
Inc dptr
Mov a, r1
Add a, r3
Jnc ahead
Inc r2
Ahead: mov r1,a
Djnz r0,back
Mov r5, #00h
Clr c
Mov a,r1
Again:subb a, r4
Inc r5
Jc next
Sjmp again
Next:cjne r2,#00,loc
Dec r5
Dept. of ECE, B.I.T., Mangalore
Add a,r4
Movx @dptr,a
Mov a,r5
Inc dptr
Movx @dptr, a
Sjmp end1
Loc: dec r2
Sjmp again
End1:lcall 0003h
end
40
2012-13
10ESL47
Microcontrollers Lab
41
2012-13
10ESL47
Microcontrollers Lab
Viva Questions
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
42
2012-13
10ESL47
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
Microcontrollers Lab
43
2012-13
10ESL47
Microcontrollers Lab
Explain the function of the PCON register during serial data communication.
How the Serial data interrupts are generated?
How is data transmitted serially in the 8051? Explain briefly.
How is data received serially in the 8051? Explain briefly.
What are the various modes of Serial Data Transmission? Explain each mode
briefly.
95. Explain with a timing diagram the shift register mode in the 8051.
96. What is the use of the serial communication mode 0 in the 8051?
97. Explain in detail the Serial Data Mode 1 in the 8051.
98. Explain how the Baud rate is calculated for the Serial Data Mode 1.
99. How is the Baud rate for the Multiprocessor communication Mode calculated?
100. Explain in detail the Multiprocessor communication Mode in the 8051.
101. Explain the significance of the 9th bit in the Multiprocessor communication
Mode.
102. Explain the Serial data mode 3 in the 8051.
103. What are interrupts and how are they useful in Real Time Programming?
104. Briefly describe the Interrupt structure in the 8051.
105. Explain about vectored and non-vectored interrupts in general.
106. What are the five interrupts provided in the 8051?
107. What are the three registers that control and operate the interrupts in 8051?
108. Describe the Interrupt Enable (IE) special function register and its various
bits.
109. Describe the Interrupt Priority (IP) special function register and its need.
110. Explain in detail how the Timer Flag interrupts are generated.
111. Explain in detail how the Serial Flag interrupt is generated.
112. Explain in detail how the External Flag interrupts are generated.
113. What happens when a high logic is applied on the Reset pin?
114. Why the Reset interrupt is called a non-maskable interrupt?
115. Why do we require a reset pin?
116. How can you enable/disable some or all the interrupts?
117. Explain how interrupt priorities are set? And how interrupts that occur
simultaneously are handled.
118. What Events can trigger interrupts, and where do they go after getting
triggered?
119. What are the actions taken when an Interrupt Occurs?
110. What are Software generated interrupts and how are they generated?
111. What is RS232 and MAX232?
112. What is the function of RS and E pins in an LCD?
113. What is the use of R/W pin in an LCD?
114. What is the significance of DA instruction?
115. What is packed and unpacked BCD?
116. What is the difference between CY and OV flag?
117. When will the OV flag be set?
118. What is an ASCII code?
90.
91.
92.
93.
94.
44
2012-13
10ESL47
Microcontrollers Lab
45
2012-13
10ESL47
Microcontrollers Lab
46
2012-13
10ESL47
Microcontrollers Lab
Instruction set
47
2012-13
10ESL47
Microcontrollers Lab
48
2012-13
10ESL47
Microcontrollers Lab
49
2012-13