You are on page 1of 21

Microprocessors And Microcontrollers Lab Manual 15CSL48

SOFTWARE PROGRAMS: PART A

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.
.model small
.data
array dw 1122h, 2345h, 3344h, 4455h
len dw ($-array)/2
key equ 4455h
msg1 db ‘element found in’
result db ‘position’, 13, 10, ‘$’
msg2 db ‘element not found’
db 13, 10, ‘$’
.code
mov ax, @data
mov ds, ax
mov bx, 01
mov dx, len
mov cx, key
again: cmp bx, dx
ja failure
mov ax, bx
add ax, dx
shr ax, 01
mov si, ax
dec si
add si, si
cmp cx, array[si]
jae bigger
dec ax
mov dx, ax
jmp again
bigger:je success
inc ax
mov bx,ax
jmp again
success: add al, 00
add al,’0’
mov result, al
lea dx, msg1
jmp display
failure: lea dx, msg2
display: move ah, 09h

44
Microprocessors And Microcontrollers Lab Manual 15CSL48

int 21h
mov ah, 4ch
int 21h
end

RESULT: The 8086 ALP has been successfully executed and the output has been
verified.

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.

.model small
.data
a db 34h, 78h, 56h, 47h
len dw ($ - a)
.code
mov ax, @data
mov ds, ax
mov bx, len
dec bx
outer: mov cx, bx
mov si, 0
inner: mov al, a[si]
inc si
cmp al, a[si]
ja zzz
xchg al, a[si]
mov a[si-1], al
zzz: loop inner
dec bx
jnz outer
mov ah, 4ch
int 21h
end

RESULT
The 8086 ALP has been successfully executed and the output was verified.

45
Microprocessors And Microcontrollers Lab Manual 15CSL48

3. Develop an assembly language program to reverse a given string and verify whether
it is a palindrome or not. Display the appropriate message.
.model small
printf macro msg
mov ah,09h
mov dx, offset msg
int 21h
endm
exit macro
mov ah, 4ch
int 21h
endm
.data
str1 db ”madam”
n dw $-str1
str2 db 10 dup(?)
msg1 db “String is palindrome”, 0ah, 0dh, 24h
msg2 db “String is not palindrome”, 0ah, 0dh, 24h
.code
mov ax,@data
mov ds, ax
mov si, 0
mov di, 0
mov cx,n
add si, cx
dec si
L1: mov al, str1[si]
mov str2[di],al
dec si
inc di
loop L1
mov si,0
mov cx,n
L2: mov al, str1[si]
cmp al, str2[si]
je L3
printf msg2
exit

46
Microprocessors And Microcontrollers Lab Manual 15CSL48

L3: inc si
loop L2
printf msg1
exit
end

RESULT: The 8086 ALP has been successfully executed & the output is verified.

4. Develop an assembly language program to compute nCr using recursive procedure.


Assume ‘n’ and ‘r’ are non-negative integers.
.model small
.data
n dw 06h
r dw 03h
val dw 0h
.code
mov ax, @data
mov ds, ax
mov bx, r
mov cx, n
mov ax,00h
call nCr
mov val, ax
mov ah, 4ch
int 21h
nCr proc near
cmp bx, 00h
je ret1
cmp cx, bx
je ret1
cmp bx, 01h
je ret2
mov dx,bx
dec dx
cmp dx, bx
je ret2
dec cx
push cx
push bx
call nCr
pop bx
pop cx
dec bx
call nCr

47
Microprocessors And Microcontrollers Lab Manual 15CSL48

ret
ret1: add ax, 01h
ret
ret2: add ax, cx
ret
nCr endp
end

RESULT: The 8086ALP has been successfully executed and the output has been verified.

5.Design and develop an assembly language program to read the current time and date
from the system and display it in the standard format on the screen.
.model small
.data
nextline db 10,13,"$"
hypen db "-$"
day db ?
month db ?

.code
mov ax,@data
mov ds,ax
mov ah,2ch
int 21h

mov al,ch
AAM
mov bx,ax
call disp
mov dl,':'
mov ah,02h
int 21h

mov al,cl
AAM
mov bx,ax
call disp

mov ah,09h
lea dx,nextline
int 21h
MOV ah,2AH
int 21h

48
Microprocessors And Microcontrollers Lab Manual 15CSL48

mov day,dl
mov month,dh

mov al,day
AAM
mov bx,ax
call disp
lea dx,hypen
mov ah,09h
int 21h
mov al,month
AAM
mov bx,ax
call disp
lea dx,hypen
mov ah,09h
int 21h
mov ax,cx
mov bx,1000
call convert
mov ax,dx
mov bx,100
call convert
mov ax,dx
mov bx,10
call convert
add dl,30h
mov ah,02h
int 21h
mov ah,4ch
int 21h
convert proc
mov dx,0
div bx
push dx
mov dl,al
add dl,30h
mov ah,02h
int 21h
pop dx
ret
convert endp

49
Microprocessors And Microcontrollers Lab Manual 15CSL48

disp proc near


mov dl,ah
add dl,30h
mov ah,02h
int 21h
mov dl,bl
add dl,30h
mov ah,02h
int 21h
ret
disp endp
end

6.To write and simulate ARM assembly language programs for data transfer,logical
operations(Demonstrate with the help of a suitablle program).
a)Data Transfer:
AREA DATATRANSFER,CODE,READONLY
ENTRY
LDR R0,=0X40000000
LDR R1,=0X40000080
LDR R2,=0X0000000A
UP LDRB R3,[R0]
STRB R3,[R1]
ADD R0,R0,#1
ADD R1,R1,#1
ADD R2,R2,#-1
CMP R2,#0
BEQ NEXT
B UP
NEXT MOV R0,#0X18
LDR R1,=0X20026
SVC #0X123456
END

b)Arithmetic and Logical Operation:


AREA ADD,CODE,READONLY
LDR R0,=0X00000005
LDR R1,=0X0000003
MUL R2,R0,R1
EOR R2,R1
NOP
NOP
END
50
Microprocessors And Microcontrollers Lab Manual 15CSL48

7.To write and simulate C programs for ARM microprocessor using KEIL
(Demonstrate with the help of suitable program)

#include<LPC214x.H>
void main(void)
{
int a,b,c:
a=4;
b=3;
c=a+b;
a=5;
}

HARDWARE PROGRAMS:PART B

8.a.Design and develop an assembly program to demonstrate BCD Up-Down


Counter(00-99) on the Logical Controller Interface.
.model small
.stack 64
.data
msg2 db 13,10,”press any key to see BCD-up counter$”
.code
mov ax,@data
mov ds,ax
mov dx,10c3h
mov al,82h
out dx,al
lea dx,msg2
mov ah,09h
int 21h
mov ah,01h
int 21h
mov al,0
mov cx,100
mov dx,10c0h
L2:out dx,al
call delay
inc al
loop L2
51
Microprocessors And Microcontrollers Lab Manual 15CSL48

mov cx,100
L3:dec al
out dx,al
call delay
loop L3
mov ah,4ch
int 21h
delay proc near
push ax
push cx
push dx
mov cx,8000h
L5:mov ax,0ffffh
L4:dec ax
jnz L4
loop L5
pop dx
pop cx
pop ax
ret
delay endp
end

8.b.Design and develop an assembly program to read the status of two 8-bit inputs(X &
Y) from the Logic Controller Interface.
.model small
.data
msg1 db 13,10,’input X from the logic controller and enter the key$’
msg2 db 13,10,’input Y from the logic controller and enter the key$’
.code
mov ax,@data
mov ds,ax
mov al,82h
mov dx,10c3h
out dx,al
lea dx,msg1
mov ah,09h
int 21h
mov ah,01h
int 21h
mov dx,10c1h
in al,dx
mov bl,al
lea dx,msg2

52
Microprocessors And Microcontrollers Lab Manual 15CSL48

mov ah,09h
int 21h
mov ah,01h
int 21h
mov dx,10c1h
in al,dx
mul bl
mov dx,10c0h
out dx,al
mov ah,4ch
int 21h
end

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 (Examiner
does not specify these delay values nor is it necessaryfor the student to compute these
values).

.model small
.data
msg1 db 086h,88h,0f9h,08eh
msg2 db 08ch,0c7h,086h,089h
.code
mov ax,@data
mov ds,ax
mov dx,10c3h
mov al,80h
out dx,al
mov cx,5
again:mov si,offset msg1
push cx
call disp
call delay
mov si,offset msg2
call disp
call delay
pop cx
loop again
mov ah,4ch
int 21h
disp proc near
mov cx,04
L1:mov bl,08

53
Microprocessors And Microcontrollers Lab Manual 15CSL48

mov al,[si]
L2:rol al,01
mov dx,10c1h
out dx,al
push ax
mov al,0ffh
mov dx,10c2h
out dx,al
mov al,00h
out dx,al
dec b1
pop ax
jz L3
jmp L2
L3:inc si
loop L1
ret
disp endp
delay proc near
push ax
push cx
push dx
mov cx,8000h
L5:mov ah,0ffffh
L4:dec ax
jnz L4
loop L5
pop dx
pop cx
pop ax
ret
delay endp
end

10.A stepper 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
assumed by the student).

.model small
.data
.stack 100h

54
Microprocessors And Microcontrollers Lab Manual 15CSL48

n dw 200
.code
mov ax,@data
mov ds,ax
mov dx,010c3h
mov al,80h
out dx,al
mov dx,010c0h
mov al,88h
mov cx,n
L1:out dx,al
push cx
call delay
ror al,01
pop cx
loop L1
mov dx,10c0h
mov al,88h
mov cx,n
L2:out dx,al
push cx
call delay
rol al,01
pop cx
loop L2
mov ah,4ch
int 21h
delay proc near
push ax
push dx
mov cx,1000h
L3:mov ax,0ffffh
L4:dec ax
jnz L4
loop L3
pop dx
pop ax
ret
delay endp
end

55
Microprocessors And Microcontrollers Lab Manual 15CSL48

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 CRO)
outpa macro
mov dx,pa
out dx,al
endm
outpb macro
mov dx,pb
out dx,al
endm
.model small
.stack 200
.data
pa=010c0h
pb=010c1h
pc=010c2h
ctrl=010c3h
table db 0,2,8,17,30,46,64,84,105,127,150,171,191,209,225,238,247, 253,255
msg db ‘press any key to continue $’
.code
mov ax,@data
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
mov dx,ctrl
mov al,80h
out dx,al
start:mov cx,18
lea si,table
back:mov al,[si]
outpa
outpb
inc si
loop back
mov cx,18
bak:mov al,[si]
outpa
outpb
dec si
loop bak
mov ah,01h
int 16h

56
Microprocessors And Microcontrollers Lab Manual 15CSL48

jz start
mov ah,4ch
int 21h
end

11.b. Generate a Half Rectified Sine wave form using the DAC interface.(The output of
the DAC is to be displayed on the CRO)
.model small
.stack 200
.data
pa equ 10c0h
pb equ 10c1h
pc equ 10c2h
ctrl equ 10c3h
msg db 10,13,” Press any key to exit ”,10,13,”$”
table db 80h,96h,0abh,0c0h,0d2h,0e2h,0eeh,0f8h,0feh,0ffh,0feh,0ffh,
0feb,0f8h,0eeh,0e2h,0d2h,0c0h,0c0h,0abh,096h
.code
mov ax,@data
mov ds,ax
lea dx,msg
mov ah,09h
int 21h
mov dx,ctrl
mov al,80h
out dx,al
start:mov cx,18
lea si,table
bg:mov al,[si]
mov dx,pa
out dx,al
mov dx,pb
out dx,al
inc si
loop bg
mov cx,18
mov al,80h
back:mov dx,pa
out dx,al
mov dx,pb
out dx,al
loop back
mov ah,01h
int 16h
57
Microprocessors And Microcontrollers Lab Manual 15CSL48

jz start
mov ah,4ch
int 21h
end
12) Experiment No: 12
To interface LCD with ARM processor-- ARM7TDMI/LPC2148. -Write and execute
programs in C language for displaying text messages and numbers on LCD
Connections:
LCD module - FRC2

Program:
#include <LPC214x.H> // Header file for LPC2148
#include <STRING.H> // Header file for string manipulations
#define LCD_DATA_PORT(DATA) (DATA << 16) // Pin from P1.16 to P1.23 configured
as LCD data port.
#define LCD_CMD_PORT(CMD) (CMD << 8) // Pin from P0.9 to P0.11 configured as LCD
control signals.
#define LEFT 0x18 // Command for left shift.
#define RIGHT 0x1C // Command for right shift.
#define STABLE 0x06 // Command for stable.
unsigned int ENABLE = 0x08; // Pin P0.11 configured as LCD enable signals. (high to low)
unsigned int RD_WR = 0x04; // Pin P0.10 configured as LCD read/write signals. (1-read, 0-
write)
unsigned int RE_SE = 0x02; // Pin P0.9 configured as LCD register selection signals.(1-data,
0-command)
void DELAY_1M(unsigned int VALUE) // 1ms delay
{
unsigned int i,j;
for(i=0;i<VALUE;i++)
{
for(j=1;j<1200;j++);
}
}
void DELAY_1S(unsigned int n) // 1s delay
{
unsigned int i,j;
for(i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}
void LCD_ENABLE() // Signal for LCD enable (high to low with 50ms)
{
IO0SET = LCD_CMD_PORT(ENABLE); // enable is set to 1
DELAY_1M(50); // 50ms delay
IO0CLR = LCD_CMD_PORT(ENABLE); // enable is cleared to 0
}
void LCD_DATA(unsigned int LDATA) // function to display the message
{
IO1PIN = LCD_DATA_PORT(LDATA); // moving the message to LCD data port
IO0CLR = LCD_CMD_PORT(RD_WR); // LCD to write mode (RD_WR = 0)

58
Microprocessors And Microcontrollers Lab Manual 15CSL48

IO0SET = LCD_CMD_PORT(RE_SE); // LCD to data mode (RE_SE = 1)


LCD_ENABLE(); // Latching the data to display from buffer
}
void LCD_CMD(unsigned int LCMD) // function to configure the LCD
{
IO1PIN = LCD_DATA_PORT(LCMD); // moving the command to LCD data port
IO0CLR = LCD_CMD_PORT(RD_WR); // LCD into write mode (RD_WR = 0)
IO0CLR = LCD_CMD_PORT(RE_SE); // LCD into command mode (RE_SE = 0)
LCD_ENABLE(); // Latching the data to display from buffer
}
void LCD_INIT() // initializing the LCD with basic commands
{
LCD_CMD(0x38); // 8 Bit Mode, 2 Rows, 5x7 Font Style
LCD_CMD(0x0C); // Display Switch Command : Display on, Cursor on, Blink off
LCD_CMD(0x06); // Input Set : Increment Mode
LCD_CMD(0x01); // Screen Clear Command , Cursor at Home
}
void DISPLAY_MESSAGE(unsigned char ADDRESS,char *MSG) // Function to display a
complete message
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void SHIFT_MESSAGE(unsigned int SHIFT, unsigned int TIME) // Function for shift
operations with time/speed
{
while(1)
{
LCD_CMD(SHIFT);
DELAY_1S(TIME);
}
}
int main() // Main function
{
IO0DIR =0x00000E00; // Pin from P0.9 to P0.11 configured as output pins.
IO1DIR =0X00FF0000; // Pin from P1.16 to P1.23 configured as output pins.
LCD_INIT(); // LCD initialize
DISPLAY_MESSAGE (0x80, " CHIPMAX DESIGN "); // Address of first row and message
DISPLAY_MESSAGE (0xC0, "0123456789ABCDEF"); // Address of second row and
message
SHIFT_MESSAGE (LEFT,500); // Shift operations- Left, Right and no shift with speed
}
Note: Message can be change by using the function called DISPLAY_MESSAGE() with
address and message to be displayed.

59
Microprocessors And Microcontrollers Lab Manual 15CSL48

13) Experiment No: 13--To interface Stepper motor with ARM processor--
ARM7TDMI/LPC2148. Write a program to rotate stepper motor

Connections:
Stepper Motor module - FRC1

Program:
#include <LPC214x.H> // Header file for LPC2148
#define MOTOR_PORT(DATA) (DATA << 16)// Pin from P0.16 to P1.19 configured as
motor port.
unsigned char COUNT=0;
unsigned int j=0;
unsigned int CLOCK[4] = {0x03,0x09,0x0C,0x06}; // data for clockwise rotation
unsigned int ANTI_CLOCK[4] = {0x06,0x0C,0x09,0x03}; // data for anti-clockwise rotation
void DELAY_1S(unsigned int n) // 1s delay
{
unsigned int i,j;
for(i=1; i<=n; i++)
for(j=0; j<=10000; j++);
}
void CLOCK_WISE_DIRECTION(unsigned int STEP, unsigned int TIME) //Function for
clockwise direction
{
for(j=0;j<=STEP;j++)
{
IO0PIN = MOTOR_PORT(CLOCK[COUNT]);
COUNT ++;
DELAY_1S(TIME);
if(COUNT==4) COUNT=0;
}
}
void ANTI_CLOCK_WISE_DIRECTION(unsigned int STEP, unsigned int TIME)
//Function for anti-clockwise direction
{
for(j=0;j<=STEP;j++)
{
IO0PIN = MOTOR_PORT(ANTI_CLOCK[COUNT]);
COUNT ++;
DELAY_1S(TIME);
if(COUNT==4) COUNT=0;
}
}
int main() // Main function
{
IO0DIR = 0x000F0000;// Pin from P0.16 to P1.19 configured as output pins.
while(1) // infinite loop

60
Microprocessors And Microcontrollers Lab Manual 15CSL48

{
CLOCK_WISE_DIRECTION (10,500);// clockwise direction with step and speed
ANTI_CLOCK_WISE_DIRECTION(10,500);// anti-clockwise direction with step and speed
}
}
Note: no of Steps and speed can be change by varying the parameters in
CLOCK_WISE_DIRECTION and
ANTI_CLOCK_WISE_DIRECTION functions

Study Programs:
1) Experiment No: 1
Interfacing of temperature sensor with ARM LPC2148 and display temperature on
LCD

Connections:
LCD Module - FRC2
ADC Module - FRC5
Program:
#include <LPC214x.H> // Header file for LPC2148
#include <STRING.H> // Header file for string manipulations
#define LCD_DATA_PORT(DATA) (DATA << 16) // Pin from P1.16 to P1.23 configured
as LCD data port.
#define LCD_CMD_PORT(CMD) (CMD << 8) // Pin from P0.9 to P0.11 configured as LCD
control signals.
unsigned int ENABLE = 0x08; // Pin P0.11 configured as LCD enable signals. (high to low)
unsigned int RD_WR = 0x04; // Pin P0.10 configured as LCD read/write signals. (1-read, 0-
write)
unsigned int RE_SE = 0x02; // Pin P0.9 configured as LCD register seletion signals.(1-data,
0-command)
unsigned int TEMP=0,ADC=0;
void DELAY_1M(unsigned int VALUE) // 1ms delay
{
unsigned int i,j;
for(i=0;i<VALUE;i++)
{
for(j=1;j<1200;j++);
}
}
void LCD_ENABLE() // Singal for LCD enable (high to low with 50ms)
{
IO0SET = LCD_CMD_PORT(ENABLE); // enable is set to 1
DELAY_1M(50); // 50ms delay
IO0CLR = LCD_CMD_PORT(ENABLE); // enable is cleared to 0
}
void LCD_DATA(unsigned char LDATA)
{
IO1SET = LCD_DATA_PORT(LDATA); // moving the message to LCD data port
IO1CLR = ~(LCD_DATA_PORT(LDATA)); // moving the message to LCD data port
IO0CLR = LCD_CMD_PORT(RD_WR); // LCD to write mode (RD_WR = 0)
IO0SET = LCD_CMD_PORT(RE_SE); // LCD to data mode (RE_SE = 1)

61
Microprocessors And Microcontrollers Lab Manual 15CSL48

LCD_ENABLE(); // Latching the data to display from buffer


}
void LCD_CMD(unsigned int LCMD)
{
IO1SET = LCD_DATA_PORT(LCMD); // moving the command to LCD data port
IO1CLR = ~(LCD_DATA_PORT(LCMD)); // moving the command to LCD data port
IO0CLR = LCD_CMD_PORT(RD_WR); // LCD into write mode (RD_WR = 0)
IO0CLR = LCD_CMD_PORT(RE_SE); // LCD into command mode (RE_SE = 0)
LCD_ENABLE(); // Latching the data to display from buffer
}
void LCD_INIT() // initializing the LCD with basic commands
{
LCD_CMD(0x38); // 8 Bit Mode, 2 Rows, 5x7 Font Style
LCD_CMD(0x0C); // Display Switch Command : Display on, Cursor on, Blink off
LCD_CMD(0x06); // Input Set : Increment Mode
LCD_CMD(0x01); // Screen Clear Command , Cursor at Home
}
void DISPLAY_MESSAGE(unsigned char ADDRESS,char *MSG) // Function to display a
complete message
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void DISPLAY_TEMPERATURE(unsigned int TEMPERATURE) // Function to display
temperature values
{
LCD_CMD(0xCA);
LCD_DATA((TEMPERATURE % 10000/1000) | 0x30);
LCD_DATA((TEMPERATURE % 1000/100) | 0x30);
LCD_DATA((TEMPERATURE % 100/10) | 0x30);
LCD_DATA('.');
LCD_DATA((TEMPERATURE % 10/1) | 0x30);
return;
}
void INIT_ADC() // initializing ADC
{
PINSEL1 |= 0x01000000; // selecting P0.28/AD0.1 as an ADC pin
AD0CR = 0x00200602;
}
int READ_ADC() // Reading ADC values from pin
{
int VAL;
AD0CR |= 0x01000000;
do

62
Microprocessors And Microcontrollers Lab Manual 15CSL48

{
VAL = AD0DR1;
}
while (!(VAL & 0x80000000));
AD0CR &= ~0x01000000;
VAL >>=6;
VAL = VAL & 0x3FF;
return(VAL);
}
int TEMPERATURE_VALUE() // Converting the adc value to Temperature
{
unsigned int CNT,TEMPERATURE=0;
unsigned long int TEMP_SUM=0,TEMP_AVG=0;
for(CNT=0;CNT<5000;CNT++)
{
TEMPERATURE = READ_ADC();
TEMP_SUM = TEMP_SUM + TEMPERATURE;
}
TEMP_AVG = (TEMP_SUM/5000);
TEMPERATURE = TEMP_AVG;
TEMP_SUM = TEMP_AVG = 0;
TEMPERATURE = (1000*(TEMPERATURE*(3.901/1024)))-100;
return TEMPERATURE;
}
int main() // Main Function
{
IO0DIR =0x00000E00; // Pin from P0.9 to P0.11 configured as output pins.
IO1DIR =0X00FF0000; // Pin from P1.16 to P1.23 configured as output pins.
LCD_INIT(); // LCD initialize
INIT_ADC(); // ADC initialize
DISPLAY_MESSAGE(0x80," TEMPERATURE "); // first row message
DISPLAY_MESSAGE(0xC0,"DEGREE C = "); // second row message
while(1)
{
DISPLAY_TEMPERATURE (TEMPERATURE_VALUE()); // reading and updating the
temperature value in infinite loop
}
}

2) Experiment No: 2--To design ARM based power saving system

Connections:
LDR/RELAY - FRC1
Program:
#include <LPC214x.H> // Header file for LPC2148
unsigned int LDR = 0x00010000;// Pin P0.16 configured as LDR input signal
unsigned int LED = 0x00040000; // Pin P0.18 configured as LED ouput signal
void DELAY_1S(unsigned int n) // 1s delay
{
unsigned int i,j;

63
Microprocessors And Microcontrollers Lab Manual 15CSL48

for(i=1; i<=n; i++)


for(j=0; j<=10000; j++);
}
void POWER_SAVING_SYSTEM(unsigned int TIME) // function for power saving system
{
unsigned int TEMP=0;
TEMP = IO0PIN;
TEMP = TEMP<<2;
IOSET0 = TEMP;
IOCLR0 = ~TEMP;
DELAY_1S(TIME);
}
int main() // Main Function
{
IO0DIR =0x00040000;// Pin P0.16 is input and P0.18 is an output pin
while(1)
{
POWER_SAVING_SYSTEM(100); // Power saving system with time adjustment
}

64

You might also like