📄 timin.lst
字号:
MPASM 03.70.01 Released TIMIN.ASM 3-27-2006 15:47:27 PAGE 1
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00002 ;
00003 ; TIMIN.ASM MPB 25-8-05
00004 ;
00005 ; Measure input period using Timer1 16-bit capture
00006 ; and display in microseconds
00007 ;
00008 ; STATUS: Capture working
00009 ; Conversion working
00010 ; Display in progress
00011 ;
00012 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00013
00014 PROCESSOR 16F877A
00015
00016 ; Clock = XT 4MHz, standard fuse settings:
00017
2007 3731 00018 __CONFIG 0x3731
00019
00020 ; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00021
00022 INCLUDE "P16F877A.INC" ; Standard register labels
00001 LIST
00002 ; P16F877A.INC Standard Header File, Version 1.00 Microchip Technology, Inc.
00398 LIST
00023
00024 ; Local label equates.....................................
00025
00000020 00026 Hibyte EQU 020
00000021 00027 Lobyte EQU 021
00028
00000022 00029 Tents EQU 022
00000023 00030 Thous EQU 023
00000024 00031 Hunds EQU 024
00000025 00032 Tens EQU 025
00000026 00033 Ones EQU 026
00034
00035
00036 ; Program begins ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00037
0000 00038 ORG 0 ; Place machine code
0000 0000 00039 NOP ; Required for ICD mode
0001 2805 00040 GOTO init
00041
0004 00042 ORG 4 ; Interrupt vector adress
0004 2814 00043 GOTO ISR ; jump to service routine
00044
0005 0000 00045 init NOP
0006 1683 1303 00046 BANKSEL TRISD ; Select bank 1
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0008 0188 00047 CLRF TRISD ; Initialise display port
Message[302]: Register in operand not in bank 0. Ensure that bank bits are correct.
0009 018C 00048 CLRF PIE1 ; Disable peripheral interrupts
MPASM 03.70.01 Released TIMIN.ASM 3-27-2006 15:47:27 PAGE 2
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00049
000A 1283 1303 00050 BANKSEL PORTD ; Select bank 0
000C 0188 00051 CLRF PORTD ; Clear display outputs
00052
000D 30C0 00053 MOVLW B'11000000' ; Enable..
000E 008B 00054 MOVWF INTCON ; ..peripheral interrupts
000F 3004 00055 MOVLW B'00000100' ; Capture mode:
0010 0097 00056 MOVWF CCP1CON ; ..every falling edge
0011 3001 00057 MOVLW B'00000001' ; Enable..
0012 0090 00058 MOVWF T1CON ; ..Timer 1
00059
0013 28E6 00060 GOTO start ; Jump to main program
00061
00062 ; INTERRUPT SERVICE ROUTINE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00063
0014 018E 00064 ISR CLRF TMR1L
0015 018F 00065 CLRF TMR1H
0016 110C 00066 BCF PIR1,CCP1IF ; Reset interrupt flag
0017 0009 00067 RETFIE
00068
00069 ; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
00070
00071 INCLUDE "LCDIS.INC" ; Include display routines
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 ;--------------------------------------------------------------
0018 30F9 00024 onems MOVLW D'249' ; Count for 1ms delay
0019 00F0 00025 MOVWF Timer1 ; Load count
001A 0000 00026 loop1 NOP ; Pad for 4 cycle loop
Message[305]: Using default destination of 1 (file).
001B 0BF0 00027 DECFSZ Timer1 ; Count
001C 281A 00028 GOTO loop1 ; until Z
001D 0008 00029 RETURN ; and finish
MPASM 03.70.01 Released TIMIN.ASM 3-27-2006 15:47:27 PAGE 3
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00030
00031 ;--------------------------------------------------------------
00032 ; Delay Xms
00033 ; Receives count in W, uses Onems
00034 ;--------------------------------------------------------------
001E 00F1 00035 xms MOVWF TimerX ; Count for X ms
001F 2018 00036 loopX CALL onems ; Delay 1ms
Message[305]: Using default destination of 1 (file).
0020 0BF1 00037 DECFSZ TimerX ; Repeat X times
0021 281F 00038 GOTO loopX ; until Z
0022 0008 00039 RETURN ; and finish
00040
00041 ;--------------------------------------------------------------
00042 ; Generate data/command clock siganl E
00043 ;--------------------------------------------------------------
0023 1508 00044 pulseE BSF PORTD,E ; Set E high
0024 2018 00045 CALL onems ; Delay 1ms
0025 1108 00046 BCF PORTD,E ; Reset E low
0026 2018 00047 CALL onems ; Delay 1ms
0027 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 ;--------------------------------------------------------------
0028 00F5 00054 send MOVWF OutCod ; Store output code
0029 39F0 00055 ANDLW 0F0 ; Clear low nybble
002A 0088 00056 MOVWF PORTD ; Output high nybble
002B 18F4 00057 BTFSC Select,RS ; Test RS bit
002C 1488 00058 BSF PORTD,RS ; and set for data
002D 2023 00059 CALL pulseE ; and clock display register
002E 2018 00060 CALL onems ; wait 1ms for display
00061
Message[305]: Using default destination of 1 (file).
002F 0EF5 00062 SWAPF OutCod ; Swap low and high nybbles
0030 0875 00063 MOVF OutCod,W ; Retrieve output code
0031 39F0 00064 ANDLW 0F0 ; Clear low nybble
0032 0088 00065 MOVWF PORTD ; Output low nybble
0033 18F4 00066 BTFSC Select,RS ; Test RS bit
0034 1488 00067 BSF PORTD,RS ; and set for data
0035 2023 00068 CALL pulseE ; and clock display register
0036 2018 00069 CALL onems ; wait 1ms for display
0037 0008 00070 RETURN ; done
00071
00072 ;--------------------------------------------------------------
00073 ; Initialise the display
00074 ; Uses Send
00075 ;--------------------------------------------------------------
0038 3064 00076 inid MOVLW D'100' ; Load count for 100ms delay
0039 201E 00077 CALL xms ; and wait for display start
003A 30F0 00078 MOVLW 0F0 ; Mask for select code
003B 00F4 00079 MOVWF Select ; High nybble not masked
00080
MPASM 03.70.01 Released TIMIN.ASM 3-27-2006 15:47:27 PAGE 4
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
003C 3030 00081 MOVLW 0x30 ; Load initial nibble
003D 0088 00082 MOVWF PORTD ; and output it to display
003E 2023 00083 CALL pulseE ; Latch initial code
003F 3005 00084 MOVLW D'5' ; Set delay 5ms
0040 201E 00085 CALL xms ; and wait
0041 2023 00086 CALL pulseE ; Latch initial code again
0042 2018 00087 CALL onems ; Wait 1ms
0043 2023 00088 CALL pulseE ; Latch initial code again
0044 1208 00089 BCF PORTD,4 ; Set 4-bit mode
0045 2023 00090 CALL pulseE ; Latch it
00091
0046 3028 00092 MOVLW 0x28 ; Set 4-bit mode, 2 lines
0047 2028 00093 CALL send ; and send code
0048 3008 00094 MOVLW 0x08 ; Switch off display
0049 2028 00095 CALL send ; and send code
004A 3001 00096 MOVLW 0x01 ; Code to clear display
004B 2028 00097 CALL send ; and send code
004C 3006 00098 MOVLW 0x06 ; Enable cursor auto inc
004D 2028 00099 CALL send ; and send code
004E 3080 00100 MOVLW 0x80 ; Zero display address
004F 2028 00101 CALL send ; and send code
0050 300C 00102 MOVLW 0x0C ; Turn on display
0051 2028 00103 CALL send ; and send code
00104
0052 0008 00105 RETURN ; Done
00106
00107 ;--------------------------------------------------------------
00072
00073 ;----------------------------------------------------------------
00074 ; Convert 16 bit binary result to 5 digits
00075 ;----------------------------------------------------------------
00076
0053 0815 00077 conv MOVF CCPR1L,W ; Get high byte
0054 00A1 00078 MOVWF Lobyte ; and store
0055 0816 00079 MOVF CCPR1H,W ; Get low byte
0056 00A0 00080 MOVWF Hibyte ; and store
00081
0057 3006 00082 MOVLW 06 ; Correction value
0058 1003 00083 BCF STATUS,C ; prepare carry flag
Message[305]: Using default destination of 1 (file).
0059 07A1 00084 ADDWF Lobyte ; add correction
005A 1803 00085 BTFSC STATUS,C ; and carry
Message[305]: Using default destination of 1 (file).
005B 0AA0 00086 INCF Hibyte ; in required
00087
005C 01A2 00088 CLRF Tents ; clear ten thousands register
005D 01A3 00089 CLRF Thous ; clear thousands register
005E 01A4 00090 CLRF Hunds ; clear hundreds register
005F 01A5 00091 CLRF Tens ; clear tens register
0060 01A6 00092 CLRF Ones ; clear ones register
00093
00094 ; Subtract 10000d (2710h) and count ...........................
00095
MPASM 03.70.01 Released TIMIN.ASM 3-27-2006 15:47:27 PAGE 5
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
0061 3010 00096 sub10 MOVLW 010 ; get low byte to sub
0062 1403 00097 BSF STATUS,C ; get ready to subtract
Message[305]: Using default destination of 1 (file).
0063 02A1 00098 SUBWF Lobyte ; sub 10h from low byte
0064 1803 00099 BTFSC STATUS,C ; borrow required?
0065 286E 00100 GOTO sub27 ; no - sub high byte
00101
0066 08A0 00102 MOVF Hibyte,F ; yes - check high byte
0067 1D03 00103 BTFSS STATUS,Z ; zero?
0068 286D 00104 GOTO take1 ; no - take borrow
00105
0069 3010 00106 MOVLW 010 ; yes - load low byte to add
006A 1003 00107 BCF STATUS,C ; get ready to add
Message[305]: Using default destination of 1 (file).
006B 07A1 00108 ADDWF Lobyte ; restore low byte
006C 287C 00109 GOTO subE8 ; next digit
00110
Message[305]: Using default destination of 1 (file).
006D 03A0 00111 take1 DECF Hibyte ; take borrow
00112
006E 3027 00113 sub27 MOVLW 027 ; get high byte to sub
006F 1403 00114 BSF STATUS,C ; get ready to subtract
Message[305]: Using default destination of 1 (file).
0070 02A0 00115 SUBWF Hibyte ; sub from high byte
0071 1C03 00116 BTFSS STATUS,C ; borrow taken?
0072 2875 00117 GOTO done1 ; yes - restore remainder
Message[305]: Using default destination of 1 (file).
0073 0AA2 00118 INCF Tents ; no - count ten thousand
0074 2861 00119 GOTO sub10 ; sub 10000 again
00120
0075 3010 00121 done1 MOVLW 010 ; restore..
0076 1003 00122 BCF STATUS,C ; get ready to add
Message[305]: Using default destination of 1 (file).
0077 07A1 00123 ADDWF Lobyte ; restore low byte
0078 1803 00124 BTFSC STATUS,C ; Carry into high byte?
Message[305]: Using default destination of 1 (file).
0079 0AA0 00125 INCF Hibyte ; yes - add carry to high byte
007A 3027 00126 MOVLW 027 ; restore..
Message[305]: Using default destination of 1 (file).
007B 07A0 00127 ADDWF Hibyte ; ..high byte
00128
00129
00130 ; Subtract 1000d (03E8) and count.................................
00131
007C 30E8 00132 subE8 MOVLW 0E8 ; get low byte to sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -