Вы находитесь на странице: 1из 23

10CSL48

MICROPROCESSOR AND MICROCONTROLLER


LABORATORY MANUAL

ACADEMIC YEAR 2017-18

Prepared by:

Anand D
Anusha
Keerti N
Roopa P
COURSE LABORATORY MANUAL

A. LABORATORY OVERVIEW
Degree: BE Programme: CSE
Semester: 4 Academic Year: 2017-18
Microprocessors and
Laboratory Title: Laboratory Code: 15CSL48
Microcontroller Laboratory
L-T-P-S: 1-0-2-0 Duration of USE: 3 Hrs
Total Contact Hours: 42 Hrs USE Marks: 80
Credits: 2 IA Marks: 20

B. DESCRIPTION
1. PREREQUISITES:
• Microprocessors And ARM Processors(15CS44)
• Basic Electronics (15ELN15)
• Analog and Digital Electronics(15CS32)
• Computer programming laboratory (15CPL16)
• Programming in C and Data Structures (15PCDS13).

2. BASE COURSE:
• Microprocessors and Microcontrollers (15CS44)

3. COURSE OUTCOMES:
At the end of the course, the student will be able to
 Apply the programming techniques in designing simple assembly language programs for solving
simple problems by using instruction set of 8086 microprocessor / ARM.
 Gain hands-on experience in doing experiments on 8086 microprocessor / ARM by using
Assembler tool (MASM / MASM) in the laboratory and present the report.
 Understand the hardware, software tradeoffs involved in the design and interface hardware
devices to x86/ARM family.
 Assess processors for various kinds of applications.

4. GENERAL INSTRUCTIONS:
Start Run… cmd
MASM COMMANDS:
D:\ masm > edit filename.asm ; Write the program and save.
D:\ masm > masm filename.asm; If any errors, correct the same.
D:\ masm > link filename.obj
D:\ masm > debug filename.exe ; debugger command prompt

After the debugger command prompt the following commands are used;
a – assemble
d – dump (to view the contents of the data memory)
g – go (to execute the entire program at a time)
u – unassemble
t – trace (to execute the program in single step)
r – register (to see the contents of the register)
q – quit
? – to view all the options
5. CONTENTS:
Expt Blooms
Title of the Experiments CO
No. Level
Design and develop an assembly language program to search a key element
1 “X” in a L3 CO1,2,3,4
list of ‘n’ 16-bit numbers. Adopt Binary search algorithm in your program
for searching.
2 Design and develop an assembly program to sort a given set of ‘n’ 16-bit L3 CO1,2,3,4
numbers in ascending order. Adopt Bubble Sort algorithm to sort given
elements.
3 Develop an assembly language program to reverse a given string and L3 CO1,2,3,4
verify whether it is a palindrome or not. Display the appropriate message.
4 Develop an assembly language program to compute nCr using recursive L3 CO1,2,3,4
procedure. Assume that ‘n’ and ‘r’ are non-negative integers.

Design and develop an assembly language program to read the current time
5 and display. L3 CO1,2,3,4

To write and simulate ARM assembly language programs for data transfer,
arithmetic and logical operations (Demonstrate with the help of a suitable
6 program). L3 CO1,2,3,4

7 To write and simulate C Programs for ARM microprocessor in KEIL L3 CO1,2,3,4


a. Design and develop an assembly program to demonstrate BCD Up-Down
Counter (00-99) on the Logic Controller Interface.
b. Design and develop an assembly program to read the status of two 8-bit
8 inputs (X & Y) from the Logic Controller Interface and display X*Y. L4 CO1,2,3,4
Design and develop an assembly program to display messages “FIRE” and
“HELP” alternately with flickering effects on a 7-segment display interface for
a suitable period of time. Ensure a flashing rate that makes it easy to read
both the messages (Examiner does not specify these delay values nor is it
9 necessary for the student to compute these values). L3 CO1,2,3,4
Design and develop an assembly program to drive a Stepper Motor interface
and rotate the motor in specified direction (clockwise or counter-clockwise)
by N steps (Direction and N are specified by the examiner). Introduce suitable
delay between successive steps. (Any arbitrary value for the delay may be
10 assumed by the student). L4 CO1,2,3,4
Design and develop an assembly language program to
a. Generate the Sine Wave using DAC interface (The output of the DAC is to
be displayed on the CRO).
b. Generate a Half Rectified Sine waveform using the DAC interface. (The
11 output of the DAC is to be displayed on the CRO). L4 CO1,2,3,4

