Notes
Notes - notes.io |
acall CONFIGURE_LCD
MOV DPTR,#200H
KEYBOARD_LOOP:
ACALL GET_INPUT ;Get input from user and put into specific RAM location
;ACALL CONTROL ;Using the operator, determine which operation will be applied
sjmp KEYBOARD_LOOP
GET_INPUT:
ACALL KEYBOARD
PUSH ACC ;Save the first input, we will clear screen now
ACALL SET_SCREEN ;Prepare screen
POP ACC ;Get all input, print and save into specific registers
ACALL SEND_DATA
ANL A, #0FH
MOV 40H, A
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 41H, A
ACALL KEYBOARD
MOV R7, A ;This controls which arithmetic operation will be done
MOV A, R7 ;Uses arithmetic operator as input
CJNE A, #'+', ERR_MSG
ACALL FIRSTNUMBERADD ;Summing procedure + Print
FIRSTNUMBERADD: MOV A, 40H ;FIRST NUMBER 2 DIGIT STORED
MOV B, #10
MUL AB
ADD A,41H
MOVX @DPTR, A
INC DPTR
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 42H, A
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 43H, A
ACALL KEYBOARD
MOV R7, A ;This controls which arithmetic operation will be done
MOV A, R7 ;Uses arithmetic operator as input
CJNE A, #'+', ERR_MSG
ACALL SECONDNUMBERADD
SECONDNUMBERADD: MOV A, 42H ;SECOND NUMBER 2 DIGIT STORED
MOV B, #10
MUL AB
ADD A,43H
MOVX @DPTR, A
INC DPTR
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 34H, A
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 35H, A
ACALL KEYBOARD
MOV R7, A ;This controls which arithmetic operation will be done
MOV A, R7 ;Uses arithmetic operator as input
CJNE A, #'+', ERR_MSG
ACALL THIRDNUMBERADD
THIRDNUMBERADD: MOV A, 34H ;THIRD NUMBER 2 DIGIT STORED
MOV B, #10
MUL AB
ADD A,35H
MOVX @DPTR, A
INC DPTR
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 36H, A
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 37H, A
ACALL KEYBOARD
MOV R7, A ;This controls which arithmetic operation will be done
MOV A, R7 ;Uses arithmetic operator as input
CJNE A, #'+', ERR_MSG
ACALL FOURTHNUMBERADD
ERR_MSG:
MOV A, R7
ACALL SEND_DATA
RET
FOURTHNUMBERADD:MOV A, 36H ;FOURTH NUMBER 2 DIGIT STORED
MOV B, #10
MUL AB
ADD A,37H
MOVX @DPTR, A
INC DPTR
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 38H, A
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 39H, A
ACALL KEYBOARD
MOV R7, A ;This controls which arithmetic operation will be done
MOV A, R7 ;Uses arithmetic operator as input
CJNE A, #'+', ERR_MSG
ACALL FIFTHNUMBERADD
FIFTHNUMBERADD:MOV A, 38H ;FIFTH NUMBER 2 DIGIT STORED
MOV B, #10
MUL AB
ADD A,39H
MOVX @DPTR, A
INC DPTR
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 3AH, A
ACALL KEYBOARD
;ACALL SEND_DATA
ANL A, #0FH
MOV 3BH, A
ACALL KEYBOARD
MOV R7, A ;This controls which arithmetic operation will be done
MOV A, R7 ;Uses arithmetic operator as input
CJNE A, #'+', ERR_MSG
ACALL SIXTHNUMBERADD
SIXTHNUMBERADD:MOV A, 3AH ;SIXTH NUMBER 2 DIGIT STORED
MOV B, #10
MUL AB
ADD A,3BH
MOVX @DPTR, A
; ACALL KEYBOARD
; ;ACALL SEND_DATA
; ANL A, #0FH
; MOV 3CH, A
; ACALL KEYBOARD
; ;ACALL SEND_DATA
; ANL A, #0FH
; MOV 3DH, A
;
;
; MOV A, 3CH ;SEVETNH NUMBER 2 DIGIT STORED
; MOV B, #10
; MUL AB
; ADD A,3DH
; MOV R7, A
mov a, #0C0H ;After all input is done, move to next line
acall SEND_COMMAND
RET
SET_SCREEN:
mov a, #01H ;Clear Screen
acall SEND_COMMAND
mov a, #80H ;Move to first line
acall SEND_COMMAND
RET
; ERR_MSG: RET
;----------------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------------
;Program to sort an array of number using the Bubble Sort algorithm in ascending order.
;----------------------------------------------------------------------------------------------------
;Input Location: 9000h
;Output Location: 9000h itself
;Number of elementS: 010h
;In the bubble sort algorithm, adjacent elements are compared and sorted with respect to each other.
;This process is done repeatedly starting from the first element everytime till the array is sorted.
;Here's an example. The numbers in the array currently being compared are enclosed in quotes:
;Given array: (5,1,8,2)
;First Pass:
; ("5,3",8,2) -> ("3,5",8,2) -Swap 5 and 3 since 5 is greater.
; (3,"5,8",2) -> (3,"5,8",2) -5 and 8 are in order so don't swap them. Move on.
; (3,5,"8,2") -> (3,5,"2,8") -8 is greater - swap it's position with 2.
;Second Pass:
; ("3,5",2,8) -> ("3,5",2,8) -3 and 5 are in order. Do nothing and move on.
; (3,"5,2",8) -> (3,"2,5",8) -5 is greater swap 2's and 5's positions.
;Third Pass:
; ("2,3",5,8) -> ("2,3",5,8) -3 is greater so swap.
;This sorts the array as (2,3,5,8) which is in ascending order. Notice that the number of passes is
;one less than the number of elements in the array and number of iterations in each pass is the
;total number of elements minus the current pass number.
;----------------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------------
MOV DPTR,#200H
MOV 06H, #06h
;-----------------------------------Data Required for the Program------------------------------------
MOV R0, #05h ;Counter for LOOP1
;----------------------------Sort in Ascending Order Using Bubble Sort-------------------------------
LOOP1: ;Outer Loop - Handles number of passes
;MOV DPTR, #300h ;Point to beginning of array
MOV A, R0 ;Initialize R1 - the counter for LOOP2
MOV R1, A ;to the value of R0 - the number of iterations in each pass is same
;as the number of elements minus serial number of the current pass.
LOOP2: ;Inner Loop - Handles each pass.
MOVC A, @A+DPTR ;Copy a number of the array to the accumulator
MOV R2, A ;and store it in R2.
INC DPTR ;Move to the net number
MOVC A, @A+DPTR ;and store that in the accumulator.
SUBB A, R2 ;Subtract the first from the second.
JNC Continue2 ;If no carry is generated the second is greater and the numbers are
;in order with respect to each other. Otherwise they must be swapped.
SwapNumbers:
MOVC A, @A+DPTR ;Move the second number to the accumulator.
XCH A, R2 ;Exchange contents of the accumulator and R2. This makes A contain
;the first number and R2 the second.
MOVX @DPTR, A ;Store the first number at the place where the second one was stored.
DEC DPL ;Move to the previous memory location.
MOV A, R2 ;Copy the second number to the accumulator
MOVX @DPTR, A ;and store it in the first number's place.
Continue2: DJNZ R1, LOOP2 ;Move on to the next iteration of the current pass.
Continue1: DJNZ R0, LOOP1 ;Move on to the next pass.
;Here: SJMP Here ;End of program - Loop here indefinitely.
MOV A, 06H
MOV B ,#02H
DIV AB
MOV R6,B
CJNE R0,#0h,ODDMEDIAN
LJMP EVENMEDIAN
;----------------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------------
ODDMEDIAN: MOV A,R7
ADD A, #01H
MOV B ,#02H
DIV AB
SUBB A,#01H
MOV DPTR, #200h
BACK: INC DPTR
DJNZ ACC, BACK
MOVC A, @A+DPTR
MOV B ,#02H
DIV AB
MOV B, #100 ;Convert into ASCII characters and print
DIV AB
ADD A, #30H
ACALL SEND_DATA
MOV A,B
MOV B, #10
DIV AB
ADD A, #30H
ACALL SEND_DATA
MOV A,B
ADD A, #30H
ACALL SEND_DATA
EVENMEDIAN:MOV A,R7
MOV B ,#02H
DIV AB
SUBB A,#01H
MOV DPTR, #200h
BACK2: INC DPTR
DJNZ ACC, BACK2
MOVC A, @A+DPTR
MOV R5,A
INC DPTR
MOVC A, @A+DPTR
ADD A,R5
MOV B ,#02H
DIV AB
MOV B, #100 ;Convert into ASCII characters and print
DIV AB
ADD A, #30H
ACALL SEND_DATA
MOV A,B
MOV B, #10
DIV AB
ADD A, #30H
ACALL SEND_DATA
MOV A,B
ADD A, #30H
ACALL SEND_DATA
SAMPLEMEAN:MOV DPTR, #200h
MOV R4, #00h
MOV A,R7
loop: MOVC A, @A+DPTR ; Coping value from memory location at which R0 is pointing
ADD A,R4
MOV R4,A ; Sum is stored in R4 register
INC DPTR
DJNZ R7, loop
MOV B,#06h ; Moving number of elements to register B
MOV A,R4 ; Moving Sum all elements to register A
DIV AB ; Finding average
MOV R3,A
MEANDEVIATION:MOV DPTR, #200h
MOV R4, #00h
MOV A,R7
loop3: MOVC A, @A+DPTR ; Coping value from memory location at which R0 is pointing
SUBB A,R3
MOV R4,A ; Sum is stored in R4 register
INC DPTR
DJNZ R7, loop3
MOV B,#06h ; Moving number of elements to register B
MOV A,R4 ; Moving Sum all elements to register A
DIV AB ; Finding average
MOV R3,A
;KEYBOARD_LOOP:
; acall KEYBOARD
; ;now, A has the key pressed
; acall SEND_DATA
; sjmp KEYBOARD_LOOP
CONFIGURE_LCD: ;THIS SUBROUTINE SENDS THE INITIALIZATION COMMANDS TO THE LCD
mov a,#38H ;TWO LINES, 5X7 MATRIX
acall SEND_COMMAND
mov a,#0FH ;DISPLAY ON, CURSOR BLINKING
acall SEND_COMMAND
mov a,#06H ;INCREMENT CURSOR (SHIFT CURSOR TO RIGHT)
acall SEND_COMMAND
mov a,#01H ;CLEAR DISPLAY SCREEN
acall SEND_COMMAND
mov a,#80H ;FORCE CURSOR TO BEGINNING OF THE FIRST LINE
acall SEND_COMMAND
ret
SEND_COMMAND:
mov p1,a ;THE COMMAND IS STORED IN A, SEND IT TO LCD
clr p3.5 ;RS=0 BEFORE SENDING COMMAND
clr p3.6 ;R/W=0 TO WRITE
setb p3.7 ;SEND A HIGH TO LOW SIGNAL TO ENABLE PIN
acall DELAY
clr p3.7
ret
SEND_DATA:
mov p1,a ;SEND THE DATA STORED IN A TO LCD
setb p3.5 ;RS=1 BEFORE SENDING DATA
clr p3.6 ;R/W=0 TO WRITE
setb p3.7 ;SEND A HIGH TO LOW SIGNAL TO ENABLE PIN
acall DELAY
clr p3.7
ret
DELAY:
push 0
push 1
mov r0,#50
DELAY_OUTER_LOOP:
mov r1,#255
djnz r1,$
djnz r0,DELAY_OUTER_LOOP
pop 1
pop 0
ret
KEYBOARD: ;takes the key pressed from the keyboard and puts it to A
mov P0, #0ffh ;makes P0 input
K1:
mov P2, #0 ;ground all rows
mov A, P0
anl A, #00001111B
cjne A, #00001111B, K1
K2:
acall DELAY
mov A, P0
anl A, #00001111B
cjne A, #00001111B, KB_OVER
sjmp K2
KB_OVER:
acall DELAY
mov A, P0
anl A, #00001111B
cjne A, #00001111B, KB_OVER1
sjmp K2
KB_OVER1:
mov P2, #11111110B
mov A, P0
anl A, #00001111B
cjne A, #00001111B, ROW_0
mov P2, #11111101B
mov A, P0
anl A, #00001111B
cjne A, #00001111B, ROW_1
mov P2, #11111011B
mov A, P0
anl A, #00001111B
cjne A, #00001111B, ROW_2
mov P2, #11110111B
mov A, P0
anl A, #00001111B
cjne A, #00001111B, ROW_3
ljmp K2
ROW_0:
mov DPTR, #KCODE0
sjmp KB_FIND
ROW_1:
mov DPTR, #KCODE1
sjmp KB_FIND
ROW_2:
mov DPTR, #KCODE2
sjmp KB_FIND
ROW_3:
mov DPTR, #KCODE3
KB_FIND:
rrc A
jnc KB_MATCH
inc DPTR
sjmp KB_FIND
KB_MATCH:
clr A
movc A, @A+DPTR; get ASCII code from the table
ret
;ASCII look-up table
KCODE0: DB '1', '2', '3', 'A'
KCODE1: DB '4', '5', '6', 'B'
KCODE2: DB '7', '8', '9', 'C'
KCODE3: DB '*', '0', '#', 'D'
ORG 300h
ARRAYLIST:
DB 12 , 69 , 35 ,78 ,88 ,5 ,100 ,34 , 56 , 32 , 61 , 22 ,10 , 99 , 17 ; 15 numbers
END
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team