0% found this document useful (0 votes)
46 views

Experiment No.1 Aim:: Perform Addition, Subtraction, Multiplication, Division and Store Result in Memory

The document describes 4 experiments conducted on a microcontroller: 1. Perform basic arithmetic operations like addition, subtraction, etc and store the results in memory locations. 2. Clear RAM and move even valued numbers from one memory location to another. 3. Interface 8 LEDs and show different lighting patterns like all on, all off, alternate on and sequential on. 4. Interface 4 keys and light the corresponding LED for each key press. Show error for simultaneous key presses.

Uploaded by

Sakshi Tyagi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Experiment No.1 Aim:: Perform Addition, Subtraction, Multiplication, Division and Store Result in Memory

The document describes 4 experiments conducted on a microcontroller: 1. Perform basic arithmetic operations like addition, subtraction, etc and store the results in memory locations. 2. Clear RAM and move even valued numbers from one memory location to another. 3. Interface 8 LEDs and show different lighting patterns like all on, all off, alternate on and sequential on. 4. Interface 4 keys and light the corresponding LED for each key press. Show error for simultaneous key presses.

Uploaded by

Sakshi Tyagi
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

EXPERIMENT NO.

1 AIM:
Perform addition, subtraction, multiplication, division and store result in memory.

CODE:
org 0000h op1 equ 0b4h op2 equ 40h mov r0,#50h ;--------------------Addition clr c mov a,#op1 mov b,#op2 add a,b mov @r0,a ;--------------------Subtraction inc r0 clr c mov a,#op1 subb a,b mov @r0,a ;--------------------Multiplication inc r0 mov a,#op1 mul ab mov @r0,a inc r0 mov @r0,b ;--------------------Division inc r0 mov a,#op1 mov b,#op2 div ab mov @r0,a r0 inc r0 mov @r0,b r0 end ;using directives

;load pointer. r0=50h, RAM address

;clear carry flag

;addition (a+b) ;store result in RAM memory location pointed to by r0 ;increment pointer

;subtraction (a-b) ;store result in RAM memory location pointed to by r0 ;increment pointer ;multiplication (a*b) ;store result in RAM memory location pointed to by r0 ;store result in RAM memory location pointed to by r0 ;increment pointer

;division (a/b) ;store result (quotient) in RAM memory location pointed to by ;increment pointer ;store result (remainder) in RAM memory location pointed to by

OUTPUT:

EXPERIMENT NO.2 AIM:


Clear General Purpose RAM, move all even valued numbers stored in a string of 10 bytes to new memory location.

CODE:
org 0000h op1 equ 50h op2 equ 65h clr c mov r0,#op1 mov r1,#op2 mov r2,#10 l1: mov a,@r0 rrc a byte inc r0 jnc l2 djnz r2,l1 sjmp next l2: rlc a mov @r1,a inc r1 djnz r2,l1 next: nop end ;using directives

;clear carry flag ;load pointer. R0=50h, RAM location ;load pointer. R1=65h, RAM location ;loading counter for scanning 10 bytes

;rotating value in regiater a with carry to right to identify even or odd ;increment pointer ;if carry bit is 0 jump to l2 ;loop until counter = 0 ;short jump to next ;rotate left with carry to retain byte in regiater a ;move the byte to new location in RAM ;increment pointer ;loop until counter = 0

OUTPUT:

EXPERIMENT NO.3 AIM:


Interface 8 LEDs in common anode configuration then show following pattern:All ON, All OFF, Alternate ON, Sequential ON.

CODE:
org 0000h ;--------------------All ON and All OFF m: mov r0,#04 ;load counter m1: mov P0,#00h ;all on call delay ;delay called to retain output for visible amount of time mov P0,#0ffh ;all off call delay ;delay called to retain output for visible amount of time djnz r0,m1 ;loop until counter = 0 ;--------------------Alternate ON mov r0,#04 ;load counter m2: mov a,#0aah ;alternate on and off mov P0,a call delay ;delay called to retain output for visible amount of time mov a,#55h ;alternate on and off mov P0,a call delay ;delay called to retain output for visible amount of time djnz r0,m2 ;loop until counter = 0 ;--------------------Sequential ON mov r0,#04 ;load counter m3: mov r1,#08 ;load counter mov dptr,#mydata ;load ROM pointer m4: clr a movc a,@a+dptr ;move data from code space mov P0,a call delay ;delay called to retain output for visible amount of time inc dptr djnz r1,m4 ;loop until counter = 0 djnz r0,m3 ;loop until counter = 0 sjmp m ;--------------------delay function defination delay: mov 31h,#0ffh l1: mov 31h,#99h djnz 30h,$ djnz 31h,$ ret ;--------------------On-chip code space used for store data mydata: db 0feh,0fdh,0fbh,0f7h,0efh,0dfh,0bfh,7fh end

OUTPUT:

EXPERIMENT NO.4 AIM:


Interface 4 keys with microcontroller and switch ON corresponding LED. For simultaneous key press, show error conditions.

CODE:
org 0000h main: mov P1,#0ffh mov a,P1 mov r0,#00h mov r1,#04h clr c check: rrc a jnc next inc r0 next: djnz r1,check rrc a cjne r0,#01h,error swap a mov P2,a sjmp main ;-------------------ERROR error: mov P2,#00h sjmp main end ;configure P1 as input port ;take key input ;set error check counter ;initialize counter

;rotate right with carry ;jump if carry = 0 ;increment if a key is pressed

;check for multiple key press ;light the LED corresponding to key pressed ;repeat

;no LED on if multiple key press detected ;repeat

OUTPUT:

You might also like