Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

calculator

Status
Not open for further replies.

sara_6252

New Member
please i need a source code in assembley langauge for a calculator that displayed at screen (lcd) which does the four function (*,/,+,-) using 8051 for two digit
thanks
pleaaaaaaaaaaaase
 
Hi, i can help you with that code but in diferent way. i have a code for calculator but in picbasic(for pic micocontrollers).if you want ask me again.
 
Whilst we enjoy helping people; in order to help you we need to know how far you've progressed. Please post what you've already done, including any ideas you've had. If you need help that your lecturer should have provided, please tell us (and your lecturer) what you found was lacking. It is not right if you manage to attain a high grade from the help we have provided if your lecturer is negligent; it will make them appear to be better than they really are and put you at an unfair advantage to your classmates.

It also would help us to know more about your education, geographical location and experience with the English language.
 
my code:
please help


Code:
RS EQU P3.4
RW EQU P3.5
EN EQU P3.6
DATA EQU P1
 DB4     EQU   P3.4
 DB5     EQU   P3.5
 DB6     EQU   P3.6
 DB7     EQU   P3.7
 EN      EQU   P3.3
 RS      EQU   P3.2
 

mov r7,#3
lcall operand
cjne r7,#2,error
mov r0,a
lcall operator
cjne r7,#1,error
mov r1,a
lcall operand
cjne r7,#0,error
mov r2,a
lcall equal
LCALL INIT_LCD
MOV A, #'0'

error:
jmp $

operand:
LCALL WRITE_TEXT
lCALL INIT_LCD
MOV P2, #11110000B
JNB P2.0, ROW1
JNB P2.1, ROW2
JNB P2.2, ROW3
JNB P2.3, ROW4
;JMP LOOP

ROW1:
MOV P2, #00001111B
JNB P2.4, SHOW7
JNB P2.5, SHOW8
JNB P2.6, SHOW9
;JNB P2.7, SHOW_ADD
JMP $

ROW2:
MOV P2, #00001111B
JNB P2.4, SHOW4
JNB P2.5, SHOW5
JNB P2.6, SHOW6
;JNB P2.7,SHOW_sub
JMP $

ROW3:
MOV P2, #00001111B
JNB P2.4, SHOW1
JNB P2.5, SHOW2
JNB P2.6, SHOW3
;JNB P2.7, SHOW_MUL
JMP $

ROW4:
MOV P2, #00001111B
JNB P2.4, SHOW_ON
JNB P2.5, SHOW0
;JNB P2.6, SHOW_equal
;JNB P2.7, SHOW_div
JMP $

SHOW0:
MOV A, #'0'
lCALL WRITE_TEXT
lCALL DELAY
dec r7

SHOW1:
MOV A, #'1'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP

SHOW2:
MOV A, #'2'
lCALL WRITE_TEXT
lCALL DELAY
;JMP LOOP

SHOW3:
MOV A, #'3'
lCALL WRITE_TEXT
;CALL DELAY
dec r7
;JMP LOOP

SHOW4:
MOV A, #'4'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP

SHOW5:
MOV A, #'5'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP

SHOW6:
MOV A, #'6'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP

SHOW7:
MOV A, #'7'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SHOW8:
MOV A, #'8'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP

SHOW9:
MOV A, #'9'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP



ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SHOW_ON:
MOV A, #'ON'
lCALL WRITE_TEXT
lCALL DELAY
;JMP LOOP

operator:

LCALL WRITE_TEXT

lCALL INIT_LCD
MOV P2, #11110000B
JNB P2.0, ROW11
JNB P2.1, ROW22
JNB P2.2, ROW33
JNB P2.3, ROW44
;JMP LOOP

ROW11:
MOV P2, #00001111B
;JNB P2.4, SHOW7
;JNB P2.5, SHOW8
;JNB P2.6, SHOW9
JNB P2.7, SHOW_ADD
JMP $

ROW22:
MOV P2, #00001111B
;JNB P2.4, SHOW4
;JNB P2.5, SHOW5
;JNB P2.6, SHOW6
JNB P2.7,SHOW_sub
JMP $

ROW33:
MOV P2, #00001111B
;JNB P2.4, SHOW1
;JNB P2.5, SHOW2
;JNB P2.6, SHOW3
JNB P2.7, SHOW_MUL
JMP $

ROW44:
MOV P2, #00001111B
;JNB P2.4, SHOW_ON
;JNB P2.5, SHOW0
JNB P2.6, SHOW_equal
JNB P2.7, SHOW_div
JMP $



SHOW_ADD:
MOV A, #'+'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP


SHOW_sub:
MOV A, #'-'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP


SHOW_mul:
MOV A, #'*'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP


SHOW_div:
MOV A, #'/'
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP

ret

equal:
LCALL WRITE_TEXT

lCALL INIT_LCD
MOV P2, #11110000B
JNB P2.2, ROW444
ROW444:
JNB P2.6, SHOW_equal
SHOW_EQUAL: MOV A, #'='
lCALL WRITE_TEXT
lCALL DELAY
dec r7
;JMP LOOP
ret



INIT_LCD:
CLR RS
CLR RW
CLR EN
MOV DATA, #38H
SETB EN
CLR EN
lCALL WAIT_LCD
CLR RS
CLR RW
MOV DATA, #0EH
SETB EN
CLR EN
lCALL WAIT_LCD
CLR RS
CLR RW
MOV DATA, #06H
SETB EN
CLR EN
lCALL WAIT_LCD
RET

WAIT_LCD:
MOV R1, #50
LOOP2:
MOV R2, #50
LOOP1:
DJNZ R2, LOOP1
DJNZ R1, LOOP2
RET

WRITE_TEXT:
SETB RS
CLR RW
CLR EN
MOV DATA, A
SETB EN
NOP
NOP
CLR EN
lCALL WAIT_LCD
RET

DELAY:
MOV R1, #50
LOOP4:
MOV R2, #50
LOOP3:
MOV R3, #300
LOOP5:
DJNZ R3, LOOP5
DJNZ R2, LOOP3
DJNZ R1, LOOP4
RET


;mov r0,p3
;mov r1,p3
;mov r2,p3
;mov r3,p3

cjne r1,#'+',sub
mov a,r0
add a,r1
jmp equ

equ:
cjne r3,#'=',error2
lcall WRITE_TEXT
;JMP LOOP
error2:nop

sub: 
cjne r1,#'-',mul
mov a,r0
subb a,r2

mul:
cjne r1,#'*',div
mov a,r0
mov b,r2
mul ab

div:
cjne r1,#'/',error1
mov b,r2
mov a,r0
div ab
error1:
jmp $
 
Last edited:
justDIY said:
you need to have your keyboard cleaned, it seems some of your llllllllllllletters are sticking!

it's not the keyboard, as sometimes the letter 'a' also freezes....

And sara, you would have much more chances to acheive your project by communicating your problem with us in detail, explaining where is the problem in the code, instead of begging for help.
 
Status
Not open for further replies.

Latest threads

Back
Top