📄 pulse.sdi
字号:
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,;
,,,; PULSE.ASM MPB 21-8-05
,,,; Generates timed output interval using Timer 2
,,,; in compare mode
,,,; Timer interrupt sets output, cleared after 1ms
,,,;
,,,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,, PROCESSOR 16F877A
,,,; Clock = XT 4MHz, standard fuse settings
00002007,3731,, __CONFIG 0x3731
,,,
,,,; LABEL EQUATES ......................................
,,,
,,, INCLUDE "P16F877A.INC" ; Standard register labels
,,,
,,,Count EQU 20 ; soft timer
,,,
,,,; Program begins ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
,,,
,,, ORG 0 ; Place machine code
00000000,0000,, NOP ; for ICD mode
00000001,2805,, GOTO init ; Jump over ISR vector
,,,
,,, ORG 4 ; ISR vector address
00000004,2820,, GOTO isr ; run ISR
,,,
00000005,0000,init,init NOP
00000006,1683 1303,, BANKSEL TRISC ; Select bank 1
00000008,30FB,, MOVLW B'11111011' ; RC2 = output
00000009,0087,, MOVWF TRISC ; Initialise display port
0000000A,3004,, MOVLW B'00000100' ; Timer1 interrupt..
0000000B,008C,, MOVWF PIE1 ; ..enable
,,,
0000000C,1283 1303,, BANKSEL PORTC ; Select bank 0
0000000E,0187,, CLRF PORTC ; Clear output
0000000F,30C0,, MOVLW B'11000000' ; Peripheral interupt..
00000010,008B,, MOVWF INTCON ; ..enable
00000011,3008,, MOVLW B'00001000' ; Compare mode..
00000012,0097,, MOVWF CCP1CON ; ..set output on match
00000013,3027,, MOVLW 027 ; Initial value..
00000014,0096,, MOVWF CCPR1H ; .. for high byte (10ms)
00000015,3010,, MOVLW 010 ; Initial value..
00000016,0095,, MOVWF CCPR1L ; .. for low byte (10ms)
00000017,3001,, MOVLW B'00000001' ; Timer1 enable..
00000018,0090,, MOVWF T1CON ; with internal clock (1MHz)
,,,
00000019,2831,, GOTO start ; Jump to main program
,,,
,,,; SUBROUTINES............................................
,,,
,,,; 1ms delay with 1us cycle time (1000 cycles)
,,,
0000001A,30F9,onems,onems MOVLW D'249' ; Count for 1ms delay
0000001B,00A0,, MOVWF Count ; Load count
0000001C,0000,loop,loop NOP ; Pad for 4 cycle loop
0000001D,0BA0,, DECFSZ Count ; Count
0000001E,281C,, GOTO loop ; until Z
0000001F,0008,, RETURN ; and finish
,,,
,,,
,,,; INTERRUPT SERVICE ROUTINE..............................
,,,
,,,; Reset interrupt, check buttons, generate 1ms pulse
,,,
00000020,018C,isr,isr CLRF PIR1 ; clear interrupt flags
00000021,018F,, CLRF TMR1H ; clear timer high..
00000022,018E,, CLRF TMR1L ; ..and low byte
,,,
00000023,1808,, BTFSC PORTD,0 ; dec frequency button?
00000024,2828,, GOTO other ; no
00000025,0F96,, INCFSZ CCPR1H ; yes, inc period, zero?
00000026,2828,, GOTO other ; no
00000027,0396,, DECF CCPR1H ; yes, step back
,,,
00000028,1888,other,other BTFSC PORTD,1 ; inc frequency button?
00000029,282D,, GOTO wait ; no
0000002A,0B96,, DECFSZ CCPR1H ; yes, inc period, zero?
0000002B,282D,, GOTO wait ; no
0000002C,0A96,, INCF CCPR1H ; yes, step back
,,,
0000002D,201A,wait,wait CALL onems ; wait 1ms
0000002E,1197,, BCF CCP1CON,3 ; clear output
0000002F,1597,, BSF CCP1CON,3 ; re-enable timer mode
,,,
00000030,0009,, RETFIE ; return to main program
,,,
,,,
,,,;-----------------------------------------------------------
,,,; Main program
,,,;-----------------------------------------------------------
00000031,2831,start,start GOTO start ; wait for timer interrupt
,,, END ; of source code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -