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 0067 2040 00101 CALL send ; and send code 0068 300C 00102 MOVLW 0x0C ; Turn on display 0069 2040 00103 CALL send ; and send code 00104 006A 0008 00105 RETURN ; Done 00106 00107 ;-------------------------------------------------------------- 00104 00105 00106 ; Scan keypad ............................................. 00107 006B 300F 00108 keyin MOVLW 00F ; deselect.. 006C 0087 00109 MOVWF PORTC ; ..all rows 006D 1007 00110 BCF PORTC,0 ; select row A 006E 2030 00111 CALL onems ; wait output stable 00112 006F 1A07 00113 BTFSC PORTC,4 ; button 7? 0070 2876 00114 GOTO b8 ; no 0071 3037 00115 MOVLW '7' ; yes 0072 00B0 00116 MOVWF Char ; load key code 0073 3007 00117 MOVLW 07 ; and 0074 00C0 00118 MOVWF Kval ; key value 0075 0008 00119 RETURN 00120 0076 1A87 00121 b8 BTFSC PORTC,5 ; button 8? 0077 287D 00122 GOTO b9 ; no 0078 3038 00123 MOVLW '8' ; yes 0079 00B0 00124 MOVWF Char 007A 3008 00125 MOVLW 08 007B 00C0 00126 MOVWF Kval 007C 0008 00127 RETURN 00128 007D 1B07 00129 b9 BTFSC PORTC,6 ; button 9? 007E 2884 00130 GOTO bd ; no 007F 3039 00131 MOVLW '9' ; yes 0080 00B0 00132 MOVWF Char 0081 3009 00133 MOVLW 09 0082 00C0 00134 MOVWF Kval 0083 0008 00135 RETURN 00136 0084 1B87 00137 bd BTFSC PORTC,7 ; button /? 0085 288A 00138 GOTO rowb ; no 0086 302F 00139 MOVLW '/' ; yes 0087 00B0 00140 MOVWF Char ; store key code 0088 00B4 00141 MOVWF Oper ; store operator symbol 0089 0008 00142 RETURN 00143 008A 1407 00144 rowb BSF PORTC,0 ; select row B MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 6 LOC OBJECT CODE LINE SOURCE TEXT VALUE 008B 1087 00145 BCF PORTC,1 008C 2030 00146 CALL onems 00147 008D 1A07 00148 BTFSC PORTC,4 ; button 4? 008E 2894 00149 GOTO b5 ; no 008F 3034 00150 MOVLW '4' ; yes 0090 00B0 00151 MOVWF Char 0091 3004 00152 MOVLW 04 0092 00C0 00153 MOVWF Kval 0093 0008 00154 RETURN 00155 0094 1A87 00156 b5 BTFSC PORTC,5 ; button 5? 0095 289B 00157 GOTO b6 ; no 0096 3035 00158 MOVLW '5' ; yes 0097 00B0 00159 MOVWF Char 0098 3005 00160 MOVLW 05 0099 00C0 00161 MOVWF Kval 009A 0008 00162 RETURN 00163 009B 1B07 00164 b6 BTFSC PORTC,6 ; button 6? 009C 28A2 00165 GOTO bm ; no 009D 3036 00166 MOVLW '6' ; yes 009E 00B0 00167 MOVWF Char 009F 3006 00168 MOVLW 06 00A0 00C0 00169 MOVWF Kval 00A1 0008 00170 RETURN 00171 00A2 1B87 00172 bm BTFSC PORTC,7 ; button x? 00A3 28A8 00173 GOTO rowc ; no 00A4 3078 00174 MOVLW 'x' ; yes 00A5 00B0 00175 MOVWF Char 00A6 00B4 00176 MOVWF Oper 00A7 0008 00177 RETURN 00178 00A8 1487 00179 rowc BSF PORTC,1 ; select row C 00A9 1107 00180 BCF PORTC,2 00AA 2030 00181 CALL onems 00182 00AB 1A07 00183 BTFSC PORTC,4 ; button 1? 00AC 28B2 00184 GOTO b2 ; no 00AD 3031 00185 MOVLW '1' ; yes 00AE 00B0 00186 MOVWF Char 00AF 3001 00187 MOVLW 01 00B0 00C0 00188 MOVWF Kval 00B1 0008 00189 RETURN 00190 00B2 1A87 00191 b2 BTFSC PORTC,5 ; button 2? 00B3 28B9 00192 GOTO b3 ; no 00B4 3032 00193 MOVLW '2' ; yes 00B5 00B0 00194 MOVWF Char 00B6 3002 00195 MOVLW 02 00B7 00C0 00196 MOVWF Kval 00B8 0008 00197 RETURN MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 7 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00198 00B9 1B07 00199 b3 BTFSC PORTC,6 ; button 3? 00BA 28C0 00200 GOTO bs ; no 00BB 3033 00201 MOVLW '3' ; yes 00BC 00B0 00202 MOVWF Char 00BD 3003 00203 MOVLW 03 00BE 00C0 00204 MOVWF Kval 00BF 0008 00205 RETURN 00206 00C0 1B87 00207 bs BTFSC PORTC,7 ; button -? 00C1 28C6 00208 GOTO rowd ; no 00C2 302D 00209 MOVLW '-' ; yes 00C3 00B0 00210 MOVWF Char 00C4 00B4 00211 MOVWF Oper 00C5 0008 00212 RETURN 00213 00C6 1507 00214 rowd BSF PORTC,2 ; select row D 00C7 1187 00215 BCF PORTC,3 00C8 2030 00216 CALL onems 00217 00C9 1A07 00218 BTFSC PORTC,4 ; button C? 00CA 28CF 00219 GOTO b0 ; no 00CB 3063 00220 MOVLW 'c' ; yes 00CC 00B0 00221 MOVWF Char 00CD 00B4 00222 MOVWF Oper 00CE 0008 00223 RETURN 00224 00CF 1A87 00225 b0 BTFSC PORTC,5 ; button 0? 00D0 28D6 00226 GOTO be ; no 00D1 3030 00227 MOVLW '0' ; yes 00D2 00B0 00228 MOVWF Char 00D3 3000 00229 MOVLW 00 00D4 00C0 00230 MOVWF Kval 00D5 0008 00231 RETURN 00232 00D6 1B07 00233 be BTFSC PORTC,6 ; button =? 00D7 28DB 00234 GOTO bp ; no 00D8 303D 00235 MOVLW '=' ; yes 00D9 00B0 00236 MOVWF Char 00DA 0008 00237 RETURN 00238 00DB 1B87 00239 bp BTFSC PORTC,7 ; button +? 00DC 28E1 00240 GOTO done ; no 00DD 302B 00241 MOVLW '+' ; yes 00DE 00B0 00242 MOVWF Char 00DF 00B4 00243 MOVWF Oper 00E0 0008 00244 RETURN 00245 00E1 1587 00246 done BSF PORTC,3 ; clear last row 00E2 01B0 00247 CLRF Char ; character code = 0 00E3 0008 00248 RETURN 00249 00250 MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 8 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00251 ; Write display ........................................... 00252 00E4 0837 00253 disout MOVF Kcode,W ; Load the code 00E5 14F4 00254 BSF Select,RS ; Select data mode 00E6 2040 00255 CALL send ; and send code 00E7 0008 00256 RETURN 00257 00258 ; Process operations ...................................... 00259 00E8 0834 00260 calc MOVF Oper,W ; check for add 00E9 00B5 00261 MOVWF Temp ; load input op code 00EA 302B 00262 MOVLW '+' ; load plus code Message[305]: Using default destination of 1 (file). 00EB 02B5 00263 SUBWF Temp ; compare 00EC 1903 00264 BTFSC STATUS,Z ; and check if same 00ED 2901 00265 GOTO add ; yes, jump to op 00266 00EE 0834 00267 MOVF Oper,W ; check for subtract 00EF 00B5 00268 MOVWF Temp 00F0 302D 00269 MOVLW '-' Message[305]: Using default destination of 1 (file). 00F1 02B5 00270 SUBWF Temp 00F2 1903 00271 BTFSC STATUS,Z 00F3 2905 00272 GOTO sub 00273 00F4 0834 00274 MOVF Oper,W ; check for multiply 00F5 00B5 00275 MOVWF Temp 00F6 3078 00276 MOVLW 'x' Message[305]: Using default destination of 1 (file). 00F7 02B5 00277 SUBWF Temp 00F8 1903 00278 BTFSC STATUS,Z 00F9 2912 00279 GOTO mul 00280 00FA 0834 00281 MOVF Oper,W ; check for divide 00FB 00B5 00282 MOVWF Temp 00FC 302F 00283 MOVLW '/' Message[305]: Using default destination of 1 (file). 00FD 02B5 00284 SUBWF Temp 00FE 1903 00285 BTFSC STATUS,Z 00FF 2918 00286 GOTO div 0100 2813 00287 GOTO scan ; rescan if key invalid 00288 00289 00290 ; Calclate results from 2 input numbers ................... 00291 0101 0831 00292 add MOVF Num1,W ; get first number 0102 0732 00293 ADDWF Num2,W ; add second 0103 00B3 00294 MOVWF Result ; and store result 0104 292F 00295 GOTO outres ; display result 00296 00297 0105 1403 00298 sub BSF STATUS,C ; Negative detect flag 0106 0832 00299 MOVF Num2,W ; get first number MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 9 LOC OBJECT CODE LINE SOURCE TEXT VALUE 0107 0231 00300 SUBWF Num1,W ; subtract second 0108 00B3 00301 MOVWF Result ; and store result 00302 0109 1C03 00303 BTFSS STATUS,C ; answer negative? 010A 290C 00304 GOTO minus ; yes, minus result 010B 292F 00305 GOTO outres ; display result 00306 010C 302D 00307 minus MOVLW '-' ; load minus sign 010D 14F4 00308 BSF Select,RS ; Select data mode 010E 2040 00309 CALL send ; and send symbol 00310 Message[305]: Using default destination of 1 (file). 010F 09B3 00311 COMF Result ; invert all bits Message[305]: Using default destination of 1 (file). 0110 0AB3 00312 INCF Result ; add 1 0111 292F 00313 GOTO outres ; display result 00314 00315 0112 0831 00316 mul MOVF Num1,W ; get first number 0113 01B3 00317 CLRF Result ; total to Z Message[305]: Using default destination of 1 (file). 0114 07B3 00318 add1 ADDWF Result ; add to total Message[305]: Using default destination of 1 (file). 0115 0BB2 00319 DECFSZ Num2 ; num2 times and 0116 2914 00320 GOTO add1 ; repeat if not done 0117 292F 00321 GOTO outres ; done, display result 00322 00323 0118 01B3 00324 div CLRF Result ; total to Z 0119 0832 00325 MOVF Num2,W ; get divisor 011A 1003 00326 BCF STATUS,C ; set C flag Message[305]: Using default destination of 1 (file). 011B 0AB3 00327 sub1 INCF Result ; count loop start Message[305]: Using default destination of 1 (file). 011C 02B1 00328 SUBWF Num1 ; subtract 011D 1D03 00329 BTFSS STATUS,Z ; exact answer? 011E 2920 00330 GOTO neg ; no 011F 292F 00331 GOTO outres ; yes, display answer 0120 1803 00332 neg BTFSC STATUS,C ; gone negative? 0121 291B 00333 GOTO sub1 ; no - repeat Message[305]: Using default destination of 1 (file). 0122 03B3 00334 DECF Result ; correct the result 0123 0832 00335 MOVF Num2,W ; get divisor Message[305]: Using default destination of 1 (file). 0124 07B1 00336 ADDWF Num1 ; calc remainder 00337 0125 0833 00338 MOVF Result,W ; load result 0126 3E30 00339 ADDLW 030 ; convert to ASCII 0127 14F4 00340 BSF Select,RS ; Select data mode 0128 2040 00341 CALL send ; and send result 00342 0129 3072 00343 MOVLW 'r' ; indicate remainder 012A 2040 00344 CALL send MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 10 LOC OBJECT CODE LINE SOURCE TEXT VALUE 012B 0831 00345 MOVF Num1,W 012C 3E30 00346 ADDLW 030 ; convert to ASCII 012D 2040 00347 CALL send 012E 2813 00348 GOTO scan 00349 00350 00351 ; Convert binary to BCD ................................... 00352 012F 0833 00353 outres MOVF Result,W ; load result 0130 00B9 00354 MOVWF Lsd ; into low digit store 0131 01B8 00355 CLRF Msd ; high digit = 0 0132 1403 00356 BSF STATUS,C ; set C flag 0133 300A 00357 MOVLW D'10' ; load 10 00358 Message[305]: Using default destination of 1 (file). 0134 02B9 00359 again SUBWF Lsd ; sub 10 from result Message[305]: Using default destination of 1 (file). 0135 0AB8 00360 INCF Msd ; inc high digit 0136 1803 00361 BTFSC STATUS,C ; check if negative 0137 2934 00362 GOTO again ; no, keep going Message[305]: Using default destination of 1 (file). 0138 07B9 00363 ADDWF Lsd ; yes, add 10 back Message[305]: Using default destination of 1 (file). 0139 03B8 00364 DECF Msd ; inc high digit 00365 00366 00367 ; display 2 digit BCD result .............................. 00368 013A 0838 00369 MOVF Msd,W ; load high digit result 013B 1903 00370 BTFSC STATUS,Z ; check if Z 013C 2940 00371 GOTO lowd ; yes, dont display Msd 00372 013D 3E30 00373 ADDLW 030 ; convert to ASCII 013E 14F4 00374 BSF Select,RS ; Select data mode 013F 2040 00375 CALL send ; and send Msd 00376 0140 0839 00377 lowd MOVF Lsd,W ; load low digit result 0141 3E30 00378 ADDLW 030 ; convert to ASCII 0142 14F4 00379 BSF Select,RS ; Select data mode 0143 2040 00380 CALL send ; and send Msd 00381 0144 2813 00382 GOTO scan ; scan for clear key 00383 00384 00385 ; Restart ................................................ 00386 0145 3001 00387 clear MOVLW 01 ; code to clear display 0146 10F4 00388 BCF Select,RS ; Select data mode 0147 2040 00389 CALL send ; and send code 0148 01B6 00390 CLRF Kcount ; reset count of keys 0149 2813 00391 GOTO scan ; and rescan keypad 00392 00393 MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 11 LOC OBJECT CODE LINE SOURCE TEXT VALUE 00394 END ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 12 SYMBOL TABLE LABEL VALUE ACKDT 00000005 ACKEN 00000004 ACKSTAT 00000006 ADCON0 0000001F ADCON1 0000009F ADCS0 00000006 ADCS1 00000007 ADDEN 00000003 ADFM 00000007 ADIE 00000006 ADIF 00000006 ADON 00000000 ADRESH 0000001E ADRESL 0000009E BCLIE 00000003 BCLIF 00000003 BF 00000000 BRGH 00000002 C 00000000 C1INV 00000004 C1OUT 00000006 C2INV 00000005 C2OUT 00000007 CCP1CON 00000017 CCP1IE 00000002 CCP1IF 00000002 CCP1M0 00000000 CCP1M1 00000001 CCP1M2 00000002 CCP1M3 00000003 CCP1X 00000005 CCP1Y 00000004 CCP2CON 0000001D CCP2IE 00000000 CCP2IF 00000000 CCP2M0 00000000 CCP2M1 00000001 CCP2M2 00000002 CCP2M3 00000003 CCP2X 00000005 CCP2Y 00000004 CCPR1H 00000016 CCPR1L 00000015 CCPR2H 0000001C CCPR2L 0000001B CHS0 00000003 CHS1 00000004 CHS2 00000005 CIS 00000003 CKE 00000006 CKP 00000004 CM0 00000000 CM1 00000001 MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 13 SYMBOL TABLE LABEL VALUE CM2 00000002 CMCON 0000009C CMIE 00000006 CMIF 00000006 CREN 00000004 CSRC 00000007 CVR0 00000000 CVR1 00000001 CVR2 00000002 CVR3 00000003 CVRCON 0000009D CVREN 00000007 CVROE 00000006 CVRR 00000005 Char 00000030 D 00000005 DATA_ADDRESS 00000005 DC 00000001 D_A 00000005 E 00000002 EEADR 0000010D EEADRH 0000010F EECON1 0000018C EECON2 0000018D EEDATA 0000010C EEDATH 0000010E EEIE 00000004 EEIF 00000004 EEPGD 00000007 F 00000001 FERR 00000002 FSR 00000004 GCEN 00000007 GIE 00000007 GO 00000002 GO_DONE 00000002 I2C_DATA 00000005 I2C_READ 00000002 I2C_START 00000003 I2C_STOP 00000004 IBF 00000007 IBOV 00000005 INDF 00000000 INTCON 0000000B INTE 00000004 INTEDG 00000006 INTF 00000001 IRP 00000007 Kcode 00000037 Kcount 00000036 Kval 00000040 Lsd 00000039 Msd 00000038 MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 14 SYMBOL TABLE LABEL VALUE NOT_A 00000005 NOT_ADDRESS 00000005 NOT_BO 00000000 NOT_BOR 00000000 NOT_DONE 00000002 NOT_PD 00000003 NOT_POR 00000001 NOT_RBPU 00000007 NOT_RC8 00000006 NOT_T1SYNC 00000002 NOT_TO 00000004 NOT_TX8 00000006 NOT_W 00000002 NOT_WRITE 00000002 Num1 00000031 Num2 00000032 OBF 00000006 OERR 00000001 OPTION_REG 00000081 Oper 00000034 OutCod 00000075 P 00000004 PCFG0 00000000 PCFG1 00000001 PCFG2 00000002 PCFG3 00000003 PCL 00000002 PCLATH 0000000A PCON 0000008E PEIE 00000006 PEN 00000002 PIE1 0000008C PIE2 0000008D PIR1 0000000C PIR2 0000000D PORTA 00000005 PORTB 00000006 PORTC 00000007 PORTD 00000008 PORTE 00000009 PR2 00000092 PS0 00000000 PS1 00000001 PS2 00000002 PSA 00000003 PSPIE 00000007 PSPIF 00000007 PSPMODE 00000004 Point 00000073 R 00000002 RBIE 00000003 RBIF 00000000 RC8_9 00000006 MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 15 SYMBOL TABLE LABEL VALUE RC9 00000006 RCD8 00000000 RCEN 00000003 RCIE 00000005 RCIF 00000005 RCREG 0000001A RCSTA 00000018 RD 00000000 READ_WRITE 00000002 RP0 00000005 RP1 00000006 RS 00000001 RSEN 00000001 RX9 00000006 RX9D 00000000 R_W 00000002 Result 00000033 S 00000003 SEN 00000000 SMP 00000007 SPBRG 00000099 SPEN 00000007 SREN 00000005 SSPADD 00000093 SSPBUF 00000013 SSPCON 00000014 SSPCON2 00000091 SSPEN 00000005 SSPIE 00000003 SSPIF 00000003 SSPM0 00000000 SSPM1 00000001 SSPM2 00000002 SSPM3 00000003 SSPOV 00000006 SSPSTAT 00000094 STATUS 00000003 SYNC 00000004 Select 00000074 T0CS 00000005 T0IE 00000005 T0IF 00000002 T0SE 00000004 T1CKPS0 00000004 T1CKPS1 00000005 T1CON 00000010 T1INSYNC 00000002 T1OSCEN 00000003 T1SYNC 00000002 T2CKPS0 00000000 T2CKPS1 00000001 T2CON 00000012 TMR0 00000001 MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 16 SYMBOL TABLE LABEL VALUE TMR0IE 00000005 TMR0IF 00000002 TMR1CS 00000001 TMR1H 0000000F TMR1IE 00000000 TMR1IF 00000000 TMR1L 0000000E TMR1ON 00000000 TMR2 00000011 TMR2IE 00000001 TMR2IF 00000001 TMR2ON 00000002 TOUTPS0 00000003 TOUTPS1 00000004 TOUTPS2 00000005 TOUTPS3 00000006 TRISA 00000085 TRISB 00000086 TRISC 00000087 TRISD 00000088 TRISE 00000089 TRISE0 00000000 TRISE1 00000001 TRISE2 00000002 TRMT 00000001 TX8_9 00000006 TX9 00000006 TX9D 00000000 TXD8 00000000 TXEN 00000005 TXIE 00000004 TXIF 00000004 TXREG 00000019 TXSTA 00000098 Temp 00000035 Timer1 00000070 TimerX 00000071 UA 00000001 Var 00000072 W 00000000 WCOL 00000007 WR 00000001 WREN 00000002 WRERR 00000003 Z 00000002 _BODEN_OFF 00003FBF _BODEN_ON 00003FFF _CPD_OFF 00003FFF _CPD_ON 00003EFF _CP_ALL 00001FFF _CP_OFF 00003FFF _DEBUG_OFF 00003FFF _DEBUG_ON 000037FF MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 17 SYMBOL TABLE LABEL VALUE _HS_OSC 00003FFE _LP_OSC 00003FFC _LVP_OFF 00003F7F _LVP_ON 00003FFF _PWRTE_OFF 00003FFF _PWRTE_ON 00003FF7 _RC_OSC 00003FFF _WDT_OFF 00003FFB _WDT_ON 00003FFF _WRT_1FOURTH 00003BFF _WRT_256 00003DFF _WRT_HALF 000039FF _WRT_OFF 00003FFF _XT_OSC 00003FFD __16F877 00000001 add 00000101 add1 00000114 again 00000134 b0 000000CF b2 000000B2 b3 000000B9 b5 00000094 b6 0000009B b8 00000076 b9 0000007D bd 00000084 be 000000D6 bm 000000A2 bp 000000DB bs 000000C0 calc 000000E8 clear 00000145 disout 000000E4 div 00000118 done 000000E1 first 0000002A inid 00000050 keyin 0000006B keyon 00000018 loop1 00000032 loopX 00000037 lowd 00000140 minus 0000010C mul 00000112 neg 00000120 onems 00000030 outres 0000012F pulseE 0000003B rowb 0000008A rowc 000000A8 rowd 000000C6 scan 00000013 second 0000002D MPASM 03.70.01 Released CALC.ASM 3-7-2006 14:36:19 PAGE 18 SYMBOL TABLE LABEL VALUE send 00000040 start 0000000C sub 00000105 sub1 0000011B wait 0000001C xms 00000036 MEMORY USAGE MAP ('X' = Used, '-' = Unused) 0000 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0080 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 00C0 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0100 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX 0140 : XXXXXXXXXX------ ---------------- ---------------- ---------------- 2000 : -------X-------- ---------------- ---------------- ---------------- All other memory blocks unused. Program Memory Words Used: 330 Program Memory Words Free: 7862 Errors : 0 Warnings : 3 reported, 0 suppressed Messages : 24 reported, 0 suppressed