0% found this document useful (0 votes)
18 views29 pages

ES LAB Programs

It contains the programs of embedded system

Uploaded by

gowthami jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views29 pages

ES LAB Programs

It contains the programs of embedded system

Uploaded by

gowthami jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Steps for the simulation of 8051 ALP

1. Double Click on the µ


2. Close any previous projects that were opened using – Project->Close.
3. Start Project  New µvision Project and create a new folder Type a file names
Select the CPU from the device database (Database- Atmel- AT89C51ED2).

On clicking ‘OK’, the following option is displayed. Choose No

4. Create a source file (using Filenew), type in the assembly or C program and save this
(filename.asm/ filename.c) and add this source file to the project by right clicking on the
Source Group in the Project Window and Add Files to Groupoption.

5. Set the Target options using Project Options for Target ‘Target 1’configuration
dialog. Set the Xtal frequency as 11.0592 MHz, and also the Options for Target
Debug  use either Simulator / KeilMonitor- 51 driver.

1
If Keil Monitor- 51 driver is used click on Settings COM Port settings select the
COM Port to which the board is connected and select the baud rate as 19200 or 9600
(recommended). Enable Serial Interrupt option if the user application is not using on-
chip UART, to stop program execution.
6. Build the project; using Project  Build Project. Any errors in the code are indicated
by – “Target not created” in the Build window, along with the error line. Debug the
errors. After an error free build, goto Debug mode.

7. Now user can enter into Debug mode with Debug- Start / Stop Debug session dialog.
Or by clicking the icon.
8. Run the program using the Debug-Run command & halted using Debug-Stop
Running. Also the (reset, run, halt) icons can be used. Additional icons are

(step, step over, step into, run till cursor).

9. If it is an interface program the outputs can be seen on the LCD, CRO, motor, led status,
etc. If it is a part-A program, the appropriate memory window is opened using View
memory window (for data RAM & XRAM locations), Watch window (for timer
program), serial window, etc.
Note: To access internal RAM area type address say i:20h.
Similarly to access the DPTR region (XRAM-present on chip in AT89C51ED2) say
9000h location type in X:9000H.
ATMEL chip > Device > Settings > RS232 > 9600 > Connect

For interfacing programs:Ensure the following supporting files are present in the
working directory
 lcd.h , LCD.LIB, REG51F.H, REG51XD2.H

Source group1: For the step 4 above, add all the supporting files and application program
Similar steps are followed as same as simulation programs

2
PART- A
8051 Assembly Language Programs using Keil simulator

Warm-Up cycle:

1. Programs to introduce accessing external memory, internal memory, registers


2. Programs to introduce arithmetic and logic instructions

Example programs:
#1 To add two data bytes in External data memories
ORG 00
mov DPTR,#1000h; initialize Ext MEMORY
movx A, @DPTR; Get the First data
mov R0,A; Copy D1 to R0
inc DPTR; To point to next memory
movx A, @DPTR; Get the Second data
add A,R0; Add nums
inc DPTR; To point to sum mem
movx @DPTR, A; To Store the sum
here: sjmp here

# 2 To increment two data internal data memories

org 00
mov r0,#25h;
inc @r0;
inc r0;
inc @r0;
here: sjmp here
end
# 3 To perform logical AND of data internal data memories

org 00
mov r0,#25h;
mov a, @r0 ;
inc r0;
anl a,@r0;
inc r0;
mov @r0,a
here: sjmp here
end

3
First cycle programs:

1. Program to Block transfer without overlap:

org 00h
sjmp 30h
org 30h
mov dptr,#9000h
mov r0,#10
mov r1,#90h
mov r2,#91h
nxt: movx a,@dptr
mov dph,r2
movx @dptr,a
mov dph,r1
incdptr
djnz r0,nxt
hr: sjmphr
end

2. Program to Block exchange


