|
51单片机的完整计算器程序
单片机源程序如下:
- ;$$$$变量定义区(30H-)$$$$$
- OUTBIT EQU P2 ; 位控制口
- OUTSEG EQU P0 ; 段控制口
- ROW_COLUMN EQU P1 ; 读键盘行线口
- VARIABLE_DELAY1 EQU 30H ;延时变量
- VARIABLE_DELAY2 EQU 31H
- VARIABLE_STORE1 EQU 32H ;存储第一个输入数
- VARIABLE_STORE2 EQU 33H
- VARIABLE_STORE3 EQU 34H ;存储第二个输入数
- VARIABLE_STORE4 EQU 35H
- VARIABLE_STORE5 EQU 36H ;存储最后结果
- VARIABLE_STORE6 EQU 37H
- VARIABLE_INPUT1A EQU 38H ;第一个输入数保存地址
- VARIABLE_INPUT1B EQU 39H
- VARIABLE_INPUT1C EQU 3AH
- VARIABLE_INPUT1D EQU 3BH
- VARIABLE_INPUT2A EQU 3CH ;第二个输入数保存地址
- VARIABLE_INPUT2B EQU 3DH
- VARIABLE_INPUT2C EQU 3EH
- VARIABLE_INPUT2D EQU 3FH
- VARIABLE_REPLACE_POINT EQU 40H ;结果显示位置指针
- ;VARIABLE_RESULTB EQU 41H
- ;VARIABLE_RESULTC EQU 42H
- ;VARIABLE_RESULTD EQU 43H
- VARIABLE_SIGN1 EQU 44H ;保存第一个符号位
- VARIABLE_SIGN2 EQU 45H ;保存第二个符号位
- VARIABLE_INPUT1_POINT EQU 46H ;第一个输入数状态指针,记录输入的位数
- VARIABLE_INPUT2_POINT EQU 47H ;第二个输入数状态指针,记录输入的位数
- VARIABLE_RESULT_POINT EQU 48H ;第二个输入数状态指针,记录输入的位数
- VARIABLE_PLACE1_POINT EQU 49H ;第一个输入数位置指针
- VARIABLE_PLACE2_POINT EQU 4AH ;第一个输入数位置指针
- VARIABLE_LEDBUF_POINT EQU 4BH ;第一个输入数位置指针
- VARIABLE_LEDBUF EQU 4CH ; 显示缓冲
- S1 EQU 50H ;自定义数字电路入口与出口
- S2 EQU 51H ;功能1实现:将分离个位数字(S1-S5),转化为十进制,存储在S6,S7
- S3 EQU 52H ;功能2实现:将十进制位数字(S6-S7),转化为个位数字,存储在(S1-S5)
- S4 EQU 53H ;S1(最高位),S5(最低位)
- S5 EQU 54H
- S6 EQU 55H
- S7 EQU 56H
- KEY1 BIT P3.2
- KEY2 BIT P3.3
- KEY3 BIT P3.4
- KEY4 BIT P3.5
- ;****************************************************进入主程序*****************************************************************************
- ORG 0000H
- AJMP STABLE
- ORG 0100H
- ; *****************************************************键码定义和键值定义*******************************************************************
- LEDMAP: ; 八段管显示码(共阳极)
- DB 0C0h, 0F9h, 0A4h, 0B0h, 099h, 092h, 082h, 0F8h,080h, 090h, 088h, 083h,0C6H
- KEYTABLE:
- DB 00h, 04h, 08h
- DB 01h, 05h, 09h
- DB 02h, 06h, 0Ah
- DB 03h, 07h, 0Bh
- ;$$$$子程序区$$$
- $$$
- ;****************************************************延时程序(30H,31H)**********************************************************************
- DELAY:
- MOV VARIABLE_DELAY1,#10H
- DE1:
- MOV VARIABLE_DELAY2,#06FH
- DE:
- DJNZ VARIABLE_DELAY2,DE
- DJNZ VARIABLE_DELAY1 ,DE1
- RET
- ;***************************************************扫描按键程序*****************************************************************************
- SCANNING:
- JNB KEY1,FUNCTION1_SIGN1
- JNB KEY2,FUNCTION2_SIGN1
- JNB KEY3,FUNCTION3_SIGN1
- JNB KEY4,FUNCTION4_SIGN1
- RET
- ;****************************************************第一个符号位保存程序*****************************************************************
- FUNCTION1_SIGN1:
- MOV VARIABLE_SIGN1,#1
- SJMP SCANNING
- FUNCTION2_SIGN1:
- MOV VARIABLE_SIGN1,#2
- SJMP SCANNING
- FUNCTION3_SIGN1:
- MOV VARIABLE_SIGN1,#3
- SJMP SCANNING
- FUNCTION4_SIGN1:
- MOV VARIABLE_SIGN1,#4
- SJMP SCANNING
- ;****************************************************LED显示程序****************************************************************************
- DISPLAYLED:
- MOV R0, #VARIABLE_LEDBUF
- MOV R1, #4 ; 共4个八段管
- MOV R2, #11111110B ; 从左边开始显示
- LOOP:
- MOV OUTBIT, #0FFH ; 关所有八段管
- MOV OUTSEG, @R0
- MOV OUTBIT, R2 ; 显示一位八段管
- ACALL DELAY ;
- MOV A, R2 ; 位选选中下一位
- RL A ;
- MOV R2, A ;
- INC R0
- DJNZ R1, LOOP
- RET
- ;**************************************************行值局部程序*****************************************************************************
- GET_ROW1:
- MOV A,ROW_COLUMN ; 读入键状态
- ORL A, #0f8h ; 高5位不用,变为11111
- CPL A ;11111110->00000001,11111101->00000010,11111011->00000100, 1,2,4
- RET
- ;*******************************得到行值程序,出口参数R3(行值)**********************************************************************************
- GET_ROW:
- MOV ROW_COLUMN,#07H ;将行线置1.列线置0
- MOV R3,#0FFH
- ACALL GET_ROW1
- GE1:
- RRC A
- INC R3
- JC GE2
- SJMP GE1
- GE2:
- RET
- ;***************************得到列值程序,出口参数R4(列值),所用寄存器R1,R2******************************************** ***************
- GET_COLUMN:
- MOV ROW_COLUMN,#07H ;将行线置1.列线置0
- MOV R2, #4
- KLoop:
- CJNE R2,#4,NEXT1
- MOV A,#01FH
- AJMP NEXT5
- NEXT1:
- CJNE R2,#3,NEXT2
- MOV A,#02FH
- AJMP NEXT5
- NEXT2:
- CJNE R2,#2,NEXT3
- MOV A,#04FH
- AJMP NEXT5
- NEXT3:
- CJNE R2,#1,NEXT5
- MOV A,#08FH
- NEXT5:
- MOV ROW_COLUMN, a
- ACALL GET_ROW1 ;调用得到行值时需要给出列值的状态
- JZ GOON1 ;当
- A为零时,说明本列有键按下
- DJNZ R2, KLoop ;扫描四次直至将全部列扫描完毕
- GOON1:
- MOV A, #4 ;列值减1
- SUBB A,R2
- MOV R4,A
- RET
- ;************键值计算程序,入口参数,R3(行值),R4(列值),出口参数R5(键值)******************************************************************
- CALCULATE_KEY: ;键值 = 列 X 3 + 行
- MOV A,R4
- MOV B,#3
- MUL AB
- ADD A,R3
- MOV DPTR,#KEYTABLE
- ACALL LOOK_UP_TABLE
- MOV R5,A
- RET
- ;**************************************************按键抖动去除程序**********************************************************************
- WAIT_RELEASE:
- ACALL TEST_KEY
- JNZ WAIT_RELEASE
- RET
- ;************************************************得到键值总程序,出口参数R5(键值)********************************************************************
- GET_KEY:
- ACALL GET_ROW
- ACALL GET_COLUMN
- ACALL CALCULATE_KEY
- ACALL WAIT_RELEASE
- RET
- ;*****************************************************测试按键是否按下程序,出口参数A***********************************************
- TEST_KEY:
- MOV ROW_COLUMN,#07H ;将行线置1.列线置0
- ACALL GET_ROW1
- RET
- ;**********************************************计算器输入第一个数程序****************************************************************
- CALCULATOR_INPUT1: ;USE:R0,R1,R2;出口参数R5
- MOV R1,VARIABLE_PLACE1_POINT ;将所得键码送入相应存储区
- MOV A,R5
- MOV @R1,A
- INC VARIABLE_PLACE1_POINT
- ACALL LOOK_UP_TABLE1 ;将所得段码送入相应缓冲区
- MOV R0,VARIABLE_LEDBUF_POINT
- MOV @R0,A
- INC VARIABLE_LEDBUF_POINT
- RET
- ;**********************************************计算器输入第二个数程序****************************************************************
- CALCULATOR_INPUT2: ;USE:R0,R1,R2;出口参数R5
- CLR C
- MOV A,R5
- CAL1:
- INC VARIABLE_INPUT2_POINT
- MOV R2,VARIABLE_INPUT2_POINT
- CJNE R2,#5,CAL4
- SJMP CAL5 ;输入四个数后,第五个数一定为符号位
- CAL4:
- SUBB A,#8
- JC CAL2 ;符号位应大等于8
- SJMP CAL3
- CAL2:
- ADDC A,#8
- MOV R1,VARIABLE_PLACE2_POINT ;将所得键码送入相应存储区
- MOV @R1,A
- INC VARIABLE_PLACE2_POINT
- ACALL LOOK_UP_TABLE1 ;将所得段码送入相应缓冲区
- MOV R0,VARIABLE_LEDBUF_POINT
- MOV @R0,A
- INC VARIABLE_LEDBUF_POINT
- SJMP CAL5
- CAL3:
- ADD A,#8
- CAL5:
- RET
- ;************************************************************整合程序1***********************************************************************
- INTEGRATE1:
- MOV R7, VARIABLE_INPUT1_POINT
- CJNE R7,#1,FF1
- MOV S5,VARIABLE_INPUT1A
- MOV S1,#0
- MOV S2,#0
- MOV S3,#0
- MOV S4,#0
- LCALL CALCULATOR_INTEGRATE
- AJMP NEXT22
- FF1:
- CJNE R
- 7,#2,FF2
- MOV S4,VARIABLE_INPUT1A
- MOV S5,VARIABLE_INPUT1B
- MOV S2,#0
- MOV S3,#0
- MOV S1,#0
- LCALL CALCULATOR_INTEGRATE
- AJMP NEXT22
- FF2:
- CJNE R7,#3,FF3
- MOV S3,VARIABLE_INPUT1A
- MOV S4,VARIABLE_INPUT1B
- MOV S5,VARIABLE_INPUT1C
- MOV S1,#0
- MOV S2,#0
- LCALL CALCULATOR_INTEGRATE
- AJMP NEXT22
- FF3:
- MOV S2,VARIABLE_INPUT1A
- MOV S3,VARIABLE_INPUT1B
- MOV S4,VARIABLE_INPUT1C
- MOV S5,VARIABLE_INPUT1D
- MOV S1,#0
- LCALL CALCULATOR_INTEGRATE
- NEXT22:
- MOV VARIABLE_STORE1,S6 ;将转化后的值存在S8和S9中
- MOV VARIABLE_STORE2,S7
- LCALL QL
- MOV VARIABLE_LEDBUF+0, #0FFH ; 显示管输完符号位后显示全灭
- MOV VARIABLE_LEDBUF+1, #0FFH
- MOV VARIABLE_LEDBUF+2, #0FFH
- MOV VARIABLE_LEDBUF+3, #0FFH
- MOV VARIABLE_LEDBUF_POINT,#VARIABLE_LEDBUF
- RET
- ;************************************************************整合程序2***********************************************************************
- INTEGRATE2:
- DEC VARIABLE_INPUT2_POINT
- MOV R7, VARIABLE_INPUT2_POINT
- CJNE R7,#1,FFI1
- MOV S5,VARIABLE_INPUT2A
- MOV S1,#0
- MOV S2,#0
- MOV S3,#0
- MOV S4,#0
- LCALL CALCULATOR_INTEGRATE
- AJMP NEXTI22
- FFI1:
- CJNE R7,#2,FFI2
- MOV S4,VARIABLE_INPUT2A
- MOV S5,VARIABLE_INPUT2B
- MOV S2,#0
- MOV S3,#0
- MOV S1,#0
- LCALL CALCULATOR_INTEGRATE
- AJMP NEXTI22
- FFI2:
- CJNE R7,#3,FFI3
- MOV S3,VARIABLE_INPUT2A
- MOV S4,VARIABLE_INPUT2B
- MOV S5,VARIABLE_INPUT2C
- MOV S1,#0
- MOV S2,#0
- LCALL CALCULATOR_INTEGRATE
- AJMP NEXTI22
- FFI3:
- MOV S2,VARIABLE_INPUT2A
- MOV S3,VARIABLE_INPUT2B
- MOV S4,VARIABLE_INPUT2C
- MOV S5,VARIABLE_INPUT2D
- MOV S1,#0
- LCALL CALCULATOR_INTEGRATE
- NEXTI22:
- MOV VARIABLE_STORE3,S6 ;将转化后的值存在S8和S9中
- MOV VARIABLE_STORE4,S7
- LCALL QL
- MOV VARIABLE_LEDBUF+0, #0FFH ; 显示管输完符号位后显示全灭
- MOV VARIABLE_LEDBUF+1, #0FFH
- MOV VARIABLE_LEDBUF+2, #0FFH
- MOV VARIABLE_LEDBUF+3, #0FFH
- MOV VARIABLE_LEDBUF_POINT,#VARIABLE_LEDBUF
- RET
- ;**********************************************计算器运算程序*****************************************************************************
- ;***********************************************计算器加法**********************************************************************************
- CALCULATOR_ADDITION:
- MOV R1,VARIABLE_STORE2 ;入口:R1(H),R0,R3(H),R2,出口:和R1(H),R0(L)
- MOV R0,VARIABLE_STORE1
- MOV R3,VARIABLE_STORE4
- MOV R2,VARIABLE_STORE3
- LCALL ADDITION
- MOV VARIABLE_STORE6,R1
- MOV VARIABLE_STORE5,R0
- MOV S7,VARIABLE_STORE6
- MOV S6,VARIABLE_STORE5
- LCALL CALCULATOR_SEPARATE
- RET
- ;*********************************************计算器减法***********************************************************************************
- CALCULATOR_SUBTRACTION:
- MOV R1,VARIABLE_STORE2
- MOV R0,VARIABLE_STORE1
- MOV R3,VARIABLE_STORE4
- MOV R2,VARIABLE_STORE3
- LCALL SUBTRACTION ;入口:减数R3(H),R2(L),被减数R1(H),R0(L),出口:差R1(H),R0(L)
- MOV VARIABLE_STORE6,R1
- MOV VARIABLE_STORE5,R0
- MOV S7,VARIABLE_STORE6
- MOV S6,VARIABLE_STORE5
- LCALL CALCULATOR_SEPARATE
- RET
- ;*********************************************计算器乘法***********************************************************************************
- CALCULATOR_MULTIPLICATION:
- MOV R1,VARIABLE_STORE2
- MOV R0,VARIABLE_STORE1
- MOV R3,VARIABLE_STORE4
- MOV R2,VARIABLE_STORE3
- LCALL MULTIPLICATION ;入口:被乘数R3,R2,乘数R1,R0,结果R7,R6,R5,R4
- MOV VARIABLE_STORE6,R5
- MOV VARIABLE_STORE5,R4
- MOV S7,VARIABLE_STORE6
- MOV S6,VARIABLE_STORE5
- LCALL CALCULATOR_SEPARATE
- RET
- ;*********************************************计算器除法***********************************************************************************
- CALCULATOR_DIVISION:
- MOV R6,VARIABLE_STORE2 ;入口:R6(H),R7(L),被除数,R4(H),R5(L),除数,出口:商R6(H),R7(L),余R4(H),R5(L
- MOV R7,VARIABLE_STORE1
- MOV R4,VARIABLE_STORE4
- MOV R5,VARIABLE_STORE3
- LCALL DIVISION
- MOV VARIABLE_STORE6,R6
- MOV VARIABLE_STORE5,R7
- MOV S7,VARIABLE_STORE6
- MOV S6,VARIABLE_STORE5
- LCALL CALCULATOR_SEPARATE
- RET
- ;*********************************************设立最后计算器显示的位数和位置***********************************************************************************
- CALCULATOR_RESULT_DESIGN: ;设立最后显示的位数
- MOV A,S1
- CJNE A,#0,H1
- MOV A,S2
- CJNE A,#0,H2
- MOV A,S3
- CJNE A,#0,H3
- MOV A,S4
- CJNE A,#0,H4
- MOV A,S5
- CJNE A,#0,H5
- RET
- H1:
- MOV VARIABLE_REPLACE_POINT,#S1 ;最后显示位置指针
- MOV VARIABLE_RESULT_POINT,#5
- RET
- H2:
- MOV VARIABLE_REPLACE_POINT,#S2
- MOV VARIABLE_RESULT_POINT,#4
- RET
- H3:
- MOV VARIABLE_REPLACE_POINT,#S3
- MOV VARIABLE_RESULT_POINT,#3
- RET
- H4:
- MOV VARIABLE_REPLACE_POINT,#S4
- MOV VARIABLE_RESULT_POINT,#2
- RET
- H5:
- MOV VARIABLE_REPLACE_POINT,#S5
- MOV VARIABLE_RESULT_POINT,#1
- RET
- ;***********************************************************显示结果送入缓冲区************************************************************
- RESULT_LEDBUF:
- MOV R7,#0
- NEXTR77:
- MOV A,R7
- CJNE A,VARIABLE_RESULT_POINT,NEXTR8 ;控制显示位数
- RET
- NEXTR8:
- INC R7
- MOV R1,VARIABLE_REPLACE_POINT ;将显示位置的数字送给A寄存器
- MOV A,@R1
- LCALL LOOK_UP_TABLE1
- INC VARIABLE_REPLACE_POINT ;显示位置后移
- MOV R0,VARIABLE_LEDBUF_POINT ;将要显示段码送给缓冲区
- MOV @R0,A
- INC VARIABLE_LEDBUF_POINT
- SJMP NEXTR77
- ;;**********************************************************数字电路整合功能***************************************************************
- CALCULATOR_INTEGRATE: ;出口参数S6,S7,入口参数,S1,S2,S3,S4,S5
- ACALL QL
- MOV R0,S1
- MOV R1,#0
- MOV DPTR, #10000
- MOV R3, DPH
- MOV R2, DPL
- ACALL MULTIPLICATION
- MOV S7, R5
- MOV S6, R4
- ACALL QL
- MOV R0,S2
- MOV R1,#0
- MOV DPTR, #1000
- MOV R3, DPH
- MOV R2,DPL
- ACALL MULTIPLICATION
- MOV A,R5
- MOV R1,A
- MOV A,R4
- MOV R0,A
- MOV R3,S7
- MOV R2,S6
- ACALL ADDITION
- MOV S7, R1
- MOV S6 ,R0
- ACALL QL
- MOV R0,S3
- MOV R1,#0
- MOV DPTR, #100
- MOV R3, DPH
- MOV R2, DPL
- ACALL MULTIPLICATION
- MOV A,R5
- MOV R1,A
- MOV A,R4
- MOV R0,A
- MOV R3,S7
- MOV R2,S6
- ACALL ADDITION
- MOV S7, R1
- MOV S6 ,R0
- ACALL QL
- MOV R0,S4
- MOV R1,#0
- MOV DPTR, #10
- MOV R3, DPH
- MOV R2, DPL
- ACALL MULTIPLICATION
- MOV A,R5
- MOV R1,A
- MOV A,R4
- MOV R0,A
- MOV R3,S7
- MOV R2,S6
- ACALL ADDITION
- MOV S7, R1
- MOV S6 ,R0
- ACALL QL
- MOV R0,S5
- MOV R1,#0
- MOV DPTR, #1
- MOV R3, DPH
- MOV R2, DPL
- ACALL MULTIPLICATION
- MOV A,R5
- MOV R1,A
- MOV A,R4
- MOV R0,A
- MOV R3,S7
- MOV R2,S6
- ACALL ADDITION
- MOV S7, R1
- MOV S6 ,R0
- RET
- ;************************************************************数字电路分离功能**************************************************************
- CALCULATOR_SEPARATE: ;入口参数S6,S7,出口参数,S1,S2,S3,S4,S5
- ACALL QL
- MOV R6,S7
- MOV R7,S6
- MOV DPTR, #10000
- MOV R4, DPH
- MOV R5, DPL
- ACALL DIVISION
- MOV S1,R7
- MOV S7,R4
- MOV S6,R5
- ACALL QL
- MOV R6,S7
- MOV R7,S6
- MOV DPTR, #1000
- MOV R4, DPH
- MOV R5, DPL
- ACALL DIVISION
- MOV S2,R7
- MOV S7,R4
- MOV S6,R5
- ACALL QL
- MOV R6,S7
- MOV R7,S6
- MOV DPTR, #100
- MOV R4, DPH
- MOV R5, DPL
- ACALL DIVISION
- MOV S3,R7
- MOV S7,R4
- MOV S6,R5
- ACALL QL
- MOV R6,S7
- MOV R7,S6
- MOV DPTR, #10
- MOV R4, DPH
- MOV R5, DPL
- ACALL DIVISION
- MOV S4,R7
- MOV S7,R4
- MOV S6,R5
- ACALL QL
- MOV R6,S7
- MOV R7,S6
- MOV DPTR, #1
- MOV R4, DPH
- MOV R5, DPL
- ACALL DIVISION
- MOV S5,R7
- RET
- ;****************************************************0—-65535之内加减乘除*******************************************************************
- ;**********************************************************加法******************************************************************************
- ADDITION: ;入口:R1(H),R0,R3(H),R2,出口:和R1(H),R0(L)
- MOV A,R0
- ADD A,R2
- MOV R0,A
- MOV A,R1
- ADDC A,R3
- MOV R1,A
- RET
- ;**********************************************************减法******************************************************************************
- SUBTRACTION: ;入口:减数R3(H),R2(L),被减数R1(H),R0(L),出口:差R1(H),R0(L)
- CLR C
- MOV A,R0
- SUBB A,R2
- MOV R0,A
- MOV A,R1
- SUBB A,R3
- MOV R1,A
- RET
- ;**********************************************************乘法******************************************************************************
- MULTIPLICATION: ;入口:被乘数R3,R2,乘数R1,R0,结果R7,R6,R5,R4
- CLR A
- MOV
- R7, A
- MOV R6, A
- MOV R5, A
- MOV R4, A
- MOV 46H, #10H
- MULLOOP1:
- CLR C
- MOV A, R4
- RLC A
- MOV R4, A
- MOV A, R5
- RLC A
- MOV R5, A
- MOV A, R6
- RLC A
- MOV R6, A
- MOV A, R7
- RLC A
- MOV R7, A
- MOV A, R0
- RLC A
- MOV R0, A
- MOV A, R1
- RLC A
- MOV R1,A
- JNC MULLOOP2
- CLR C
- MOV A, R4
- ADDC A, R2
- MOV R4, A
- MOV A, R5
- ADDC A, R3
- MOV R5, A
- MOV A, R6
- ADDC A, #00H
- MOV R6, A
- MOV A, R7
- ADDC A, #00H
- MOV R7, A
- MULLOOP2: DJNZ 46H,MULLOOP1
- RET
- ;**********************************************************除法******************************************************************************
- DIVISION: ;入口:R6(H),R7(L),被除数,R4(H),R5(L),除数,出口:商R6(H),R7(L),余R4(H),R5(L)
- UDIV:
- CLR C
- CLR A
- MOV R2,A
- MOV R3,A
- MOV B,#10H
- MOVBIT: MOV A,R7;R6、R7中数据左移一位到R2、R3中,C到R7
- RLC A
- MOV R7,A
- MOV A,R6
- RLC A
- MOV R6,A
- MOV A,R3
- RLC A
- MOV R3,A
- MOV A,R2
- RLC A
- MOV R2,A
- CLR C ;R2R3-R4R5
- MOV A,R3
- SUBB A,R5
- PUSH Acc
- MOV A,R2
- SUBB A,R4
- JBC Cy,MOVBIT0;不够减,清C继续左移
- MOV R2,A;够减,存回余数并置位C
- POP Acc
- MOV R3,A
- SETB C
- SJMP MOVBIT1
- MOVBIT0: POP Acc
- MOVBIT1: DJNZ B,MOVBIT
- MOV A,R7
- RLC A
- MOV R7,A
- MOV A,R6
- RLC A
- MOV R6,A
- MOV A,R2
- MOV R4,A
- MOV A,R3
- MOV R5,A
- RET
- ;**********************************************************寄存器清零******************************************************************************
- QL:
- MOV R0,#0
- MOV R1,#0
- MOV R2,#0
- MOV R3,#0
- MOV R4,#0
- MOV R5,#0
- MOV R6,#0
- MOV R7,#0
- RET
- ;###################################################查表源程序,入口参数A,DPTR#############################################################
- LOOK_UP_TABLE:
- MOVC A, @A+DPTR
- RET
- ;***************************************************查表程序1,入口参数A********************************************************************************
- LOOK_UP_TABLE1:
- MOV DPTR,#LEDMAP
- MOVC A, @A+DPTR
- RET
- ;###################################################初始化显示缓冲区程序###################################################################
- INIT_LEDBUF:
- MOV VARIABLE_LEDBUF+0,#0FFH
- MOV VARIABLE_LEDBUF+1,#0FFH
- MOV VARIABLE_LEDBUF+2,#0FFH
- MOV VARIABLE_LEDBUF+3,#0FFH
- MOV ROW_COLUMN,#07H
- ;###################################################变量初始化程序##########################################################################
- INIT_VARIABLE:
- MOV VARIABLE_STORE1,#0
- MOV VARIABLE_STORE2,#0
- MOV VARIABLE_STORE3,#0
- MOV VARIABLE_STORE4,#0
- MOV VARIABLE_STORE5,#0
- MOV VARIABLE_STORE6,#0
- MOV VARIABLE_INPUT1A,#0
- MOV VARIABLE_INPUT1B,#0
- MOV VARIABLE_INPUT1C,#0
- MOV VARIABLE_INPUT1D,#0
- MOV VARIABLE_INPUT2A,#0
- MOV VARIABLE_INPUT2B,#0
- MOV VARIABLE_INPUT2C,#0
- MOV
- VARIABLE_INPUT2D,#0
- MOV VARIABLE_REPLACE_POINT,#0
- ;MOV VARIABLE_RESULTB,#0
- ;MOV VARIABLE_RESULTC,#0
- ;MOV VARIABLE_RESULTD,#0
- MOV VARIABLE_SIGN1,#0
- MOV VARIABLE_SIGN2,#0
- MOV VARIABLE_INPUT1_POINT,#0
- MOV VARIABLE_INPUT2_POINT,#0
- MOV VARIABLE_RESULT_POINT,#0
- MOV VARIABLE_PLACE1_POINT,#VARIABLE_INPUT1A
- MOV VARIABLE_PLACE2_POINT,#VARIABLE_INPUT2A
- MOV VARIABLE_LEDBUF_POINT,#VARIABLE_LEDBUF
- MOV S1,#0
- MOV S2,#0
- MOV S3,#0
- MOV S4,#0
- MOV S5,#0
- MOV S6,#0
- MOV S7,#0
- SETB KEY1
- SETB KEY2
- SETB KEY3
- SETB KEY4
- RET
- ;***************************************************初始化程序******************************************************************************
- INIT:
- ACALL INIT_VARIABLE
- ACALL INIT_LEDBUF
- RET
- ;$$$$主程序区$$$$$
- STABLE:
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
51单片机的完整计算器程序.rar
(4.21 KB, 下载次数: 69)
|
|