📄 app_1169.asm
字号:
;******************************************************************************
errorsr
; *** errorsr code goes here ***
call HWI2C_readLast_W ;
call HWI2C_stop ;
dead
movlw 0x45 ; Load w with ASCII 'E' for ERROR
movwf xmtreg ; Move w to xmtreg
call asyxmtc ; Call UART routine
goto dead ; Transmit ASCII 'E' forever
;******************************************************************************
HWI2C_start
movlw 0x00 ;T load w with literal
movwf tcount ;T move w to tcount
bcf PIR1,SSPIF ;T clear completed flag
bsf SSPCON2,SEN ;T send start
sloop1
; call delay_100ms ;OP_T
btfsc PIR1,SSPIF ;T start completed?
goto sxloop ;T exit loop
incf tcount,f ;T increment tcount
movlw 0xFF ;T load w with literal
subwf tcount,w ;T subtract 0xFF from tcount result in w
btfss STATUS,Z ;T test zero flag, skip next instr if z set
goto sloop1 ;T loop until timeout
goto serror ;T complete timeout error
sxloop call clear_cf_ok ;T clear carry flag =>Success
return
serror call set_cf_error ;T set carry flag =>error
return
;******************************************************************************
HWI2C_stop
movlw 0x00 ;T load w with literal
movwf tcount ;T move w to tcount
bcf PIR1,SSPIF ;T clear completed flag
bsf SSPCON2,PEN ;T send stop
ploop1
; call delay_100ms ;OP_T
btfsc PIR1,SSPIF ;T start completed?
goto pxloop ;T exit loop
incf tcount,f ;T increment tcount
movlw 0xFF ;T load w with literal
subwf tcount,w ;T subtract 0xFF from tcount result in w
btfss STATUS,Z ;T test zero flag, skip next instr if z set
goto ploop1 ;T loop until timeout
goto perror ;T complete timeout error
pxloop call clear_cf_ok ;T clear carry flag =>Success
return
perror call set_cf_error ;T set carry flag =>error
return
;******************************************************************************
HWI2C_repeatedStart
movlw 0x00 ;T load w with literal
movwf tcount ;T move w to tcount
bcf PIR1,SSPIF ;T clear completed flag
bsf SSPCON2,RSEN ;T send repeated start
rsloop1
; call delay_100ms ;OP_T
btfsc PIR1,SSPIF ;T repeated start completed?
goto rsxloop ;T exit loop
incf tcount,f ;T increment tcount
movlw 0xFF ;T load w with literal
subwf tcount,w ;T subtract 0xFF from tcount result in w
btfss STATUS,Z ;T test zero flag, skip next instr if z set
goto rsloop1 ;T loop until timeout
goto rserror ;T complete timeout error
rsxloop call clear_cf_ok ;T clear carry flag =>Success
return
rserror call set_cf_error ;T set carry flag =>error
return
;******************************************************************************;
HWI2C_W_slaveAddr
bcf PIR1,SSPIF ;T clear completed flag
movwf SSPBUF ;T send data
wloop1 btfss PIR1,SSPIF ;T data sent?
goto wloop1 ;T loop until completed
btfsc SSPCON2,ACKSTAT ;T ACK error? if no then skip
goto werror ;T set_cf_error
call clear_cf_ok ;T clear carry flag =>Success
return
werror call set_cf_error ;T set carry flag =>error
return
;******************************************************************************
set_cf_error
movlw 0x00 ; 0x00 into W
sublw 0x00 ; Subtract W-0x00: If W<=N C set; If W>N C clear.
return ; error=> cf=set
;******************************************************************************
clear_cf_ok
movlw 0x01 ; 0x00 into W
sublw 0x00 ; Subtract W-0x00: If W<=N C set; If W>N C clear.
return ; success=> cf=clear
;******************************************************************************
HWI2C_readMore_W
movlw 0x00 ;T load w with literal
movwf tcount ;T move w to tcount
bcf PIR1,SSPIF ;T clear completed flag
bsf SSPCON2,RCEN ;T receive data byte
rloop1
; call delay_100ms ;OP_T
btfsc PIR1,SSPIF ;T data byte received?
goto xloop ;T exit loop
incf tcount,f ;T increment tcount
movlw 0xFF ;T load w with literal
subwf tcount,w ;T subtract 0xFF from tcount result in w
btfss STATUS,Z ;T test zero flag, skip next instr if z set
goto rloop1 ;T loop until timeout
goto rerror ;T receive timeout error
xloop movf SSPBUF,w ;T load data byte into w
movwf data0 ;T loads data byte into data0
bcf PIR1,SSPIF ;T clear completed flag
bcf SSPCON2,ACKDT ;T set ACK
bsf SSPCON2,ACKEN ;T send ACK
rloop2 btfss PIR1,SSPIF ;T send completed?
goto rloop2 ;T loop until completed
call clear_cf_ok ;T clear carry flag =>Success
movf data0,w ;T move contents of data0 to w
return
rerror call set_cf_error ;T set carry flag =>error
return
;******************************************************************************
HWI2C_readLast_W
movlw 0x00 ;T load w with literal
movwf tcount ;T move w to tcount
bcf PIR1,SSPIF ;T clear completed flag
bsf SSPCON2,RCEN ;T receive data byte
rloop3
; call delay_100ms ;OP_T
btfsc PIR1,SSPIF ;T data byte received?
goto xloop2 ;T exit loop
incf tcount,f ;T increment tcount
movlw 0xFF ;T load w with literal
subwf tcount,w ;T subtract 0xFF from tcount result in w
btfss STATUS,Z ;T test zero flag, skip next instr if z set
goto rloop3 ;T loop until timeout
goto rerror2 ;T receive timeout error
xloop2 movf SSPBUF,w ;T load data byte into w
movwf data0 ;T loads data byte into data0
bcf PIR1,SSPIF ;T clear completed flag
bsf SSPCON2,ACKDT ;T set NOACK
bsf SSPCON2,ACKEN ;T send NOACK
rloop4 btfss PIR1,SSPIF ;T send completed?
goto rloop4 ;T loop until completed
call clear_cf_ok ;T clear carry flag =>Success
movf data0,w ;T move contents of data0 to w
return
rerror2 call set_cf_error ;T set carry flag =>error
return
;******************************************************************************
; UART routine
asyxmtc bcf PORTC,xmit ;T used to be portc,xmit
call full
movlw 0x08 ;TEST_T "08"
movwf bitctr
asyxmt1 rrcf xmtreg,f
btfsc STATUS,C
goto asyxmt2
bcf PORTC,xmit ;T used to be portc,xmit
goto asyxmt3
asyxmt2 bsf PORTC,xmit ;T used to be portc,xmit
;
asyxmt3 call full
decfsz bitctr,f
goto asyxmt1
;
bsf PORTC,xmit ;T used to be portc,xmit
call full
retlw 0
;******************************************************************************
; Modified for 115.2kbps (~8.6usec bit period)
full movlw d'3'
movwf cntrb
vdly0 movlw d'6' ; was d'43' for 2400 baud
movwf cntra
vdly1 decfsz cntra,f
goto vdly1
decfsz cntrb,f
goto vdly0
retlw 0
;******************************************************************************
;Delay Subroutine
;This subroutine implementes a delay greater
;than or equal to the MAX1169's maximum conversion time in fast mode
delay
movlw 0x0F ;0x0F to w
movwf xcount ;to xcount
repeat decfsz xcount,f ;decrement xcount and skip if '0'
goto repeat ;not '0' yet
return
;******************************************************************************
;End of program
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -