?? ver1b.asm
字號:
; proportional to integral ppm converter
; the device works as an integrator
list p=12F675
radix hex
include P12F675.INC
errorlevel -302
__CONFIG _CPD_OFF&_CP_OFF&_BODEN_OFF&_MCLRE_OFF&_WDT_OFF&_INTRC_OSC_NOCLKOUT
resetout macro
bcf GPIO, 0x01;
endm
setout macro
bsf GPIO, 0x01;
endm
setstate0 macro
movlw 0xf0 ;
andwf MYSTAT, f ;
bsf mystat0 ;
endm
setstate1 macro
movlw 0xf0 ;
andwf MYSTAT, f ;
bsf mystat1 ;
endm
setstate2 macro
movlw 0xf0 ;
andwf MYSTAT, f ;
bsf mystat2 ;
endm
setstate3 macro
movlw 0xf0 ;
andwf MYSTAT, f ;
bsf mystat3 ;
endm
exitint macro
goto reti ;
endm
prepare0 macro
resetout
movlw intv0 ; intv0 is the state0 timeout
movwf TMR0
bcf INTCON, T0IF ;
endm
prepare1 macro
resetout
movlw intv1 ; intv1 is the state1 timeout
movwf TMR0
bcf INTCON, T0IF ;
endm
prepare2 macro
setout
movf psout, w ; psout is the state2 timeout
movwf TMR0 ; aka the pulse out
bcf INTCON, T0IF ;
endm
prepare3 macro
resetout
movlw intv3 ; intv0 is the state0 timeout
movwf TMR0
bcf INTCON, T0IF ;
endm
docalculus macro
movf TMR0, w ; load it
movwf psin ; to psin
movf psin, w ;
addlw th0 ;
btfss STATUS, C ; it should be some carry to carry on
goto exitc ; pulse too short
movf psin, w ;
addlw th1 ;
btfss STATUS, C ; it should be some carry to carry on
goto calmin ; minimal pulse detected
movf psin, w ;
addlw th2 ;
btfss STATUS, C ; it should be some carry to carry on
goto exitc ; pulse is neutral
movf psin, w ;
addlw th3 ;
btfss STATUS, C ; it should be some carry to carry on
goto calmax ; maximal pulse detected
goto exitc ; pulse is too long
calmin movlw thmin ; test for minimal pulse (maximal couter0 value)
addwf psout, w ;
btfss STATUS, C ;
incf psout, f ; increment if the overflow was not generated
goto exitc ;
calmax movlw thmax ; test for minimal pulse (maximal couter0 value)
addwf psout, w ;
btfsc STATUS, C ;
decf psout, f ; increment if the overflow was not generated
goto exitc ;
exitc nop;
endm
; now file deffinitions
;*****constants
; HARDWARE
; GP0 in
; GP1 out
; GP2
; GP3 i/o
; GP4
; GP5
; now file definitions
;CONSTANTS
intv0 equ d'201' ; timeout state0, 7mS
intv1 equ d'238' ; -//- state1 2.3mS
intv3 equ d'138' ; -//- state3 15mS
th0 equ d'10' ; too short inpulse th
th1 equ d'7' ; bandgap short
th2 equ d'5' ; bandgap long
th3 equ d'2' ; too long th
thmax equ d'240' ; maximal pulse out wdth
thmin equ d'248' ; minimal -//-
psstart equ d'244' ; startup value -//-
; the temporary files
W_TEMP equ 0x20 ; temporary w file
STATUS_TEMP equ 0x21
PCLATH_TEMP equ 0x22
; play files
MYSTAT equ 0x23 ; mystat
#define mystat0 MYSTAT, 0 ; mystat0
#define mystat1 MYSTAT, 1 ; mystat1
#define mystat2 MYSTAT, 2 ; mystat2
#define mystat3 MYSTAT, 3 ; mystat3
psin equ 0x26 ; input wdth
psout equ 0x27 ; output wdth
start org 0x0000 ; reset vector
nop ; allow debugger
nop
goto init ; goto initblock
; ISR XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
intr org 0x0004 ; interrupt vector
MOVWF W_TEMP ;copy W to temp register,could be in either bank
SWAPF STATUS, W ;swap status to be saved into W
BCF STATUS, RP0 ;change to bank 0 regardless ofcurrent bank
MOVWF STATUS_TEMP ;save status to bank 0 register
bcf STATUS, RP0
bcf STATUS, RP1
TM0T btfss INTCON, T0IF ; timer0 interr test
goto notm ; if no timer0 interrupt
bcf INTCON, T0IF ; clear it
btfss mystat2
goto tmns2 ; if no state 2
prepare3 ;
setstate3
exitint ;
tmns2 btfss mystat1 ;
goto tmns1 ;
prepare2 ;
setstate2 ;
exitint ;
tmns1 btfss mystat3 ;
goto tmns3 ;
prepare0 ;
setstate0 ;
exitint ;
tmns3 btfss mystat0 ;
goto tmns0 ;
prepare1 ;
setstate1 ;
exitint ;
tmns0 prepare2 ;
setstate2 ;
exitint ;
notm btfss INTCON, GPIF ;
goto exitinti ;
nop
bcf INTCON, GPIF ; clear the int source
movf GPIO, w ; read the port
andlw 0x01 ; isolate lsb, in
btfsc STATUS, Z ;
goto ntmin0 ;
ntmin1 btfss mystat0 ;
goto exitinti ;
prepare1 ;
setstate1 ;
exitint ;
ntmin0 btfss mystat1 ;
goto exitinti ;
docalculus ;
prepare2 ;
setstate2 ;
exitint ;
exitinti exitint ;
reti SWAPF STATUS_TEMP ,W ;swap STATUS_TEMP register into W, sets bank to original state
MOVWF STATUS ;move W into STATUS register
SWAPF W_TEMP, F ;swap W_TEMP
SWAPF W_TEMP,W ;swap W_TEMP into W
retfie ; exit general ISR
; INIT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
init bcf INTCON, GIE ; disable all interrupts
bsf STATUS, RP0 ; Bank 1
call 3FFh ; Get the cal value
movwf OSCCAL ; Calibrate
bcf STATUS, RP0 ; Bank 0
bcf STATUS, RP0 ;
bcf STATUS, RP1 ; bank0
clrf GPIO ; clear port
movlw 0x07 ; all digital
movwf CMCON
movlw 0x00
movwf GPIO ;
bsf STATUS, RP0 ; bank1
dirset movlw b'11111101' ; all inputs but GP1
movwf TRISIO ; configure them
anaset movlw b'00000000' ; all digital
movwf ANSEL ;
movlw b'00000001' ; enable only gp0 IOCB
movwf IOCB ;
bcf STATUS, RP0 ; return to
bcf STATUS, RP1 ; bank0
movlw b'00000000' ; disable ADC,
movwf ADCON0 ;
movlw b'00101000' ;
movwf INTCON ; enable TMR0 and IOCB
bsf STATUS, RP0 ; bank1
movlw b'00000000' ;
movwf PIE1 ;
bcf STATUS, RP0 ; return to
bcf STATUS, RP1 ; bank0
movlw b'00000000' ;
movwf T1CON ; timer, not enabled yet, no prescaler
clrwdt ;Clear WDT
clrf TMR0 ;and tmr0
bsf STATUS, RP0 ; bank1
movlw b'01000110' ; 128x prescaler, to TMR0 as timer, GP2 positive interr
movwf OPTION_REG ;
movlw b'00111100' ; WPU
movwf WPU ;
bcf STATUS, RP0 ; return to
bcf STATUS, RP1 ; bank0
movlw 0x01 ;
movwf MYSTAT ;
movlw psstart ;
movwf psout ;
bsf INTCON, GIE ;
; the
mloop goto mloop ;
org 0x3FF ;
retlw 0x84 ; the calibration value
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -