ORG 0x000 ; processor reset vector
nop ; nop required for icd
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
movf FSR,w ; 保护FSR
movwf fsr_temp
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
fsr_temp EQU 0x7C ; variable used for context saving
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving
cblock 0x20
tx_buff:8
tx_point
tx_count
ad_data_buff: 8 ;采样数据缓冲区
ad_data_point ;采样数据缓冲区偏移指针
ad_data_L ;采样数据平滑处理单元低8位
ad_data_H ;采样数据平滑处理单元高8位
ad_result_L ;最终采样数据低8位
ad_result_H ;最终采样数据高8位
endc
#define TX_IE PIE1,TXIE
#define TX_IF PIR1,TXIF
#define PE_IE INTCON,PEIE
#define G_IE INTCON,GIE
;**********************************************************************
ORG 0x000 ; processor reset vector
nop ; nop required for icd
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
movf FSR,w
movwf fsr_temp
;Bank1 判断是否串行发送
;**********************
banksel PIE1
btfss TX_IE
goto Other_int
banksel PIR1
btfss TX_IF
goto Other_int
;判断完成,间接寻址取数据
movlw tx_buff
movwf FSR
movf tx_point,w
addwf FSR,f
movf INDF,w
;发送数据
movwf TXREG
;偏移指针等准备发送下一个数据
incf tx_point
decfsz tx_count,f ;缓冲区还有数据没有发送完毕
;保持打开TXIE中断
;一个字节发送完后产生中断继续发送后续数据
goto End_int
;缓冲区数据全部发送完毕,完成清理工作
banksel PIE1
bcf TX_IE
;bank0
;***********************
banksel STATUS
Other_int
End_int
movf fsr_temp,w
movwf FSR
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt作者: joyrus 时间: 2012-7-6 18:37
主程序部分变化比较大