org 00h
sjmp 30h
org 30h
mov dptr,#9000h
mov r0,#5
mov r1,#90h
mov r2,#91h
rpt: movx a,@dptr
mov r3,a
mov dph,r2
movx a,@dptr
mov dph,r1
movx @dptr,a
mov a,r3
mov dph,r2
movx @dptr,a
mov dph,r1
inc dptr
djnz r0,rpt
hr: sjmp hr
end

3. Program to add ‘N’ bytes


org 00h
sjmp 30h
org 30h
mov dptr,#2000h
mov r2,#5
mov r3,#00

4
mov r4,#00
nxt_bt:movx a,@dptr
add a,r4
mov r4,a
jnc skip
inc r3
skip: inc dptr
djnz r2,nxt_bt
movx @dptr,a
inc dptr
mov a,r3
movx @dptr,a

hr: sjmp hr
end

4. Program to add ‘N’ BCD numbers


org 00h
sjmp 30h

org 30h
mov dptr,#2000h
mov r2,#11
mov r3,#00
mov r4,#00
nxt_bt:movx a,@dptr
add a,r4
da a
mov r4,a
jnc skip
clr a
mov a,r3
add a,#01
da a
mov r3,a
skip: inc dptr
djnz r2,nxt_bt
mov a,r4
movx @dptr,a
inc dptr
mov a,r3
movx @dptr,a
hr: sjmp hr
end

5
5. Program for 16-bit addition

org 00h
sjmp 30h
org 30h
result equ 40h
mov dptr,#0ffabh
mov a, #0cdh
mov b,#0abh
mov r0,#result
add a,dpl
mov @r0,a
inc r0
mova,b
addc a,dph
mov @r0,a
inc r0
mov @r0,#00
jnc hr
inc @r0
hr: sjmphr
end
Second cycle programs:

1. Program to add two multibyte numbers


org 00h
sjmp 30h
org 30h
mov dptr,#9000h
mov r1,#5
mov r2,#90h
mov r3,#91h
mov r4,#92h
clr c
nxt_bt: mov dph,r2
movx a,@dptr
mov r5,a
mov dph,r3
movx a,@dptr
addc a,r5
mov dph,r4
movx @dptr,a
inc dptr
djnz r1,nxt_bt
mov a,r1
jnc skip
inc a
skip: movx @dptr,a
hr: sjmp hr
end

6
2. Program to subtract two multibyte numbers
org 00h
sjmp 30h
org 30h
mov dptr,#9000h
mov r1,#5
mov r2,#90h
mov r3,#91h
mov r4,#92h
clr c
nxt_bt: mov dph,r2
movx a,@dptr
mov r5,a
mov dph,r3
movx a,@dptr
subb a,r5
mov dph,r4
movx @dptr,a
inc dptr
djnz r1,nxt_bt
mov a,r1
jnc skip
inc a
skip: movx @dptr,a
hr: sjmp hr
end

3. Program to arrange ‘N’ binary numbers in ascending order

org 00h
sjmp 30h
org 30h
mov r0,#4
nxt_ps: mov dptr,#2000h
mov a,r0
mov r1,a
nxt_cmp:mov r2,dpl
movx a,@dptr
mov 0f0h,a
inc dptr
movx a,@dptr
cjne a,0f0h,not_eq
ajmp skip
not_eq: jnc skip
mov dpl,r2
movx @dptr,a
inc dptr
mov a,0f0h
movx @dptr,a

7
skip: djnz r1,nxt_cmp
djnz r0,nxt_ps
hr:sjmp hr
end

# Modify the above program to


i) sort in Descending order
ii) reduce the number of unnecessary passes and comparison

4. Program to XOR two bits stored in locations 30h and 31h. Store the result in 32h.
( Modify this program for XNOR operation)
; Flip Flops A = 30h, B = 31h,Y= 32h have byte address 26h
; Y=AB’ + BA’ ( XOR operation)
; Assuming initially output of XOR gate (Y) = 0
Input at 26h Output at 26h

00h 00h

01h 05h

02h 06h

03h 03h

org 00h
sjmp 30h
org 30h
mov c,30h ; Cy=A
anl c,/31h ; Cy=A.B’
mov 32h,c ; Y=A.B’
mov c,31h ; Cy= B
anl c,/30h ; Cy= B.A’
orl c,32h ; Cy=Y+BA’ = AB’ + BA’
mov 32h,c ; Y= Cy = AB’ + BA’
hr: sjmphr
end
5. Program for multiplication of 16 bit number with 8 bit number (eg: ABCD X EF )
(1000h)=EFh, (1001h) =CDh, (1002h)=ABh
;(eg1: ABCDh X EFh ) (1000h)=EFh, (1001h) =CDh, (1002h)=ABh
; ABCDh x EFh = A06463h
; eg2: ABCDh X AAh = 721622h

org 00h
mov dptr,#1000h
movx a,@dptr ; (a) = (1000h) = EFh
mov r0,a ; (r0) = (a) = EFh
inc dptr ;
movx a,@dptr ; (a) = (1001h) = CDh
mov r1,a ; (r1) = (a) = CDh

8
inc dptr
movx a,@dptr ; (a) = (1002h) = ABh
mov r2,a ;(r2) = (a) = ABh
mov b,01 ;(b) = (r1) = CDh
mov a,r0 ;(a) = (r0) = EFh
mul ab ;(b) = Higher byte of product (CDh X EFh)
;(a) = Lower byte of product (CDh X EFh)
mov r3,a ;(r3) = (a) = Lower byte of product (CDh X EFh)
mov r4,0f0h ;(r4) = (b) = Higher byte of product (CDh X EFh)
mov b,02 ; (b) = (r2)= ABh
mov a,r0 ; (a) = (r0) = EFh
mul ab; ; (b) = Higher byte of product (ABh X EFh)
; (a) = Lower byte of product (ABh X EFh)
mov r5,a ; (r5) = (a) = Lower byte of product (ABh X EFh)
mov r6,b ; (r6) = (b) = Higher byte of product (ABh X EFh)
mov a,r3 ; (a) = (r3) = Lower byte of product (CDh X EFh)
inc dptr ;
movx @dptr,a ;(1003h) = (a) = First byte of product (CDh X EFh)
mov a,r4 ;(a) = (r4) = Higher byte of product (CDh X EFh)
add a,r5 ;(a) = Second byte of the product
; = Higher byte of (CDh X EFh) + Lower byte of (ABh X EFh)
inc dptr
movx @dptr,a ; (1004h) = (a) = Second byte of product
clr a
addc a ,r6 ; (a) = Third byte of the product
; = Higher byte of (ABh X EFh)+ possible carry from Second
; byte of product
inc dptr ;
movx @dptr,a ; (1005h)= Third byte of the product
hr: sjmp hr ; ABCD x EF = A06463h
end

9
Third cycle programs
1. Program to generate 10 Fibonacci numbers with first two stored in
locations 1000h and 1001h
; Fibonacci series .... 10 Nos
; If (1000h)=2 and (1001h)= 3 then the Result = 2,3,5,8,0dh,15h,22h,37h,59h,90h

org 00h
sjmp 30h
org 30h
mov dptr,#1000h
mov r3,#08
movx a,@dptr
mov r0,a
incdptr
movx a,@dptr
nxt: xch a,r0
add a,r0
inc dptr
movx @dptr,a
djnz r3,nxt
hr: sjmp hr
end

2. Program to find GCD and LCM of two 8-bit numbers.

; Eg1: N1=6 & N2=8 GCD = 2 and LCM = 24(18h)


; Eg2: N1=14 (0Eh) and N2= 63(3Fh) GCD = 7 and LCM = 126(7Eh)
; (N1 x N2) = (LCM x GCD)
; Logic for GCD
; eg1: 8-6=2; 6-2=4; 4-2=2; 2-2=0;==> GCD=2
; eg2: 63-14=49; 49-14=35; 35-14=21; 21-14=7; 7-7=0 ⇒ GCD=7
;Logic for LCM
; LCM=(N1/GCD) x N2
; eg1: LCM= (6/2) x 8 = 3 x 8=24=18h
; eg2: LCM= (14/7) x 63 = 2 x 63 =126=7Eh
org 00h
sjmp 30h
org 30h
mov dptr,#1000h
movx a,@dptr
mov r0,a ; (r0) = N1= (1000h)
inc dptr
movx a, @dptr ; (a) = N2 = (1001h)
back: cjne a,00h,rpt
sjmp gcd
rpt: jnc skip
xch a,r0
skip: clr c
subb a,r0
sjmp back

10
gcd: incdptr
movx @dptr,a ; (1002h) = GCD
inc dptr
mov 0f0h,a ; (b) = GCD
mov 82h,#00
movx a,@dptr ; (a)=N1
div ab ; (a)/(b) q=(a) and r=(b) => (a) = (N1/GCD) (b)= 0
mov 0f0h,a ; (b)= (a) = (N1/GCD)
inc dptr
movx a,@dptr ; (a) = N2
mul ab ; (a) = (N1/GCD) x N2 =LCM
mov 82h,#03
movx @dptr,a ; (1003h) = LCM
hr:sjmp hr
end

3. Program to search an element in a block of N-bytes. If number is present, show the


position number in 1050h. If not present, show FFh in 1050h; Key element is stored in
1000h. The data block starts from 1001h
org 00h
sjmp 30h
org 30h
result equ 1050h
len equ 6
mov dptr,#1000h
mov r2,#0h ; (r2) = Position Counter
mov r1,#len
movx a,@dptr ; (a) = Key Element
mov r0,a ; (r0)= Key Element=(1000h)
bk: inc dptr
inc r2 ; Update the position counter
movx a,@dptr
cjne a,00h,nxt ; Comparing the data with key element
sjmp found
nxt: djnz r1,bk
mov r2,#0ffh ; KEY NOT FOUND
found: mov dptr,#result
mov a,r2
movx @dptr,a
hr: sjmp hr
end

11
4. Program to find the square and cube of a number.

org 00h
Sjmp 30h
org 30h

mov dptr,#1000h ; Pointer to Number N whose square and cube to be


found
movx a,@dptr
mov b,a
mov r0,a ; (r0) = N
mul ab ; To Compute Square
mov r1,a ; (r1) = Lower Byte of Square
mov r2,b ; (r2) = Higher Byte of Square
inc dptr
movx @dptr,a ; Lower Byte of Square in 1001h
inc dptr
mova,b
movx @dptr,a ; Higher Byte of Square in memory 1002h
; To Find the CUBE of N (16 bit Square X N)
mov a,r0 ; (a)= N
mov b,r1 ; (b)= (r1) = Lower Byte of the Square
mul ab ; Lower Byte of the Square X N
inc dptr
movx @dptr,a ; First Byte of the Cube stored in 1003h
mov r3,b ;
mov a,r0 ; (a)= N
mov b,r2 ; (b) = Higher Byte of Square
mul ab ;
add a,r3
inc dptr
movx @dptr,a ; Second Byte of the Cube stored in 1004h
clr a
addc a,b
inc dptr
movx @dptr,a ; Third Byte of the Cube stored in 1004h
hr:sjmp hr
end
5. Program to find square root of a 8 bit number
org 00h
sjmp 30h
org 30h
mov 30h,#81 ; store the number N into internal DM
mov r0,#01h ; (r0) = 1 Start the counter
back: mov a,r0
mov b,a
mul ab ; Find the Squre of (r0)
cjne a,30h,nxt1 ; Check whether the number N is same as square of (r0)
sjmp end_proc
nxt1: inc r0 ; Increment the counter

12
sjmp back
end_proc: mov 31h,r0 ; Store the Square root in 31h
hr: sjmphr
end

Fourth cycle programs:

Program to demonstrate Binary-up counter (00H to FFH)


{ Modify this program to demonstrate Binary-down counter (FFH to 00H) }

org 00h
sjmp 30h
org 30h
clr a
back: mov p1,a
acall delay
inc a
sjmp back
delay: mov r3,#0ffh
loop3: mov r1,#0ffh
loop2: mov r2,#0ffh
loop1: djnz r2,loop1
djnz r1,loop2
djnz r3,loop3
ret
end

2. Program to demonstrate for BCD down counter (99 to 00)


{ Modify this program to demonstrate BCD-up counter (00 to 99) }
org 00h
Sjmp 30h
org 30h
mov a,#99h
back:mov p1,a
acall delay
add a,#99h
da a
sjmp back
delay: mov r3,#0ffh
loop3 :mov r1,#0ffh
loop2: mov r2,#0ffh
loop1: djnz r2,loop1
djnz r1,loop2
djnz r3,loop3
ret
end

13
3. Program to convert Binary number to ASCII
{ Modify this program to demonstrate ASCII number to Binary }

org 00h
Sjmp 30h
org 30h

mov dptr,#1000H
movx a,@dptr
mov r0,a
anl a,#0fh
acall binary2ascii
mov a,r0
anl a,#0f0h
swap a
acall binary2ascii
hr:sjmp hr
binary2ascii:cjne a,#0ah,ner
ajmp nxt
ner: jc skip
nxt:add a,#07h
skip:add a,#30h
inc dptr
movx @dptr,a
ret
end

4. Program to convert binary number into BCD.

org 00h
sjmp 30h
org 30h
mov dptr,#1000h
movx a,@dptr
mov b,#100
div ab
inc dptr
mov r0,a
mov a,b
mov b,#10
div ab
swap a
orla,b
movx @dptr,a
inc dptr
mov a,r0
movx @dptr,a
hr: sjmphr
end

14
5. Program to generate a square wave of 2 KHz of 30%duty cycle. Use Timer 0 in
Mode 1
org 00h
sjmp 30h
org 30h
mov tmod,#01h
loop:mov th0,#0FFh
mov tl0,#76h
setb p1.5
acall delay
clr p1.5
mov tl0,#0BDh
mov th0,#0FEh
acall delay
sjmp loop
delay: setb tr0
bk:jnb tf0,bk
clr tf0
clr tr0
ret

6. Program to send the message “Serial Communication” to the serial port. Assume
XTAL = 11.0592 MHz, 8-bit data, and 1 stop bit. Baud rate=4800

ORG 0H ;starting position


MAIN:
MOV TMOD,#20H
MOV TH1,#-6 ;4800 baud rate
MOV SCON,#50H
SETB TR1

MOV DPTR,#MESSG ;load address to message


NXT_CHR: CLR A
MOVC A,@A+DPTR ;read value
OVER JZ OVER ;check for end of line
ACALL SENDCOM ;send value to serial port
INC DPTR ;move to next value
SJMP NXT_CHR ;repeat

15
; subroutine for transmitting Character

SENDCOM: MOV SBUF,A ;place value in buffer


HERE: JNB TI,HERE ;wait until transmitted
CLR TI ;clear
RET ;return
MESSG: DB “Serial Communication”,0
END

16
PART- B

C programs to interface 8051 to peripherals using Keil

1 Develop a C program to interface Matrix Key board to 8051

Key Board Interface Circuit diagram

17
Keyboard Interfacing Program
/***************************Keyboard Interface ***********************

Object : To Demonstrate the keyboard interface


Connection : Connect the interface module to 26 pin FRC connector J7 of ESAMCB51.

Output : Displays the pressed key's key code on the on-board LCD of the ESAMCB 51
It uses the LCD library to write on the LCD.

**********************************************************************/
#include <REG51xD2.H>
#include "lcd.h"
unsigned char getkey();
void delay(unsigned int);
main()
{
unsigned char key,tmp;
InitLcd(); /* Initialise LCD */
WriteString("Key Pressed="); /* Display msg on LCD */
while(1)
{
GotoXY(12,0); /*Set Cursor Position */
key = getkey(); /* Call Getkey method */
}
}
unsigned char getkey()
{
unsigned char i,j,k,indx,t;
P2 = 0x00; /* P2 as Output port */
P0 = 0xFF;
indx = 0x00; /* Index for storing the first value of scanline */
for(i=1;i<=4;i<<=1) /* for 4 scanlines */
{
P2 = 0x0f & ~i; /* write data to scanline */
t = P0; /* Read readlines connected to P0*/
t = ~t;
if(t>0) /* If key press is true */
{
delay(6000); /* Delay for bouncing */
for(j=0;j<=7;j++) /* Check for 8 lines */
{

18
t >>=1;
if(t==0) /* if get pressed key*/
{
k = indx+j; /* Display that by converting to Ascii
*/
t = k>>4;
t +=0x30;
WriteChar(t); /* Write upper nibble */
t = k & 0x0f;
if(t > 9)
t+=0x37;
else
t+=0x30;
WriteChar(t); /* write lower nibble */
return(indx+j); /* Return index of the key pressed */
}
}
}
indx += 8; /* If no key pressed increment index
*/
}
}

void delay(unsigned int x) /* Delay routine */


{
for(;x>0;x--);
}

19
2. Develop a C program to generate square and triangular wave using
DAC
Dual DAC Interface Circuit Diagram

20
Dual DAC interfacing program
/*********************************** Squre wave************************
Object : To demonstrate how to generate square wave using ESA Dual DAC interface.
Connection: Connect the interface module to 26pin FRC connector J7 ofESAMCB51.
Output: Generates the square wave with 2.5v amplitude.
user can change the amplitude and freaquency by presseing the following keys.
To change Amplitude press P3.3/INT1 on ESAMCB51.
To change frequency press P3.2/INT0 on ESAMCB51.
**********************************************************************/
#include <REG51xD2.H>
#include "lcd.h"
sbit Amp = P3^3; /* Port line to change amplitude */
sbitFre = P3^2; /* Port line to change frequency */
void delay(unsigned int x) /* delay routine */
{
for(;x>0;x--);
}
main()
{
unsigned char on = 0x7f,off=0x00;
unsignedintfre = 100;
InitLcd(); /* Initialize LCD */
WriteString("Squarewave"); /* Write to LCD */
while(1)
{
if(!Amp) /* if user choice is to change amplitude */
{
while(!Amp); /* wait for key release */
on+=0x08; /* Increase the amplitude */
}
if(!Fre) /* if user choice is to change frequency */
{
if(fre> 1000) /* if frequency exceeds 1000 reset to default */
fre = 100;
while(!Fre); /* wait for key release */
fre += 50; /* Increase the frequency */
}
P0=on; /* write apmlitude to port */
delay(fre);
21
P0 = off; /* clear port */
delay(fre);
}
}

/************************** Triangle wave *************************

Object : To demonstrate how to generate a triangular wave formusing ESA Dual DAC I/F.
Connection: Connect the Interface to 26pin FRC connector J7 ofESAMCB51.
Output : Generates a Triangular waveform with 5v Amp.

*******************************************************************/
#include <REG51xD2.H>
#include "lcd.h"

main()
{
unsigned char i=0;
InitLcd(); /* Initialise LCD */
WriteString("Triangular Wave"); /* Display on LCD */
P0 = 0x00; /* P0 as Output port */
while(1)
{
for(i=0;i<0xff;i++) /* GenerateON pulse */
P0 = i;
for(i=0xfe;i>0x00;i--) /* Generate OFF pulse */
P0 = i;
}
}

Steps to view the waveform using simulator:


Step1: Create project, include all supporting files and application file (C file). Go to Target
options > Use simulator
Step2: View > Logic analyzer window > Setup > Add P0/P1 > Close
Step 3: Run the program

Hardware details:
Vref  10.5 V , R f  2.7 K , R ref  5.1 K
Calculation:
D D D D D D D D 
I out  I ref  7  6  5  4  3  2  1  0 
 2 4 8 16 32 64 128 256 
Vref
I ref 
Rref
Vo  R f I out

22
Exercise:

Write a C program to generate a


 N-Step staircase waveform
 Sinusoidal signal
 Positive and Negative ramp signal with a variable slope

3. Develop a C program to rotate stepper motor in Clockwise and anti-


clockwise using interrupt

Working principle of Stepper motor

23
Stepper Motor Interface Circuit diagram

24
Stepper Motor Interfacing program
/**************************** Stepper Motor **************************

Object : To demonstrate the Stepper motor interface.


Connection : Connect the stepper motor interface to 26 pin FRC connector J7
of ESAMCB51.
Output : whenever you run the program the motor rotates in clockwise.
If you want to change the direction press the interrupt button( P3.2/INTO*).
when youpress the button, INT0 interrupts the main program and changes the
direction of themotor .

**********************************************************************/
#include <REG51xD2.H>
#include "lcd.h"
static bit Dir=0;
voidChangeDir(void) interrupt 0 /* Int Vector at 000BH, Reg Bank 1
*/
{
Dir = ~Dir; /* Complement the Direction flag */
ClrLcd();
if(Dir)
WriteString("Clockwise");
else
WriteString("Anti Clockwise");
}
void delay(unsigned int x) /* Delay Routine */
{
for(;x>0;x--);
}
main()
{
unsigned char Val,i;
EA=0x1; /* Enable Interrupt flag and Interrupt 0 & Serial Interrupt */
EX0=0x1;
ES=0x0; /*since the monitor is using the serial interrupt it has to be enabled*/
InitLcd(); /* Initialise LCD */
WriteString("Anti Clockwise"); /* Write to LCD */
while(1)
{
if(Dir) /* If Dir Clockwise */

25
{
Val = 0x88;
for(i=0;i<4;i++)
{
P0 = Val; /* Write data for clock wise
direction*/
Val = Val>>1;
delay(575);
}
}
else /* AntiClockwise Direction */
{
Val = 0x11;
for(i=0;i<4;i++)
{
P0 = Val; /* Write data for anticlockwise direction*/
Val = Val<<1;
delay(575);
}
}
}
}

26
PART- C
IoT Experiments using Arduino uno
IoT Board with Arduino UNO R3

Steps to connect the IoT board to the system


1. Connect USB port of PC to Arduino USB port and connect power cord

Procedure to run an application on Arduino


1. Click on the Arduino icon on desk top

2. File->New->Write the Arduino program->save

3. Tools->Board->select Arduino/Genuino Uno

4. Tools->port->COM n ( Arduino/Genuino Uno )

5. → (upload)

27
/* 1. Program to test Buzzer */ // RM17 - RM9 connected and RM25-RM26
int buzzer_pin = 9; // Arduino pin #23/D9 or Board pin P38
void setup(){
pinMode(buzzer_pin, OUTPUT);
Serial.begin(9600);
digitalWrite(buzzer_pin,HIGH);
}
void loop() {
digitalWrite(buzzer_pin, LOW);
delay(5000);
digitalWrite(buzzer_pin, HIGH);
delay(2000);
}
/* 2. Digital light sensor : Connect RM3 to RM20 */
int light_pin = 5; //Arduino board pin #19 / D5
void setup() {
pinMode(light_pin, INPUT);
Serial.begin(9600);
}
void loop() {
int light_data = digitalRead(light_pin);
if (light_data)
Serial.println("Light Not Detected!");
else
Serial.println("Light Detected!");

delay(1000);
}

28
Open Ended Experiments:
1. Design a Calculator to perform arithmetic functions.
2. Perform Serial communication to transmit a multimedia file / Image / Audio using
C language.
3. Using ALP, design a temperature controller to meet the design specifications.
4. Generate a given wave pattern using the DAC interface.

29

You might also like