Professional Documents
Culture Documents
Microprocessors Lab Manual Part A Software Programs
Microprocessors Lab Manual Part A Software Programs
Microprocessors Lab Manual Part A Software Programs
LAB MANUAL
PART A
SOFTWARE PROGRAMS
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.
.data
array dw 1234h,2345h,3456h,4567h,5678h
len dw ($-array)/2
srchkey equ 0456h
msg1 db "Element Found ",'$'
msg2 db "Element Not Found ",'$'
.code
start: mov ax,@data
mov ds,ax
mov bx,01
mov cx,srchkey
mov dx,len
bigger:je success
inc ax
mov bx,ax
jmp again
success:lea dx,msg1
jmp display
failure:lea dx,msg2
display:mov ah,09h
int 21h
mov ah,4ch
int 21h
end
.data
array dw 1010h,2511h,1222h,1643h,5432h
len db $-array
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov cl,len
dec cl
nochange:inc si
inc si
dec ch
jnz up1
cmp dl,0
je last
dec cl
jnz up2
end
.data
str_read db "Enter the String : ",'$'
str1 db 255 dup('$')
str_rev db "Reveresed String is : ",'$'
str2 db "String is Palindrome",'$'
str3 db "String is not Palindrome",'$'
newline db 13,10,'$'
.code
start: mov ax,@data
mov ds,ax
mov si,0
Printf str_read
Printf newline
Printf str2
jmp stop
end
.data
n dw 6
r dw 4
ncr dw 1
msg db "the ncr is :$"
.code segment
start:
mov ax,@data
mov ds,ax
mov bx,n
inc bx
mov cx,r
call ncp
lea dx,msg
mov ah,09h
int 21h
mov ax,ncr
call display
mov ah,4ch
int 21h
ncp proc near
cmp cx,00h
je l1
push cx
dec cx
call ncp
mov ax,bx
pop cx
sub ax,cx
mul ncr
div cx
mov ncr,ax
l1: ret
ncp endp
display proc
aam
add ax,3030h
mov bx,ax
mov dl,bh
mov ah,02h
int 21h
end
.data
msg db 'the current time is : $'
msg1 db 10,13,'the current date is : $'
.code
start: mov ax,@data
mov ds,ax ;initialise ds
lea dx,msg ;display the message
mov ah,09h
int 21h
mov ah,2ch ;dos function to get the current system time
int 21h
mov al,ch ; CH stores the hours returned
call display
mov dl,':’ ; display the char ':'
mov ah,02h
int 21h
mov al,cl ; CL stores the minute returned
call display
mov dl,':' ; display the char ':'
mov ah,02h
int 21h
mov al,dh ; DH stores the second returned
call display
end
AREA PROGRAM,CODE,READONLY
START
LDR R1,VALUE1
LDR R2,VALUE2
LDR R3,VALUE3
LDR R4,VALUE4
LDR R5,VALUE5
MOV R6,R1
ADD R7,R1,R2
ADD R8,R3,#1
ADDS R9,R4,R5
ADC R10,R1,R2
SUB R11,R2,#1
MUL R12,R1,R2
AND R5,R1,R2
ORR R6,R1,R2
EOR R7,R1,R2
STR R1,RESULT
SWI &11
VALUE1 DCD &00000001
VALUE2 DCD &00000002
VALUE3 DCD &00000003
VALUE4 DCD &00000004
VALUE5 DCD &FFFFFFFF
RESULT DCD 0
END
#include<lpc21xx.h>
int main(void)
{
int var1=10;
int var2=20;
int sum, diff, mu, div;
sum = var1 + var2;
diff = var1 - var2;
mu = var1*var2;
div=var1/var2;
Write two ALP modules stored in two different files; one module is to read a character
from the keyboard and the other one is to display a character. Use the above two modules
to read a string of characters from the keyboard terminated by the carriage return and
print the string on the display in the next line.
; Module 1 from which we are going to read the character from the standard output
; Name should became as by which we are going to include in the 3 module
readkb macro
mov ah,01h
int 21h
endm
; Module 2 from which we are going to write it onto the standard output
; Name should became as by which we are going to include in the 3 module
writeout macro
mov dl,al
mov ah,02h
int 21h
endm
; Module 3 from where we are going to read and write the Program from the Standard
output and Standard input same the file differently.
data segment
str1 db 255 dup(?)
newline db 13,10,'$'
data ends
code segment
assume cs:code,ds:data
start: include c:\masm\read.asm
include c:\masm\write.asm
mov ax,data
mov ds,ax
mov si,0
stdin:readkb
cmp al,0dh
jz newline1
mov str1[si],al
data segment
f_str db 255 dup('$')
s_str db 255 dup('$')
first_str_msg db " Enter the First String : ", '$'
second_str_msg db " Enter the Second String : ", '$'
str_equal db "Both String are Equal",'$'
str_not_equal db "Both String are not equal",'$'
first_str_length db "Length of First String : ",'$'
second_str_length db "Length of Second String : ",'$'
newline db 13,10,'$'
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov si,0
printf first_str_msg
mov ax,si
call display
printf newline
printf second_str_length
mov ax,di
call display
printf newline
printf str_equal
jmp end1
;display proc
display proc
aam
add ax,3030h
mov bx,ax
mov dl,bh
mov ah,02h
int 21h
mov dl,bl
code ends
end start
PART B
DATA SEGMENT
MSG1 DB "STIMULATING BCD UP_DOWN COUNTER $"
NEWLINE DB 13,10,’$’
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
PRINTF MSG1
MOV AL,82H ; move the control word into CWR
MOV DX,0D483H
OUT DX,AL
MOV DX,0D480H ; port A used as o/p port
MOV AL,0
UP_CNTR: OUT DX,AL ; o/p the count
CMP AL,100 ; if count >=9 start down counter
JZ NEXT1
INC AL ; else increment AL and loop back
CALL DELAY ; wait after each display
JMP UP_CNTR
DELAY PROC
PUSH BX
PUSH CX
MOV CX,4FFFH
LOOP2:MOV BX,0FFFFH
LOOP1:DEC BX
JNZ LOOP1
LOOP LOOP2
POP CX
POP BX
DATA SEGMENT
PORTA EQU 0D480H
PORTB EQU 0D481H
PORTC EQU 0D482H
CWR EQU 0D483H
MSG1 DB "SET THE FIRST 8 BIT NUMBER AND PRESS ENTER",'$'
MSG2 DB "SET THE SECOND 8 BIT NUMBER AND PRESS ENTER",'$'
NEWLINE 13,10,'$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX,DATA ; initialize the data segment
MOV DS,AX
MOV DX, CWR
MOV AL, 82H ; move the control word into CWR
OUT DX,AL
PRINTF MSG1
MOV AH,01H
INT 21H
MOV DX,PORTB
IN AL,DX ; port B used as i/p port for 8-bit input
MOV BL,AL
PRINTF NEWLINE ; wait for sometime
PRINTF MSG2
MOV AH,01H
INT 21H
MOV DX,PORTB ;port B used as i/p port for 2nd 8-bit data
IN AL,DX
MOV AH,01H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, 80H
MOV DX, CWR
OUT DX, AL
DISPLAY PROC
POP CX
RET
DISPLAY ENDP
CODE ENDS
END START
PROGRAM
DATA SEGMENT
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, 80H
MOV DX, CWR
OUT DX, AL
DELAY PROC
PUSH CX
PUSH BX
POP BX
POP CX
RET
DELAY ENDP
a. Generate the Sine Wave using DAC interface (The output of the DAC is to
be displayed on the CRO).
Calculate table values using the formula x[i]=128+127 SinӨ ( Equation to generate sine
wave) Where Ө(Theta ranges from0 to 180 in steps of 5 degree)
DATA SEGMENT
PORTA EQU 0D480H
PORTB EQU 0D481H
PORTC EQU 0D482H
CWR EQU 0D483H
X DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
LEN DW $-X
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA ; initialize data segment
MOV DS, AX
Algorithm: Calculate table values using the formula table[i]=128+127 SinӨ Where Ө ranges
from0 to 180. refer the same table given in program 9b.
DATA SEGMENT
PORTA EQU 0D480H
PORTB EQU 0D481H
PORTC EQU 0D482H
CWR EQU 0D483H
X DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
DB ___,___,___,___,___,___,___,___,___
LEN DW $-X
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA ; initialize data segment
MOV DS, AX
MOV AL, 80H ; 80h is control word
MOV DX, CWR ; control register address
OUT DX, AL ; control word is moved to control register
//************************Private Protoype**************************************
void _DelayMs(unsigned int delay);
//*******************End of Private Protoype************************************
//**************************************************************************
// Function: void main(void)
// Input: None
// Output: None
// Overview: Main program entry point.
// Note: None
//**************************************************************************
int main(void)
{
char silicon[] = "9964500991";
PINSEL0 = 0;
PINSEL1 = 0;
PINSEL2 &= 0x0000000C;
PINSEL2 |= 0x00000030;
ClcdInit();
ClcdCursorOff();
while(1)
}
}
/* delay function */
void _DelayMs(unsigned int count)
{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
AIM:
To develop and verify the interfacing of real time clock and serial port with ARM
DEVELOPMENT KIT:
APPARATUS REQUIRED:
PROCEDURE:
Step 1: Give a double click on μvision 4 icon on the desk top, it will generate a window as shown
below
Step 2: To create new project go to project select new micro vision project.
Step 3: select a drive where you would like to create your project.
Step 4: Create a new folder and name it with your project name.
Step 5: Open that project folder and give a name of your project executable and save it.
Step 6: After saving it will show some window there you select your microcontroller company
i.e NXP from Phillips
Step 7: Select your chip as ARM DEVELOPMENT KIT
Step 8: After selecting chip click on OK then it will display some window asking to add
STARTUP . Select YES.
Step 9: A target is created and startup is added to your project target and is shown below.
Step 10: To write your project code select a new from menu bar.
Step 11: It will display some text editor, to save that select SAVE option from menu bar.
Step 12: By giving a name with extension .c and save it
Step 13: To add our c to target give a right click on Source Group, choose “ADD s to Group”
option.
Step 14:It will displays some window there select the you have to add and click on ADD option.
RTC:
#include <LPC213x.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include "UART.h"
#define BUZZ 7
void UART1_ISR(void)__irq;
void RTC_ISR (void)__irq;
unsigned char Flag=0;
char Key;
void Initialize(void)
{
PLLCFG = 0x24; // M : 4 | P = 2 -> Fosc = 12MHz &
CCLK = 60MHz
PLLFEED = 0xAA; // Feed Process
PLLFEED = 0x55;
PLLCON = 0x01;
PLLFEED = 0xAA; // Feed Process
PLLFEED = 0x55;
while (!(PLLSTAT & 0x400)); //Wait untill PLL is Locked!
PLLCON = 0x03; //Connect PLL as the Clock Source for Microcontroller
PLLFEED = 0xAA; // Feed Process
PLLFEED = 0x55;
void Delay()
{
unsigned int i,j;
for(i=0;i<50;i++)
for(j=0;j<700;j++);
}
void Wait()
{
Delay();Delay();Delay();
Delay();Delay();Delay();
Delay();Delay(); Delay();
}
void Alarm(void)
{
IOSET0 = 1 << BUZZ;
Wait();Wait();
IOCLR0 = 1 << BUZZ;
// //for(i=0;i<250;i++)
// printf("[2M");
//}
void main(void)
{
Initialize();
UART1_Init(9600/*Baud Rate*/);
U1IER = 3;//Enable UART1 Recieve Interrupt
//PINSEL0 |= (1 << 18); //Select Pin as UART1
IO0DIR |= (1<<7); //Configure P0.7 as O/p (Buzzer)
VICVectAddr0 = (unsigned)UART1_ISR;
VICVectCntl0 = 0x20 | 7;
VICIntEnable |= (1 << 7);
VICVectAddr2 = (unsigned)RTC_ISR;
VICVectCntl2 = 0x20 | 13;
VICIntEnable |= (1 << 13);
AMR = 0xFF; //Mask all valued except hh:mm:ss for alarm comparision
PREINT = 0x00000392; // Set RTC Prescaler for PCLK 30 MHz
PREFRAC = 0x00004380;// printf("[2J\0");// Clear Screen
CCR = 0x01;
//CIIR = 0x01;
UART1_PutS("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
UART1_PutS(" ARM LPC2138 RTC Demo\n\r--------------------\n\n\n");
UART1_PutS("> Press * to Set Time\n");
UART1_PutS("> Press ! to Set Alarm\n");
UART1_PutS("> Press $ to Snooze Alarm 5 Minutes\n");
UART1_PutS("> Press . to Stop Alarm\n");
UART1_PutS("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n");
while(1)
{
printf("CTC : %d\t",CTC);
printf(">> TIME: %02d:%02d:%02d \r",HOUR,MIN,SEC); //
Display time format hh:mm:ss
DelayMs(100); // Delay for display
if (Key == '*')
{
Key = 0;
UART1_PutS(">> Set Time: ");
RTC_Setup(&HOUR);
if (Key == '.')
{
Key = 0;
Flag = 0;
}
if (Flag == 1)
{
Alarm (); Wait (); Alarm ();
}
}
void UART1_ISR(void)__irq
{
char Msg;
if(((Msg = U1IIR) & 0x01) == 0)//Check Flag Status of Recieve Interrupt
{
switch(Msg & 0x0E) //Filter Msg
{
case 0x04: while (!(U1LSR & 0x20));
//Recieve Data
Key = U1RBR;
case 0x02: break; // Interrupt
default : break;
}
}
SERIAL PORT:
#define CR 0x0D
#include <LPC21xx.H>
void init_serial (void);
int putchar (int ch);
int getchar (void);
unsigned char test;