📄 timin.sdi
字号:
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,; TIMIN.ASM MPB 25-8-05
,,,;
,,,; Measure input period using Timer1 16-bit capture
,,,; and display in microseconds
,,,;
,,,; STATUS: Capture working
,,,; Conversion working
,,,; Display in progress
,,,;
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,, PROCESSOR 16F877A
,,,
,,,; Clock = XT 4MHz, standard fuse settings:
,,,
00002007,3731,, __CONFIG 0x3731
,,,
,,,; LABEL EQUATES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,, INCLUDE "P16F877A.INC" ; Standard register labels
,,,
,,,; Local label equates.....................................
,,,
,,,Hibyte EQU 020
,,,Lobyte EQU 021
,,,
,,,Tents EQU 022
,,,Thous EQU 023
,,,Hunds EQU 024
,,,Tens EQU 025
,,,Ones EQU 026
,,,
,,,
,,,; Program begins ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,, ORG 0 ; Place machine code
00000000,0000,, NOP ; Required for ICD mode
00000001,2805,, GOTO init
,,,
,,, ORG 4 ; Interrupt vector adress
00000004,2814,, GOTO ISR ; jump to service routine
,,,
00000005,0000,init,init NOP
00000006,1683 1303,, BANKSEL TRISD ; Select bank 1
00000008,0188,, CLRF TRISD ; Initialise display port
00000009,018C,, CLRF PIE1 ; Disable peripheral interrupts
,,,
0000000A,1283 1303,, BANKSEL PORTD ; Select bank 0
0000000C,0188,, CLRF PORTD ; Clear display outputs
,,,
0000000D,30C0,, MOVLW B'11000000' ; Enable..
0000000E,008B,, MOVWF INTCON ; ..peripheral interrupts
0000000F,3004,, MOVLW B'00000100' ; Capture mode:
00000010,0097,, MOVWF CCP1CON ; ..every falling edge
00000011,3001,, MOVLW B'00000001' ; Enable..
00000012,0090,, MOVWF T1CON ; ..Timer 1
,,,
00000013,28E6,, GOTO start ; Jump to main program
,,,
,,,; INTERRUPT SERVICE ROUTINE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
00000014,018E,ISR,ISR CLRF TMR1L
00000015,018F,, CLRF TMR1H
00000016,110C,, BCF PIR1,CCP1IF ; Reset interrupt flag
00000017,0009,, RETFIE
,,,
,,,; SUBROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,, INCLUDE "LCDIS.INC" ; Include display routines
,,,;--------------------------------------------------------------
,,,; LCDIS.INC MPB 19-12-05
,,,;
,,,; Include file to operate 16x2 LCD display
,,,; Uses GPR 70 - 75
,,,;
,,,; Final version
,,,;--------------------------------------------------------------
,,,
,,,Timer1 EQU 70 ; 1ms count register
,,,TimerX EQU 71 ; Xms count register
,,,Var EQU 72 ; Output variable
,,,Point EQU 73 ; Program table pointer
,,,Select EQU 74 ; Used to set or clear RS bit
,,,OutCod EQU 75 ; Temp store for output code
,,,
,,,RS EQU 1 ; Register select output bit
,,,E EQU 2 ; Enable display input
,,,
,,,
,,,;--------------------------------------------------------------
,,,; 1ms delay with 1us cycle time (1000 cycles)
,,,;--------------------------------------------------------------
00000018,30F9,onems,onems MOVLW D'249' ; Count for 1ms delay
00000019,00F0,, MOVWF Timer1 ; Load count
0000001A,0000,loop1,loop1 NOP ; Pad for 4 cycle loop
0000001B,0BF0,, DECFSZ Timer1 ; Count
0000001C,281A,, GOTO loop1 ; until Z
0000001D,0008,, RETURN ; and finish
,,,
,,,;--------------------------------------------------------------
,,,; Delay Xms
,,,; Receives count in W, uses Onems
,,,;--------------------------------------------------------------
0000001E,00F1,xms,xms MOVWF TimerX ; Count for X ms
0000001F,2018,loopX,loopX CALL onems ; Delay 1ms
00000020,0BF1,, DECFSZ TimerX ; Repeat X times
00000021,281F,, GOTO loopX ; until Z
00000022,0008,, RETURN ; and finish
,,,
,,,;--------------------------------------------------------------
,,,; Generate data/command clock siganl E
,,,;--------------------------------------------------------------
00000023,1508,pulseE,pulseE BSF PORTD,E ; Set E high
00000024,2018,, CALL onems ; Delay 1ms
00000025,1108,, BCF PORTD,E ; Reset E low
00000026,2018,, CALL onems ; Delay 1ms
00000027,0008,, RETURN ; done
,,,
,,,;--------------------------------------------------------------
,,,; Send a command byte in two nibbles from RB4 - RB7
,,,; Receives command in W, uses PulseE and Onems
,,,;--------------------------------------------------------------
00000028,00F5,send,send MOVWF OutCod ; Store output code
00000029,39F0,, ANDLW 0F0 ; Clear low nybble
0000002A,0088,, MOVWF PORTD ; Output high nybble
0000002B,18F4,, BTFSC Select,RS ; Test RS bit
0000002C,1488,, BSF PORTD,RS ; and set for data
0000002D,2023,, CALL pulseE ; and clock display register
0000002E,2018,, CALL onems ; wait 1ms for display
,,,
0000002F,0EF5,, SWAPF OutCod ; Swap low and high nybbles
00000030,0875,, MOVF OutCod,W ; Retrieve output code
00000031,39F0,, ANDLW 0F0 ; Clear low nybble
00000032,0088,, MOVWF PORTD ; Output low nybble
00000033,18F4,, BTFSC Select,RS ; Test RS bit
00000034,1488,, BSF PORTD,RS ; and set for data
00000035,2023,, CALL pulseE ; and clock display register
00000036,2018,, CALL onems ; wait 1ms for display
00000037,0008,, RETURN ; done
,,,
,,,;--------------------------------------------------------------
,,,; Initialise the display
,,,; Uses Send
,,,;--------------------------------------------------------------
00000038,3064,inid,inid MOVLW D'100' ; Load count for 100ms delay
00000039,201E,, CALL xms ; and wait for display start
0000003A,30F0,, MOVLW 0F0 ; Mask for select code
0000003B,00F4,, MOVWF Select ; High nybble not masked
,,,
0000003C,3030,, MOVLW 0x30 ; Load initial nibble
0000003D,0088,, MOVWF PORTD ; and output it to display
0000003E,2023,, CALL pulseE ; Latch initial code
0000003F,3005,, MOVLW D'5' ; Set delay 5ms
00000040,201E,, CALL xms ; and wait
00000041,2023,, CALL pulseE ; Latch initial code again
00000042,2018,, CALL onems ; Wait 1ms
00000043,2023,, CALL pulseE ; Latch initial code again
00000044,1208,, BCF PORTD,4 ; Set 4-bit mode
00000045,2023,, CALL pulseE ; Latch it
,,,
00000046,3028,, MOVLW 0x28 ; Set 4-bit mode, 2 lines
00000047,2028,, CALL send ; and send code
00000048,3008,, MOVLW 0x08 ; Switch off display
00000049,2028,, CALL send ; and send code
0000004A,3001,, MOVLW 0x01 ; Code to clear display
0000004B,2028,, CALL send ; and send code
0000004C,3006,, MOVLW 0x06 ; Enable cursor auto inc
0000004D,2028,, CALL send ; and send code
0000004E,3080,, MOVLW 0x80 ; Zero display address
0000004F,2028,, CALL send ; and send code
00000050,300C,, MOVLW 0x0C ; Turn on display
00000051,2028,, CALL send ; and send code
,,,
00000052,0008,, RETURN ; Done
,,,
,,,;--------------------------------------------------------------
,,,
,,,;----------------------------------------------------------------
,,,; Convert 16 bit binary result to 5 digits
,,,;----------------------------------------------------------------
,,,
00000053,0815,conv,conv MOVF CCPR1L,W ; Get high byte
00000054,00A1,, MOVWF Lobyte ; and store
00000055,0816,, MOVF CCPR1H,W ; Get low byte
00000056,00A0,, MOVWF Hibyte ; and store
,,,
00000057,3006,, MOVLW 06 ; Correction value
00000058,1003,, BCF STATUS,C ; prepare carry flag
00000059,07A1,, ADDWF Lobyte ; add correction
0000005A,1803,, BTFSC STATUS,C ; and carry
0000005B,0AA0,, INCF Hibyte ; in required
,,,
0000005C,01A2,, CLRF Tents ; clear ten thousands register
0000005D,01A3,, CLRF Thous ; clear thousands register
0000005E,01A4,, CLRF Hunds ; clear hundreds register
0000005F,01A5,, CLRF Tens ; clear tens register
00000060,01A6,, CLRF Ones ; clear ones register
,,,
,,,; Subtract 10000d (2710h) and count ...........................
,,,
00000061,3010,sub10,sub10 MOVLW 010 ; get low byte to sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -