📄 calc.lst
字号:
MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 1
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00002 ;
00003 ; CALC.ASM MPB Ver 1.0 28-8-05
00004 ;
00005 ; Simple calculator
00006 ; Single digit input, two digit results
00007 ; Integer handling only
00008 ;
00009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00010
00011 PROCESSOR 16F877
00012 ; Clock = XT 4MHz, standard fuse settings
2007 3731 00013 __CONFIG 0x3731
00014
00015 ; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00016
00017 INCLUDE "P16F877A.INC"
00001 LIST
00002 ; P16F877A.INC Standard Header File, Version 1.00 Microchip Technology, Inc.
Message[301]: MESSAGE: (Processor-header file mismatch. Verify selected processor.)
00398 LIST
00018
00019
00000030 00020 Char EQU 30 ; Display character code
00000031 00021 Num1 EQU 31 ; First number input
00000032 00022 Num2 EQU 32 ; Second number input
00000033 00023 Result EQU 33 ; Calculated result
00000034 00024 Oper EQU 34 ; Operation code store
00000035 00025 Temp EQU 35 ; Temporary register for subtract
00000036 00026 Kcount EQU 36 ; Count of keys hit
00000037 00027 Kcode EQU 37 ; ASCII code for key
00000038 00028 Msd EQU 38 ; Most significant digit of result
00000039 00029 Lsd EQU 39 ; Least significant digit of result
00000040 00030 Kval EQU 40 ; Key numerical value
00031
00000001 00032 RS EQU 1 ; Register select output bit
00000002 00033 E EQU 2 ; Display data strobe
00034
00035 ; Program begins ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00036
0000 00037 ORG 0 ; Default start address
0000 0000 00038 NOP ; required for ICD mode
00039
0001 1683 1303 00040 BANKSEL TRISC ; Select bank 1
0003 30F0 00041 MOVLW B'11110000' ; Keypad direction code
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0004 0087 00042 MOVWF TRISC ;
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0005 0188 00043 CLRF TRISD ; Display port is output
00044
0006 1283 1303 00045 BANKSEL PORTC ; Select bank 0
0008 30FF 00046 MOVLW 0FF ;
0009 0087 00047 MOVWF PORTC ; Set keypad outputs high
MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 2
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
000A 0188 00048 CLRF PORTD ; Clear display outputs
000B 280C 00049 GOTO start ; Jump to main program
00050
00051
00052 ; MAIN LOOP ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00053
000C 2050 00054 start CALL inid ; Initialise the display
000D 3080 00055 MOVLW 0x80 ; position to home cursor
000E 10F4 00056 BCF Select,RS ; Select command mode
000F 2040 00057 CALL send ; and send code
00058
Warning[211]: Extraneous arguments on the line.
0010 0103 00059 CLRW Char ; ASCII = 0
Warning[211]: Extraneous arguments on the line.
0011 0103 00060 CLRW Kval ; Key value = 0
Warning[211]: Extraneous arguments on the line.
0012 0103 00061 CLRW DFlag ; Digit flags = 0
00062
0013 206B 00063 scan CALL keyin ; Scan keypad
0014 08B0 00064 MOVF Char,1 ; test character code
0015 1D03 00065 BTFSS STATUS,Z ; key pressed?
0016 2818 00066 GOTO keyon ; yes - wait for release
0017 2813 00067 GOTO scan ; no - scan again
00068
0018 0830 00069 keyon MOVF Char,W ; Copy..
0019 00B7 00070 MOVWF Kcode ; ..ASCIIcode
001A 3032 00071 MOVLW D'50' ; delay for..
001B 2036 00072 CALL xms ; ..50ms debounce
00073
001C 206B 00074 wait CALL keyin ; scan keypad again
001D 08B0 00075 MOVF Char,1 ; test character code
001E 1D03 00076 BTFSS STATUS,Z ; key pressed?
001F 281C 00077 GOTO wait ; no - rescan
0020 20E4 00078 CALL disout ; yes - show symbol
00079
Message[305]: Using default destination of 1 (file).
0021 0AB6 00080 INCF Kcount ; inc count..
0022 0836 00081 MOVF Kcount,W ; ..of keys pressed
Message[305]: Using default destination of 1 (file).
0023 0782 00082 ADDWF PCL ; jump into table
0024 0000 00083 NOP
0025 282A 00084 GOTO first ; process first key
0026 2813 00085 GOTO scan ; get operation key
0027 282D 00086 GOTO second ; process second symbol
0028 28E8 00087 GOTO calc ; calculate result
0029 2945 00088 GOTO clear ; clear display
00089
002A 0840 00090 first MOVF Kval,W ; store..
002B 00B1 00091 MOVWF Num1 ; first num
002C 2813 00092 GOTO scan ; and get op key
00093
002D 0840 00094 second MOVF Kval,W ; store..
002E 00B2 00095 MOVWF Num2 ; second number
MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 3
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
002F 2813 00096 GOTO scan ; and get equals key
00097
00098
00099 ; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00100
00101 ; Include LCD driver routine
00102
00103 INCLUDE "LCDIS.INC"
00001 ;--------------------------------------------------------------
00002 ; LCDIS.INC MPB 19-12-05
00003 ;
00004 ; Include file to operate 16x2 LCD display
00005 ; Uses GPR 70 - 75
00006 ;
00007 ; Final version
00008 ;--------------------------------------------------------------
00009
00000070 00010 Timer1 EQU 70 ; 1ms count register
00000071 00011 TimerX EQU 71 ; Xms count register
00000072 00012 Var EQU 72 ; Output variable
00000073 00013 Point EQU 73 ; Program table pointer
00000074 00014 Select EQU 74 ; Used to set or clear RS bit
00000075 00015 OutCod EQU 75 ; Temp store for output code
00016
00000001 00017 RS EQU 1 ; Register select output bit
00000002 00018 E EQU 2 ; Enable display input
00019
00020
00021 ;--------------------------------------------------------------
00022 ; 1ms delay with 1us cycle time (1000 cycles)
00023 ;--------------------------------------------------------------
0030 30F9 00024 onems MOVLW D'249' ; Count for 1ms delay
0031 00F0 00025 MOVWF Timer1 ; Load count
0032 0000 00026 loop1 NOP ; Pad for 4 cycle loop
Message[305]: Using default destination of 1 (file).
0033 0BF0 00027 DECFSZ Timer1 ; Count
0034 2832 00028 GOTO loop1 ; until Z
0035 0008 00029 RETURN ; and finish
00030
00031 ;--------------------------------------------------------------
00032 ; Delay Xms
00033 ; Receives count in W, uses Onems
00034 ;--------------------------------------------------------------
0036 00F1 00035 xms MOVWF TimerX ; Count for X ms
0037 2030 00036 loopX CALL onems ; Delay 1ms
Message[305]: Using default destination of 1 (file).
0038 0BF1 00037 DECFSZ TimerX ; Repeat X times
0039 2837 00038 GOTO loopX ; until Z
003A 0008 00039 RETURN ; and finish
00040
00041 ;--------------------------------------------------------------
00042 ; Generate data/command clock siganl E
00043 ;--------------------------------------------------------------
MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 4
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
003B 1508 00044 pulseE BSF PORTD,E ; Set E high
003C 2030 00045 CALL onems ; Delay 1ms
003D 1108 00046 BCF PORTD,E ; Reset E low
003E 2030 00047 CALL onems ; Delay 1ms
003F 0008 00048 RETURN ; done
00049
00050 ;--------------------------------------------------------------
00051 ; Send a command byte in two nibbles from RB4 - RB7
00052 ; Receives command in W, uses PulseE and Onems
00053 ;--------------------------------------------------------------
0040 00F5 00054 send MOVWF OutCod ; Store output code
0041 39F0 00055 ANDLW 0F0 ; Clear low nybble
0042 0088 00056 MOVWF PORTD ; Output high nybble
0043 18F4 00057 BTFSC Select,RS ; Test RS bit
0044 1488 00058 BSF PORTD,RS ; and set for data
0045 203B 00059 CALL pulseE ; and clock display register
0046 2030 00060 CALL onems ; wait 1ms for display
00061
Message[305]: Using default destination of 1 (file).
0047 0EF5 00062 SWAPF OutCod ; Swap low and high nybbles
0048 0875 00063 MOVF OutCod,W ; Retrieve output code
0049 39F0 00064 ANDLW 0F0 ; Clear low nybble
004A 0088 00065 MOVWF PORTD ; Output low nybble
004B 18F4 00066 BTFSC Select,RS ; Test RS bit
004C 1488 00067 BSF PORTD,RS ; and set for data
004D 203B 00068 CALL pulseE ; and clock display register
004E 2030 00069 CALL onems ; wait 1ms for display
004F 0008 00070 RETURN ; done
00071
00072 ;--------------------------------------------------------------
00073 ; Initialise the display
00074 ; Uses Send
00075 ;--------------------------------------------------------------
0050 3064 00076 inid MOVLW D'100' ; Load count for 100ms delay
0051 2036 00077 CALL xms ; and wait for display start
0052 30F0 00078 MOVLW 0F0 ; Mask for select code
0053 00F4 00079 MOVWF Select ; High nybble not masked
00080
0054 3030 00081 MOVLW 0x30 ; Load initial nibble
0055 0088 00082 MOVWF PORTD ; and output it to display
0056 203B 00083 CALL pulseE ; Latch initial code
0057 3005 00084 MOVLW D'5' ; Set delay 5ms
0058 2036 00085 CALL xms ; and wait
0059 203B 00086 CALL pulseE ; Latch initial code again
005A 2030 00087 CALL onems ; Wait 1ms
005B 203B 00088 CALL pulseE ; Latch initial code again
005C 1208 00089 BCF PORTD,4 ; Set 4-bit mode
005D 203B 00090 CALL pulseE ; Latch it
00091
005E 3028 00092 MOVLW 0x28 ; Set 4-bit mode, 2 lines
005F 2040 00093 CALL send ; and send code
0060 3008 00094 MOVLW 0x08 ; Switch off display
0061 2040 00095 CALL send ; and send code
MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 5
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
0062 3001 00096 MOVLW 0x01 ; Code to clear display
0063 2040 00097 CALL send ; and send code
0064 3006 00098 MOVLW 0x06 ; Enable cursor auto inc
0065 2040 00099 CALL send ; and send code
0066 3080 00100 MOVLW 0x80 ; Zero display address
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -