Current location - Education and Training Encyclopedia - Graduation thesis - 5 1 Single Chip Microcomputer Simple Calculator Paper
5 1 Single Chip Microcomputer Simple Calculator Paper
ORG 0000H

Starting: MOV 78H, # 0; Initialization: 78H, put 0 segments of code, and put other codes.

MOV 79H,# 10

MOV 7AH,# 10

MOV 7BH,# 10

MOV 7CH,# 10

MOV 7DH,# 10

MOV R5,# 0; R5 is the number of keystrokes, which is initially set to 0.

MOV 30H,# 0; 30H is a function key storage unit, which is set to 0.

MOV 40H,# 0; The 40H cell is initially set to 0.

MOV 4 1H,# 0; The 4 1H cell is initially set to 0.

Loop: LCALL DIR

LCALL key

INC R5

; Distribute the program to determine which key was pressed.

S 1:CJNE A,# 10,S2; Not the "+"key, skip to S2.

LJMP is fun; It's the "+"key, jump to fun.

S2:CJNE A,# 1 1,S3; Not the "-"key, skip to S3.

LJMP is fun; Is the "-"key, jump to FUN.

S3:CJNE A,# 12,S4; Not the "*" key, skip to S4.

LJMP is fun; It's the "*" key, jump to FUN.

S4:CJNE A,# 13,S5; Not the "/"key, skip to S5.

LJMP is fun; Is the "/"key, jump to FUN.

S5:CJNE A,# 14,S6; Not the "=" key, skip to S6.

LJMP is fun; It is the "=" key, which is fun to jump.

S6:CJNE A,# 15,n 1; Not the "CL" key, skip to N 1.

LJMP starts; It is the "CL" key, and the jump begins.

N 1:CJNE R5,# 1,N2; Judge the number of times the key is pressed.

LJMP D 1 1

N2:CJNE R5,#2,N3

LJMP T2

N3:CJNE R5,#3,N4

LJMP T3

N4:CJNE R5,#4,N5

LJMP T4

N5:CJNE R5,#5,N6

LJMP T5

N6:CJNE R5, #6, start

LJMP T6

MOV·R4

MOV 78H,A; The input value is sent to the display bit buffer.

MOV 79H,# 10

MOV 7AH,# 10

MOV 7BH,# 10

MOV 7CH,# 10

MOV 7DH,# 10

LJMP loop

T2:MOV·R7

MOV B,# 10

R4 MOV

MUL AB

Add a, R7

MOV·R4

MOV 7AH,# 10

MOV 7BH,# 10

MOV 7CH,# 10

MOV 7DH,# 10

MOV 79H, 78H, one to ten.

MOV 78H,R7; The new number is a single digit.

LJMP loop

T3:MOV R7,A

MOV B,# 10

R4 MOV

MUL AB

Add a, R7

MOV·R4

MOV 7BH,# 10

MOV 7CH,# 10

MOV 7DH,# 10

MOV 7AH, 79H, ten to a hundred

MOV 79H, 78H, one to ten.

MOV 78H,R7; The new number is a single digit.

LJMP loop

T4:MOV·R7

MOV B,# 10

R4 MOV

MUL AB

Add a, R7

MOV·R4

MOV 7CH,# 10

MOV 7DH,# 10

MOV 7BH,7AH

MOV 7AH,79H

MOV 79H,78H

MOV 78H,R7

LJMP loop

T5:MOV R7,A

MOV B,# 10

R4 MOV

MUL AB

Add a, R7

MOV·R4

MOV 7DH,# 10

MOV 7CH,7BH

MOV 7BH,7AH

MOV 7AH,79H

MOV 79H,78H

MOV 78H,R7

LJMP loop

T6:MOV R7,A

MOV B,# 10

R4 MOV

MUL AB

Add a, R7

MOV·R4

MOV 7DH,7CH

MOV 7CH,7BH

MOV 7BH,7AH

MOV 7AH,79H

MOV 79H,78H

MOV 78H,R7

LJMP loop

MOV 7CH,7BH

MOV 7BH,7AH

MOV 7AH,79H

MOV 79H,78H

MOV 78H,R7

LJMP loop

Fun: MOV 78H, # 10

MOV 79H,# 10

MOV 7AH,# 10

MOV R0,30h; Switch with the last function key

MOV 30H,A

MOV A,R0

CJNE A,# 10,fun 1; Judgment function key

LJMP ADDY"+"

FUN 1:CJNE A,# 1 1,FUN2

LJMP SUBT; "-"

FUN2:CJNE A,# 12,FUN3

LJMP MULT; "*"

FUN3:CJNE A,# 13,FUN4

LJMP DIVI"/"

FUN4:CJNE A, # 14, FUN5 Press the function key for the first time, that is, A=#0.

LJMP EQUA"="

FUN5:MOV 40H,R4; Save the first number.

MOV R5,# 0; Clear keystrokes

LJMP bcd decomposes it into BCD codes for later display.

Yes: LJMP begins; overflow handling

Eddy: MOV A, the first number of 40H is sent to the accumulator.

Add one, R4; The first number plus the second number.

JB CY,OF; spill over

MOV 40H,A; Save this result.

MOV R5,# 0; Clear keystrokes

LJMP BCD

SUBT:MOV A,40H

R4 SUBB

JB CY,OF

MOV 40H,A

MOV R5,#0

LJMP BCD

MULT:MOV A,40H

MOV B.

R4 MOV

MUL AB

JB OV

MOV 40H,A

MOV R5,#0

LJMP BCD

DIVI: Divi A R4

MOV B.

MOV A,40H

Division AB

JB OV

MOV 40H,A

MOV R5,#0

LJMP BCD

Equation: MOV R5, #0

LJMP BCD

BCD:MOV B,# 10

The result of MOV A, 40H is sent to the accumulator.

DIV AB result divided by 10

MOV 4 1H,A; Temporarily store "business"

MOV a and b; Take a single digit

MOV 78H,A; The unit number sent to the display buffer.

MOV A,4 1H

JZ regression; The result is a single digit, and the LOOP is returned.

MOV B,# 10

MOV A,4 1H

Division AB

MOV 4 1H,A

MOV A,B

MOV 79H,A; Ten-bit display buffer

MOV A,4 1H

JZ regression; The result is a two-digit number, which will return to the loop.

MOV 7AH,A; Hundred-digit transmission display cache

Return: LJMP loop

; Dynamic display subroutine

Director: MOV·DPTR, # TAB Digital Tube Decodes Header Address

MOV R0, # 78H Bit address of buffer to be displayed.

MOV A, # 0FEH unit bit selection signal

MOV R 1,A

LD 1:MOV A,@R0

MOVC A,@ A+DPTR; table look-at

MOV P2,r 1; * * * anode tube word bit selection is sent to P2 port.

MOV P0,A; The field code is sent to P0 port.

LCALL delay 1 ms; Delay adjustment 1ms subroutine

INC R0R0 points to the next module.

MOV A,r 1;

JNB ACC.5, LD2 judge whether to send six numbers.

RL A; Point to the next one.

MOV R 1,A; The bit selection signal is stored back to R3.

SJMP LD 1; Skip to show the next number.

LD2:RET; Send six numbers and return.

TAB:DB 0C0H, 0F9H, 0A4H, 0B0H, 099H, 092H, 082H, 0F8H, 80H, 90H, 0FFH* * * anode decoding table.

Delay 1 ms: MOV R6, second

LOOP 1:MOV R7,#248

Nototherwiseprovided(for) unless otherwise specified.

Loop 2:DJNZ R7, loop 2

DJNZ R6,LOOP 1

Soak in water to soften

KEY:LCALL KS; Call detection key subroutine

JNZ k 1; Press the button to continue.

LCALL DELAY2 Keyless Call Delay De-jitter

ACALL DIR call dynamic display

AJMP key; Return to continue detection button

k 1:LCALL delay 2; There is a key delay jitter.

LCALL KS then calls the subprogram for detecting rebar pressing.

JNZ K2 confirms that there is a button to continue the next step.

ACALL DIR call dynamic display

AJMP key; Press no key to return to continue detection.

K2:MOV R2, # 0EFH sends the scanned value to R2 for temporary storage.

MOV R3, # 00H sends the first column value to R3 for temporary storage.

K3:MOV P 1,R2; Send R2 value to port P 1.

L0:JB P 1.0,l 1; P 1.0 is equal to 1. Jump to L 1.

MOV A, # 00H sends the first line value to ACC.

AJMP LK jumps to the key value handler.

L 1:JB P 1. 1,L2; P 1. 1 equals 1 jump to L2.

MOV A, # 04H sends the row value of the second row to ACC.

AJMP LK jumps to the key value handler.

L2:JB P 1.2,L3; P 1.2 equals 1 jump to L3.

MOV A, # 08H sends the third line value to ACC.

AJMP LK jumps to the key value handler.

L3:JB P 1.3, next; P 1.3 equals 1 Skip to the next page.

MOV A, # 0CH sends the fourth line value to ACC.

LK: add one, R3; The key value after adding the row value and the column value is sent to the.

Push ACC to send the value in to the stack for temporary storage.

K4:LCALL delay 2; Call the delayed debounce program.

LCALL KS calls the key detector.

JNZ K4; The key is not released and continues to return to the detection state.

POP ACC sends stack value to ACC.

MOV·DPTR, # keyboard

MOVC A,@A+DPTR

Soak in water to soften

Next: INC R3 column value plus 1

MOV A,R2; R2 value is sent to.

JNB ACC 7, adjustable; After scanning, go to the key for the next scan.

RL A; The scan has not been completed. Move the value one bit to the left to scan the next column.

MOV·R2; Send ACC value to R2 for temporary storage.

AJMP K3 jumps to K3 to continue.

KS:MOV P 1, # 0FH is set to P 1, with four high digits 0 and four low digits 1.

MOV A,p 1; Read port P 1.

XRL A, # 0FH distinguishes values in from values in or.

RET subroutine return

KEYTAB:DB 1,2,3, 10,4,5,6, 1 1,7,8,9, 12, 15,0, 14, 13; Key value table

Delay 2:MOV R6, # 2H;; Delay de-jitter subroutine

LP 1:MOV R7,#0FAH

LP2:DJNZ R7,LP2

DJNZ R6,LP 1

Soak in water to soften

end