Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
asm
1 ;---------------------------------------------------------------------------------------------------#!
2 ;---------------------------------------------------------------------------------------------------#!
3 ;-----------------------------{{Author: Mustafa Okasha}}--------------------------------------------#!
4 ;---------------------------{{Project: BasicCalculator 1.1}}----------------------------------------#!
5 ;---------------------------{{System: 8051 microcontroller}}----------------------------------------#!
6 ;------------------------------{{Released at: 24/2/2013}}-------------------------------------------#!
7 ;---------------------------------------------------------------------------------------------------#!
8 ;---------------------------------------------------------------------------------------------------#!
9 N1 EQU 30H ;#!Ram byte location holds first oeprand
10 N2 EQU 31H ;#!Ram byte locations holds second operand
11 OP EQU 32H ;#!Ram byte location holds operation ascii code
12 R EQU 33H ;#!Ram byte location holds result
13 SIGN EQU 34H ;#!Ram byte location holds result's sign
14 TEMP EQU 35H ;#!Ram byte location holds temporary data
15 DIF BIT 0AH ;#!Digit input flag bit(0,1,2,3,4,5,6,7,8,9)
16 OIF BIT 0BH ;#!Operator input flag bit(+,-,*,/)
17 AIF BIT 0CH ;#!Assignment operator flag bit(=)
18 ORG 0H ;#!Orginate at rom address 0000H
19 AJMP MAIN ;#!Absoulte jump to main routine
20 ;--------------------------------------------------------------------------------------------------#!
21 ;--------------------------------------------------------------------------------------------------#!
22 ORG 30H ;#!Orginate at rom adress 0030H
23 MAIN: ACALL memoryInit ;#!CALL memory initialization subroutine
24 ACALL lcdInit ;#!CALL lcd initialization subroutine
25 ACALL readInput ;#!CALL read input subroutine
26 ACALL calculateResult ;#!CALL calculate result subroutine
27 ACAll printOutput ;#!CALL print output subroutine
28 AJMP MAIN ;#!return and start the program once more
29 ;--------------------------------------------------------------------------------------------------#!
30 ;--------------------------------------------------------------------------------------------------#!
31 memoryInit:
32 CLR A ;#!Clear ACC
33 MOV N1,A ;#!Clear first operand location in ram
34 MOV N2,A ;#!Clear second operand location in ram
35 MOV OP,A ;#!Clear operation location in ram
36 MOV R,A ;#!Clear result location in ram
37 MOV SIGN,A ;#!Clear sign location in ram
38 MOV TEMP,A ;#!Clear result location in ram
39 CLR C ;#!Clear carry bit
40 MOV DIF,C ;#!Clear digit flag bit
41 MOV OIF,C ;#!Clear operator flag bit
42 MOV AIF,C ;#!Clear assignment operator flag bit
43 RET ;#!return to MAIN routine
44 ;--------------------------------------------------------------------------------------------------#!
45 lcdInit:
46 MOV DPTR,#MYCOM ;#!Set DPTR to look-up table's address
47 C1: CLR A ;#!Clear ACC
48 MOVC A,@A+DPTR ;#!Get code from look-up table and placing it into ACC
49 ACALL COMMWRT ;#!CALL LCD command write subroutine
50 INC DPTR ;#!Increment DPTR <DPTR = DPTR + 1>
51 JZ C2 ;#!Jump if ACC = ZERO to end of loop
52 SJMP C1 ;#!If not start the loop again
53 C2: RET ;#!return to MAIN routine
54 ;--------------------------------------------------------------------------------------------------#!
55 readInput:
56 ACALL readKey ;#!CALL keypad subroutine to read one number
57 ACALL validateInput ;#!CALL subroutine to confirm of valid number
58 JB OIF,ERROR ;#!Jump to ERROR routine if OIF = 1
59 JB AIF,ERROR ;#!Jump to ERROR routine if AIF = 1
60 ACALL DATAWRT ;#!CALL subroutine so pass data to LCD
61 ANL A,#0FH ;#!Masking to convert number form ASCII to BCD
62 MOV N1,A ;#!Save number at RAM
63 ACALL readKey ;#!CALL keypad subroutine to read operation(+,-,*,/)
64 ACALL validateInput ;#!CALL subroutine to confirm of valid operation
65 JB DIF,ERROR ;#!Jump to ERROR routine if DIF = 1
66 JB AIF,ERROR ;#!Jump to ERROR routine if AIF = 1
67 ACALL DATAWRT ;#!CALL subroutine so pass data to LCD
68 MOV OP,A ;#!Save operation at RAM
69 ACALL readKey ;#!CALL keypad subroutine to read one number
70 ACALL validateInput ;#!CALL subroutine to confirm of valid number
71 JB OIF,ERROR ;#!Jump to ERROR routine if OIF = 1
72 JB AIF,ERROR ;#!Jump to ERROR routine if AIF = 1
73 ACALL DATAWRT ;#!CALL subroutine so pass data to LCD
74 ANL A,#0FH ;#!Masking to convert number form ASCII to BCD
Page 1
C:\Users\tafatefo\Documents\myCalculator.asm
Page 2
C:\Users\tafatefo\Documents\myCalculator.asm
Page 3
C:\Users\tafatefo\Documents\myCalculator.asm
Page 4