To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and


execute programs in C language for displaying text messages and numbers on
12 LCD L3 CO1,2,3,4

To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148.


Write a program to rotate stepper motor
13 L3 CO1,2,3,4
Study Experiments:
1. Interfacing of temperature sensor with ARM freedom board (or any other ARM
microprocessor board) and display temperature on LCD
2. To design ARM cortex based automatic number plate recognition system
3. To design ARM based power saving system

Conduction of Practical Examination:


 All laboratory experiments (all 7 + 6 nos) are to be included for practical examination.
 Students are allowed to pick one experiment from each of the lot.
 Strictly follow the instructions as printed on the cover page of answer script for breakup of marks
PART –A: Procedure + Conduction + Viva: 10 + 25 +05 (40)
PART –B: Procedure + Conduction + Viva: 10 + 25 +05 (40)
 Change of experiment is allowed only once and marks allotted to the procedure part to be made
zero.
1. Design and develop an assembly language program to search a key element “X” in a
list of ‘n’ 16-bit numbers. Adopt Binary search algorithm in your program
for searching.

Theory: Binary search is a well-known method for searching for an item in a sorted array. In the beginning
the search range is the whole array. Then the search key is compared with the middle element of the
range. If they are equal, the wanted item has been found. If the key is smaller, the same procedure is
applied recursively to the left half of the search range, otherwise to the right half .

Program

.model small
.stack 20

.data
a dw 1112h,1234h,2356h,3478h,0ab88h,0bd90h,0ff93h
count equ ($-a)/2
key dw 0bd90h
msg1 db 0dh,0ah,"search successful, key present at position $"
msg2 db 0dh,0ah,"search unsuccessful$"

.code
start: mov ax,@data
mov ds,ax
mov bx,00
mov dx,count
mov cx,key

back: cmp dx,bx


jl fail
mov ax,bx
add ax,dx
shr ax,1
mov si,ax
add si,si
cmp a[si],cx
jz success
cmp cx,a[si]
jnc big
dec ax
mov dx,ax
jmp back
big: inc ax
mov bx,ax
jmp back

success: mov bl,al


lea dx,msg1
mov ah,09h
int 21h
mov dl,bl
add dl,31h
mov ah,02h
int 21h
jmp ahead

fail: lea dx,msg2


mov ah,09h
int 21h
ahead: mov ah,4ch
int 21h

end start

Output:

sample input 1 :
list a : 0001h,0002h,0003h,0004h,0005h
key = 0002h
output :
search successful.
key element found at position 2.

sample input 2:
list a: 0001h,0002h,0003h,0004h,0005h
key = 0009h
output :
search unsuccessful.

2. Design and develop an assembly program to sort a given set of ‘n’ 16-bit numbers in ascending order.
Adopt Bubble Sort algorithm to sort given elements.

Theory
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps
through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the
wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the
list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements
"bubble" to the top of the list.

Program
.model small
.stack 20

.data
list dw 0c05h, 0120h, 0123h, 0004h
count equ 04h

.code

start: mov ax,@data


mov ds,ax

mov dx,count-1

outer : mov cx,dx


mov si,offset list

inner: mov ax,[si]


cmp ax,[si+2]
jl ahead1
xchg [si+2],ax
mov [si],ax

ahead1:inc si
inc si
loop inner
dec dx
jnz outer
mov ah,4ch
int 21h

end start

Output:
The unsorted array input is
0c05h, 0120h, 0123h, 0004h
Sorted output is
0004h, 0120h, 0123h, 0c05h

3. Develop an assembly language program to reverse a given string and verify whether it is a palindrome
or not. Display the appropriate message.

Theory
PALINDROME CHECK: This program waits till it receives a string of characters from the standard input
device(keyboard),terminated by the carriage return, and stores the string in an array called str. The
reversed string is stored in another array called rev_str. The two strings are compared character wise; for
checking whether the original string is palindrome. Necessary messages are displayed using DOS function
calls.
Program
.model small
.stack 20

.data
msg1 db 0dh,0ah,"The givenstring is Palindrome.$"
msg2 db 0dh,0ah,"The givenstring is not a Palindrome.$"
givenstring db "liril"
n dw $-givenstring
reversedstring db 10 dup(0)

.code
start:
mov ax,@data
mov ds,ax

mov si,0
mov di,0
mov cx,n
add si,cx
dec si

loop1: mov al,givenstring[si]


mov reversedstring[di],al .
dec si
inc di
loop loop1
mov si,0
mov cx,n

loop2: mov al,givenstring[si]


cmp al,reversedstring[si]
je loop3
lea dx,msg2
mov ah,09h
int 21h
mov ah,4ch
int 21h

loop3: inc si
loop loop2
lea dx,msg1
mov ah,09h
int 21h
mov ah,4ch
int 21h

end start

Output:
For string liril : The givenstring is Palindrome.
For string hello : The givenstring is not Palindrome.

4. Develop an assembly language program to compute nCr using recursive procedure. Assume that ‘n’
and ‘r’ are non-negative integers.

Theory
The ncr program computes nCr(no. of combinations of n, taken r at a time),using recursive procedure
where n and r are stored in wordwide memory locations.
Recursive definition for nCr:

Case1: If r=0 OR r=n, then nCr = 1 Case2: If r=1 OR r=n-1, then nCr = n

Case3: Other cases, nCr = (n-1)Cr + (n-1)C(r-1)

Program
//Calculating nCr value.
.MODEL SMALL
.DATA
N DB 4
R DB 2
NCR DB 0
.CODE
START: MOV AX,@DATA
MOV DS,AX
MOV AL,N
MOV BL,R
CALL NCRPRO
MOV AH,4CH
INT 21H

NCRPRO PROC NEAR


CMP BL,AL
JE RES1
CMP BL,0
JE RES1
CMP BL,1
JE RES
DEC AL
CMP BL,AL
JE INCR
PUSH AX
PUSH BX
CALL NCRPRO
POP BX
POP AX
DEC BX
PUSH AX
PUSH BX
CALL NCRPRO
POP BX
POP AX
RET
RES1:INC NCR
RET
INCR:INC NCR
RES:ADD NCR,AL
RET
NCRPRO ENDP

END START

Output:
n-4
r-2
ncr=6

5. Design and develop an assembly language program to read the current time and display.

Theory: The program for reading system time reads the system time ,using DOS ;function call number
2CH. The hour, minute and second are returned in CH, CL and DH registers (in HEX form) respectively, by
the DOS function. It is then converted into ASCII for display purpose.

Program
.model small
.data
hrs db ?
min db ?
sec db ?

.code
start:
mov ax,@data
mov ds,ax
mov ah,2ch
int 21h
mov hrs,ch
mov min,cl
mov sec,dh

mov al,hrs
call disp1
call disp2
mov al,min
call disp1
call disp2
mov al,sec
call disp1
mov ah,4ch
int 21h

disp1 proc
aam
add ax,3030h
mov bx,ax
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
mov ah,02h
int 21h
ret
disp1 endp

disp2 proc
mov dl,':'
mov ah,02h
int 21h
ret
disp2 endp
end start

Output: 12:30:23

6.To write and simulate ARM assembly language programs for data transfer, arithmetic and logical
operations (Demonstrate with the help of a suitable program).

Theory
ARM processor is easy to program at the assembly level.

The state of an ARM system is determined by the content of visible registers and memory.

• A user-mode program can see 15 32-bit general purpose registers (R0-R14), program counter
(PC) and CPSR.
• Memory system of ARM is a linear array of bytes addressed from 0 to 232-1.
• ARM instructions are all 32-bit long (except for Thumb mode). There are 232 possible machine
instructions. Fortunately, they are structured.

Features of ARM instruction set-


Load-store architecture
3-address instructions
Conditional execution of every instruction
Possible to load/store multiple registers at once
Possible to combine shift and ALU operations in a single instruction
Instruction set is of following types:
Data processing
Data movement
Flow control

Program
1.Area add, code, readonly
Ldr r1,=0x00000005
Ldr r2,=0x00000004
add r3,r1,r2
Nop
Nop
End

2.Area add, code, readonly


Ldr r1,=0x00000005
Ldr r2,=0x00000002
and r3,r1,r2
Nop
Nop
End

7.To write and simulate C Programs for ARM microprocessor in KEIL


Program
#include<lpc214x.h>
int main(void)
{
int a,b,c;
a=4;
b=5;
c= a+b;
}

int main(void)
{
int a,b,c;
a=1;
b=1;
if(a==1 && b==1)
printf(“true”);

8a. Design and develop an assembly program to demonstrate BCD Up-Down Counter (00-99) on the Logic
Controller Interface.

model small
.stack 20
.data
base_address equ 0e880h
control equ base_address+03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
.code
start:
mov ax,@data
mov ds,ax
mov dx,control
mov al,8ah
out dx,al
mov al,00h
up: mov dx,porta
out dx,al
call delay
cmp al,19h
jnz next
jmp stop
next: add al,01h
daa
jmp up
stop:mov ah,4ch
int 21h

delay proc near


mov cx,0ffffh
up1: mov bx,0ffffh
up2:
dec bx
jnz up2
loop up1
ret
delay endp
end start

b. Design and develop an assembly program to read the status of two 8-bit inputs (X & Y) from the Logic
Controller Interface and display X*Y.
.model small
.stack 20h
.data
msg1 db 'input x ',0dh,0ah,'$'
msg2 db 'input y ',0dh,0ah,'$'
msg3 db 'output the result on port a',0dh,0ah,'$'
base_address equ 0e880h
control equ base_address+03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
.code
start:
mov ax,@data
mov ds,ax
mov al,8ah
mov dx,control
out dx,al
mov al,00
mov dx,porta
out dx,al
lea dx,msg1
mov ah,09h
int 21h
mov ah,01
int 21h
mov dx,portb
in al,dx
mov cl,al
lea dx,msg2
mov ah,09h
int 21h
mov ah,01
int 21h
mov dx,portb
in al,dx
mov ch,al
lea dx,msg3
mov ah,09h
int 21h
mov ah,01h
int 21h
mov al,ch
mul cl
mov dx,porta
out dx,al
mov al,ah
and al,0fh
mov dx,portc
out dx,al
mov ah,4ch
int 21h
end start

9.Design and develop an assembly program to display messages “FIRE” and “HELP” alternately with
flickering effects on a 7-segment display interface for a suitable period of time. Ensure a flashing rate
that makes it easy to read both the messages.
.model small
.stack 20
.data
base_address equ 20c0h
control equ base_address+03h ;control port
porta equ base_address+00h ;porta address
portb equ base_address+01h ;portb address
portc equ base_address+02h ;portc address
Blanks db 0,0,0,0,0,0
fire db 0,0,79h,50h,06h,71h
help db 73h,38h,79h,76h,0,0

.code
start:
mov ax,@data
mov ds,ax
mov al,80h
mov dx,control
out dx,al
;----------display fire ---------------------------------------
up: mov di,150
fir: mov si,offset fire
call display
dec di
jnz fir
;----------display blank -------------------------------------
mov di,300
blnk: mov si,offset blanks
call display
dec di
jnz blnk
;----------display help ---------------------------------------
mov di,150
hlp: mov si,offset help
call display
dec di
jnz hlp
;----------display blank -------------------------------------
mov di,300
blnk1: mov si,offset blanks
call display
dec di
jnz blnk1

;----------keep looping till any key is pressed-----------


mov ah,0bh
int 21h
or al,al
jz up
;----------terminate-------------------------------------------
mov ah,4ch
int 21h
display proc
mov dx,portc
mov al,07h
out dx,al
mov cx,06h
mov bl,00h
select:
mov al,bl
mov dx,portc
out dx,al

mov dx,porta

lodsb
out dx,al
call delay
inc bl
cmp bl,05
jle down
mov bl,00
down:
loop select
ret

display endp
delay proc
push bx
push cx
mov cx,0ffh
up1: mov bx,0fffh
up2: dec bx
jnz up2
loop up1
pop cx
pop bx
ret
delay endp
end start

10.Design and develop an assembly program to drive a Stepper Motor interface and rotate the motor in
specified direction (clockwise or counter-clockwise) by N steps (Direction and N are specified by the
examiner). Introduce suitable delay between successive steps.

.model small
.stack 20h
.data
base_address equ 20c0h
control equ base_address+03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
.code
start:
mov ax,@data
mov ds,ax
mov al,80h
mov dx,control
out dx,al
again: mov cx,5
up:
mov al,077h
mov dx,portc
out dx,al
call delay
mov al,0bbh
out dx,al
call delay
mov al,0ddh
out dx,al
call delay
mov al,0eeh
out dx,al
call delay
loop up
mov cx,5
up1:
mov al,0eeh
mov dx,portc
out dx,al
call delay
mov al,0ddh
out dx,al
call delay
mov al,0bbh
out dx,al
call delay
mov al,077h
out dx,al
call delay
loop up1
mov ah,0bh
int 21h
or al,al
jz again
mov ah,4ch
int 21h
end start

// STEPPER MOTOR INTERFACING


//--------------------------------------------------------------
// CONTROLLER : LPC-2148
// DATE : JULY - 2016
// Developed By : Advanced Electronic Systems Bangalore,India
//----------------------------------------------------------------
//-------------------------------------------------------------------
// A stepper motor direction is controlled by shifting the voltage across
// the coils. Port lines : P1.20 to P1.23
//-------------------------------------------------------------------
#include <LPC21xx.h>

void clock_wise(void) ;
void anti_clock_wise(void) ;

unsigned int var1 ;


unsigned long int i = 0 , j = 0 , k = 0 ;

int main(void)
{
PINSEL2 = 0x00000000; //P1.20 to P1.23 GPIO
IO1DIR |= 0x00F00000 ; //P1.20 to P1.23 made as output

while(1)
{

for( j = 0 ; j < 50 ; j++ ) // 50 times in Clock wise Rotation


clock_wise() ; // rotate one round clockwise

for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show anti_clock Rotation

for( j=0 ; j < 50 ; j++ ) // 50 times in Anti Clock wise Rotation


anti_clock_wise() ; // rotate one round anticlockwise

for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show ANTI_clock Rotation

}// End of main

void clock_wise(void)
{
var1 = 0x00080000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ;

IO1CLR =0x00F00000 ; //clearing all 4 bits

IO1SET = var1 ; // setting perticular bit

for( k = 0 ; k < 3000 ; k++ ); //for step speed variation

void anti_clock_wise(void)
{
var1 = 0x00800000 ; //For Anticlockwise

IO1CLR =0x00F00000 ; //clearing all 4 bits

IO1SET = var1 ;

for( k = 0 ; k < 3000 ; k++ ) ;


for( i = 0 ; i < 3 ; i++ ) // for A B C D Stepping
{
var1 >>=1; //rotating bits
IO1CLR =0x00F00000 ; // clar all bits before setting

IO1SET = var1 ; // setting perticular bit

for( k = 0 ; k < 3000 ; k++ ) ; //for step speed variation

}
}

11.Design and develop an assembly language program to


a. Generate the Sine Wave using DAC interface (The output of the DAC is to be displayed on the CRO).
.model small
.stack 20h
.data
base_address equ 20c0h
control equ base_address+03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
table db 128,150,171,195,210,226,238,248,254,255,254,248,238,226,210,195,171,150,128,
105,84,64,45,30,17,8,2,0,2,8,17,30,45,64,84,105
.code
start: mov ax,@data
mov ds,ax
mov al,80h
mov dx,control
out dx,al
up:
lea bx,table
mov cx,36
next:
mov al,[bx]
mov dx,portb
out dx,al
inc bx
call delay
loop next
mov ah,0bh
int 21h
or al,al
jz up
mov ah,4ch
int 21h
delay proc
push cx
push bx
mov cx,000fh
up2:
mov bx,000fh
up1:
dec bx
jnz up1
loop up2
pop bx
pop cx
ret
delay endp
end start

b. Generate a Half Rectified Sine waveform using the DAC interface. (The output of the DAC is to be
displayed on the CRO).
.model small
.stack 20h
.data
base_address equ 20c0h
control equ base_address+03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
table db 128,150,171,195,210,226,238,248,254,255,254,248,238,226,210,195,171,150
.code
start:
mov ax,@data
mov ds,ax
mov al,80h
mov dx,control
out dx,al
up:
lea bx,table
mov cx,18
next:
mov al,[bx]
mov dx,portb
out dx,al
inc bx
call delay
loop next
mov cx,18
mov al,128
up1:
mov dx,portb
out dx,al
call delay
loop up1
mov ah,0bh
int 21h
or al,al
jz up
mov ah,4ch
int 21h
delay proc
push cx
push bx
mov cx,000fh
up3:
mov bx,000fh
up2:
dec bx
jnz up2
loop up3
pop bx
pop cx
ret
delay endp
end start

12.To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and execute programs in C
language for displaying text messages and numbers on LCD.
#include<lpc214x.h>
#include<stdio.h>
//Function prototypes
void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);

unsigned char temp1;


unsigned long int temp,r=0;
unsigned char *ptr,disp[] = "ALS BENGALURU",disp1[] = "LCD INTERFACING";

int main()
{
PINSEL0 = 0X00000000; // configure P0.0 TO P0.15 as GPIO
IO0DIR = 0x000000FC; //configure o/p lines for lcd [P0.2-P0.7]

lcd_init(); //lcd intialisation


delay(3200); // delay 1.06ms

clr_disp(); //clear display


delay(3200); // delay 1.06ms

temp1 = 0x81; //Display starting address of first line 2nd pos


lcd_com(); //function to send command to lcd

ptr = disp; // pointing data


while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data(); //function to send data to lcd
ptr ++;
}

temp1 = 0xC0; // Display starting address of second line 1st pos


lcd_com(); //function to send command to lcd

ptr = disp1; // pointing second data


while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data(); //send data to lcd
ptr ++;
}
while(1);

} //end of main()

// lcd initialisation routine.


void lcd_init(void)
{
temp = 0x30; //command to test LCD voltage level
wr_cn();
delay(3200);

temp = 0x30; //command to test LCD voltage level


wr_cn();
delay(3200);

temp = 0x30; //command to test LCD voltage level


wr_cn();
delay(3200);

temp = 0x20; // change to 4 bit mode from default 8 bit mode


wr_cn();
delay(3200);

temp1 = 0x28; // load command for lcd function setting with lcd in 4 bit mode,
lcd_com(); // 2 line and 5x7 matrix display
delay(3200);

temp1 = 0x0C; // load a command for display on, cursor on and blinking off
lcd_com();
delay(800);

temp1 = 0x06; // command for cursor increment after data dump


lcd_com();
delay(800);

temp1 = 0x80; // set the cursor to beginning of line 1


lcd_com();
delay(800);
}

void lcd_com(void)
{
temp = temp1 & 0xf0; //masking higher nibble first
wr_cn();
temp = temp1 & 0x0f; //masking lower nibble
temp = temp << 4;
wr_cn();
delay(500); // some delay
}

// command nibble o/p routine


void wr_cn(void) //write command reg
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0CLR = 0x00000004; // clear bit RS = 0
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008; //E=0
}

// data nibble o/p routine


void wr_dn(void) ////write data reg
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0SET = 0x00000004; // set bit RS = 1
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008; //E=0
}

// data o/p routine which also outputs high nibble first


// and lower nibble next
void lcd_data(void)
{
temp = temp1 & 0xf0; //masking higher nibble first
temp = temp ;
wr_dn();
temp= temp1 & 0x0f; //masking lower nibble
temp= temp << 4; //shift 4bit to left
wr_dn();
delay(100);
}

void clr_disp(void) // function to clear the LCD screen


{
temp1 = 0x01;
lcd_com();
delay(500);
}

void delay(unsigned int r1) // delay function using for loop


{
for(r=0;r<r1;r++);
}

13.To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148. Write a program to rotate
stepper motor
// A stepper motor direction is controlled by shifting the voltage across
// the coils. Port lines : P1.20 to P1.23
//-------------------------------------------------------------------
#include <LPC21xx.h>
void clock_wise(void) ;
void anti_clock_wise(void) ;
unsigned int var1 ;
unsigned long int i = 0 , j = 0 , k = 0 ;
int main(void)
{
PINSEL2 = 0x00000000; //P1.20 to P1.23 GPIO
IO1DIR |= 0x00F00000 ; //P1.20 to P1.23 made as output

while(1)
{
for( j = 0 ; j < 50 ; j++ ) // 50 times in Clock wise Rotation clock_wise() ;
// rotate one round clockwise

for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show anti_clock Rotation

for( j=0 ; j < 50 ; j++ ) // 50 times in Anti Clock wise Rotation anti_clock_wise() ;
// rotate one round anticlockwise
for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show ANTI_clock Rotation
}
}// End of main

void clock_wise(void)
{
var1 = 0x00080000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ;

IO1CLR =0x00F00000 ; //clearing all 4 bits

IO1SET = var1 ; // setting perticular bit

for( k = 0 ; k < 3000 ; k++ ); //for step speed variation

void anti_clock_wise(void)
{
var1 = 0x00800000 ; //For Anticlockwise

IO1CLR =0x00F00000 ;
//clearing all 4 bits

IO1SET = var1 ;

for( k = 0 ; k < 3000 ; k++ ) ;

for( i = 0 ; i < 3 ; i++ ) // for A B C D Stepping


{
var1 >>=1;
//rotating bits
IO1CLR =0x00F00000 ; // clar all bits before setting

IO1SET = var1 ; // setting perticular bit

for( k = 0 ; k < 3000 ; k++ ) ; //for step speed variation


}
}

Вам также может понравиться