|
#INCLUDE
; 接收数据程序;***********RAM DEFINE*******************
CBLOCK 10H
TEMP_CANCON ;
TEMP_CANSTAT;
W_TEMP
DELAY2 ; DELAY 延时
DELAY1 ; DELAY
COUNT ; 查表
RX_COUNT ; 接收的字节数
_PORTA ; PORTA缓冲器
ENDC
;*************LOCAL MACROS***************
CONFIGURE_MODE MACRO
BSF CANCON,REQOP2
ENDM
NORMAL_MODE MACRO
BCF CANCON,REQOP2
BCF CANCON,REQOP1
BCF CANCON,REQOP0
BCF CANCON,ABAT
ENDM
LOOPBACK_MODE MACRO
BCF CANCON,REQOP2
BSF CANCON,REQOP1
BCF CANCON,REQOP0
BCF CANCON,ABAT
ENDM
DIS_ALL_TX MACRO
BSF CANCON,ABAT
ENDM
ENABLE_ALL_TX MACRO
BCF CANCON,ABAT
ENDM
;**************DIFINE***********************
#DEFINE _TXREQ0 TXB0CON,TXREQ
#DEFINE _TXB0IF PIR3,TXB0IF
#DEFINE _RXFUL0 RXB0CON,RXFUL
#DEFINE _RXFUL1 RXB1CON,RXFUL
;******************复位矢量中断向量*************
ORG 000h
NOP
GOTO MAIN
ORG 0008h
GOTO INTSER
INTSER
;**************利用查表来调查中断源*************
MOVWF W_TEMP
MOVFF CANCON,TEMP_CANCON ;保护寄存器
MOVFF CANSTAT,TEMP_CANSTAT;
MOVF TEMP_CANSTAT,W
ANDLW b'00001110'
ADDWF PCL,F
BRA nointerrupt;
BRA errorinterrupt
BRA txb2interrupt
BRA txb1interrupt
BRA txb0interrupt
BRA rxb1interrupt
BRA RXB0_INTERRUPT
;*********txb0 中断********
txb0interrupt
BCF PIR3,TXB0IF
MOVLW 0FFH
MOVWF 20H
GOTO ACCESSBUFFERS
RETFIE
txb1interrupt
BCF PIR3,TXB1IF
GOTO ACCESSBUFFERS
RETFIE
txb2interrupt
BCF PIR3,TXB2IF
GOTO ACCESSBUFFERS
RETFIE
RXB0_INTERRUPT
BCF RXB0CON,RXFUL ;必须清零,否则会溢出到RXB1D0
BCF PIR3,RXB0IF
MOVFF RXB0D0,PORTC
GOTO ACCESSBUFFERS
RETFIE
rxb1interrupt
BCF RXB1CON,RXFUL ;必须清零,否则会溢出到RXB1D0
BCF PIR3,RXB1IF
MOVFF RXB1D0,PORTC
GOTO ACCESSBUFFERS
RETFIE
nointerrupt
BCF INTCON,TMR0IF
MOVF PORTB,W
XORLW B'00000001'
MOVWF PORTB
MOVF W_TEMP,W
retfie
errorinterrupt
BCF PIR3,ERRIF
retfie
ACCESSBUFFERS
MOVF TEMP_CANCON,W
ANDLW B'11110001'
MOVWF TEMP_CANCON
MOVF TEMP_CANSTAT,W
ANDLW B'00001110'
IORWF TEMP_CANCON
MOVFF TEMP_CANCON,CANCON
MOVF CANCON,W
ANDLW B'11110001'
IORWF TEMP_CANCON
RETFIE
;*****************主程序*************************
MAIN
CALL CLR_BANK ;CLEAR ALL BANK 0,1,2,15
;**********开始进入传输初始化的设定***************
SETUP
MOVLB 0FH ;BANK 15
LFSR FSR0,40H ;接收缓冲器
MOVLW B'11000000' ;ENABLE ALL
MOVWF INTCON ;enable gie
MOVLW B'00000001' ;ONLY ENABLE RXB0IE
MOVWF PIE3
CALL SET_PORT ;set port
CALL TXB0_IDENTIFIER ;TXB0 FILTER
CALL RXB0_FILTER0 ;RXB0 FILTER0
CALL BAUD_RATE ;50KB/S
NORMAL_MODE ;NORMAL MODE
STOP
NOP
GOTO STOP
;******************RXB0 FILTER0****************
;RXB0_FILTER0
; ;*********************************************
RXB0_FILTER0
CONFIGURE_MODE
BSF RXB0CON,RXM1
BSF RXB0CON,RXM0
;0,0 FILTER 有效
;0,1 ONLY STANDARD FRAME
;1,1 RECEIVE ALL
;1,0 ONLY EXTERN FRAME
MOVLW B'10101111'
MOVWF RXF0SIDH ;进行过滤器的设定,只能再配置位模式进行
MOVLW b'11100000'
MOVWF RXF0SIDL
MOVLW B'11111111' ;识别位XXXXX000111
MOVWF RXM0SIDH
MOVLW B'11111111' ;全部起作用
MOVWF RXM0SIDL ;进行屏蔽位设定,全部为11
RETURN
;*********设置TXB0 IDENTIFIER***********************
;TXB0_IDENTIFIER
;***************************************************
TXB0_IDENTIFIER
BCF TXB0CON,TXPRI1
BCF TXB0CON,TXPRI0 ;high interrupt
MOVLW B'10101111'
MOVWF TXB0SIDH
MOVLW B'11100000' ;标志位是XXXXX000111
MOVWF TXB0SIDL
MOVLW B'00000001'
MOVWF TXB0DLC ;数据帧 6,txrtr是零
RETURN
;***********SET_PORT******************************
SET_PORT
;********PORTB********
;RB0 OUT
;RB1 OUT
;RB2 OUT TXCAN
;RB3 IN RXCAN
;RB4 IN
;RB5 IN
;RB6 ICD2
;RB7 ICD2
CLRF LATB
MOVLW B'00001000'
MOVWF TRISB
;*******PORTC*********
;RC0 OUT RC0-RC7 ALL OUT
;RC1 OUT
;RC7 OUT
CLRF LATC
MOVLW B'00000000'
MOVWF TRISC
RETURN
;**************BAUD RATE SET******************
; FOSC =4MHZ
; NOMINAL BIT TIME = 8 TQ
; TQ=2*(BAUD RATE +1)/FOSC
; SYN =1 TQ,PRO=1TQ,PHE1=3TQ,PHE2=3TQ
; BAUD RATE= 250KB/S
; BAUD RATE PRESCALER=00000
; fosc =4mhz MAX_baud rate=250kb/s
; If fosc=16Mhz ,the max_band=1Mkb/s
;01.05,使用600米长的总线,发现接受不到数据。估计是波特率太高,换低的波特率
;*********************************************
;BAUD_RATE ;250KB/S
; CONFIGURE_MODE
; MOVLW B'00000000' ;BAUD RATE SET
; MOVWF BRGCON1
; MOVLW B'10010000'
; MOVWF BRGCON2
; MOVLW B'00000010'
; MOVWF BRGCON3
; RETURN
;**************BAUD RATE SET******************
; FOSC =4MHZ
; NOMINAL BIT TIME = 8 TQ
; TQ=2*(BAUD RATE +1)/FOSC
; SYN =1 TQ,PRO=1TQ,PHE1=3TQ,PHE2=3TQ
; BAUD RATE= 50KB/S
; BAUD RATE PRESCALER=00100
; fosc =4mhz MAX_baud rate=250kb/s
; If fosc=16Mhz ,the max_band=1Mkb/s
;************************************************
BAUD_RATE ;50KB/S
CONFIGURE_MODE
MOVLW B'00000100' ;BAUD RATE SET
MOVWF BRGCON1
MOVLW B'10010000'
MOVWF BRGCON2
MOVLW B'00000010'
MOVWF BRGCON3
RETURN
;**********CLEAR BANK************************
CLR_BANK
LFSR FSR0,00H ;BANK 0
NEXT CLRF POSTINC0
BTFSS FSR0H,0
GOTO NEXT
LFSR FSR0,100H
NEXT1 CLRF POSTINC0 ;BANK1
BTFSS FSR0H,1
GOTO NEXT1
LFSR FSR0,200H
NEXT2 CLRF POSTINC0 ;BANK 2
BTFSS FSR0H,0
GOTO NEXT2
LFSR FSR0,0F00H
NEXT3 CLRF POSTINC0 ;BANK 15
BTFSS FSR0L,7
GOTO NEXT3
RETURN
END ;这是接收数据程序
#INCLUDE
;,处于等待远程帧,然后发送程序
;等待远程帧状态,接收到远程帧进入发送程序。;***********RAM DEFINE*******************
CBLOCK 10H
TEMP_CANCON ;
TEMP_CANSTAT;
W_TEMP
DELAY2 ; DELAY 延时
DELAY1 ; DELAY
COUNT ; 查表
RX_COUNT ; 接收的字节数
_PORTA ; PORTA缓冲器
ENDC
;*************LOCAL MACROS***************
CONFIGURE_MODE MACRO
BSF CANCON,REQOP2
ENDM
NORMAL_MODE MACRO
BCF CANCON,REQOP2
BCF CANCON,REQOP1
BCF CANCON,REQOP0
BCF CANCON,ABAT
ENDM
LOOPBACK_MODE MACRO
BCF CANCON,REQOP2
BSF CANCON,REQOP1
BCF CANCON,REQOP0
BCF CANCON,ABAT
ENDM
DIS_ALL_TX MACRO
BSF CANCON,ABAT
ENDM
ENABLE_ALL_TX MACRO
BCF CANCON,ABAT
ENDM
;**************DIFINE***********************
#DEFINE _TXREQ0 TXB0CON,TXREQ
#DEFINE _TXB0IF PIR3,TXB0IF
#DEFINE _RXFUL0 RXB0CON,RXFUL
#DEFINE _RXFUL1 RXB1CON,RXFUL
;******************复位矢量中断向量*************
ORG 000h
NOP
GOTO MAIN
ORG 0008h
GOTO INTSER
INTSER
;**************利用查表来调查中断源*************
MOVWF W_TEMP
MOVFF CANCON,TEMP_CANCON ;保护寄存器
MOVFF CANSTAT,TEMP_CANSTAT;
MOVF TEMP_CANSTAT,W
ANDLW b'00001110'
ADDWF PCL,F
BRA nointerrupt;
BRA errorinterrupt
BRA txb2interrupt
BRA txb1interrupt
BRA txb0interrupt
BRA rxb1interrupt
BRA RXB0_INTERRUPT
;*********txb0 中断********
txb0interrupt
BCF PIR3,TXB0IF
MOVLW 0FFH
MOVWF 20H
GOTO ACCESSBUFFERS
RETFIE
txb1interrupt
BCF PIR3,TXB1IF
GOTO ACCESSBUFFERS
RETFIE
txb2interrupt
BCF PIR3,TXB2IF
GOTO ACCESSBUFFERS
RETFIE
RXB0_INTERRUPT
BCF RXB0CON,RXFUL ;必须清零,否则会溢出到RXB1D0
BCF PIR3,RXB0IF
MOVFF RXB0D0,PORTC
; GOTO AA
; NOP
AA GOTO ACCESSBUFFERS
RETFIE
rxb1interrupt
BCF RXB1CON,RXFUL ;必须清零,否则会溢出到RXB1D0
BCF PIR3,RXB1IF
MOVFF RXB1D0,PORTC
GOTO ACCESSBUFFERS
RETFIE
nointerrupt
; BCF INTCON,TMR0IF
; MOVF PORTB,W
; XORLW B'00000001'
; MOVWF PORTB
; MOVF W_TEMP,W
retfie
errorinterrupt
BCF PIR3,ERRIF
; MOVLW 0FFH
; MOVWF 22H
; GOTO MOVE
retfie
ACCESSBUFFERS
MOVF TEMP_CANCON,W
ANDLW B'11110001'
MOVWF TEMP_CANCON
MOVF TEMP_CANSTAT,W
ANDLW B'00001110'
IORWF TEMP_CANCON
MOVFF TEMP_CANCON,CANCON
MOVF CANCON,W
ANDLW B'11110001'
IORWF TEMP_CANCON
RETFIE
;*****************主程序*************************
MAIN
CALL CLR_BANK ;CLEAR ALL BANK 0,1,2,15
;**********开始进入传输初始化的设定***************
SETUP
MOVLB 0FH ;BANK 15
LFSR FSR0,40H ;接收缓冲器30H——37H
MOVLW B'11000000' ;ENABLE ALL
MOVWF INTCON ;enable gie
MOVLW B'00000000' ;ONLY ENABLE RXB0IE
MOVWF PIE3
CALL SET_PORT ;set port
CALL TXB0_IDENTIFIER ;TXB0 FILTER
CALL RXB0_FILTER0 ;RXB0 FILTER0
CALL BAUD_RATE ;250KB/S
NORMAL_MODE ;NORMAL MODE
;**********接收********************
;///////////1219///////////////////////////////
;//1219 ,判断是否有远程帧,然后跳到发送程序
MOVLB 0FH
MOVLW B'00000001'
MOVWF 30H
CHECK
BTFSS RXB0DLC,RXRTR ;判断是否有远程帧
GOTO $-2
BCF RXB0DLC,RXRTR
BCF _RXFUL0 ;很重要,要不就只能接收一次
INCF 30H,F
MOVFF 30H,TXB0D0
MOVFF 30H,PORTC
BSF _TXREQ0
BTFSS _TXB0IF
GOTO $-2
BCF _TXB0IF
GOTO CHECK
STOP
NOP
GOTO STOP
;******************RXB0 FILTER0****************
;RXB0_FILTER0
; STANDARD FRAME
ORTA 低五位作为ID的高五位
;*********************************************
RXB0_FILTER0
CONFIGURE_MODE
BCF RXB0CON,RXM1
BCF RXB0CON,RXM0
;0,0 FILTER 有效
;0,1 ONLY STANDARD FRAME
;1,1 RECEIVE ALL
;1,0 ONLY EXTERN FRAME
MOVLW B'10101111'
MOVWF RXF0SIDH ;进行过滤器的设定,只能再配置位模式进行
MOVLW b'11100000'
MOVWF RXF0SIDL
MOVLW B'11111111' ;识别位XXXXX000111
MOVWF RXM0SIDH
MOVLW B'11111111' ;全部起作用
MOVWF RXM0SIDL ;进行屏蔽位设定,全部为11
RETURN
;*********设置TXB0 IDENTIFIER***********************
;TXB0_IDENTIFIER
;***************************************************
TXB0_IDENTIFIER
BCF TXB0CON,TXPRI1
BCF TXB0CON,TXPRI0 ;high interrupt
MOVLW B'10101111'
MOVWF TXB0SIDH
MOVLW B'11100000' ;标志位是XXXXX000111
MOVWF TXB0SIDL
MOVLW B'00000001'
MOVWF TXB0DLC ;数据帧 6,txrtr是零
RETURN
;***********SET_PORT******************************
SET_PORT
;********PORTB********
;RB0 OUT
;RB1 OUT
;RB2 OUT TXCAN
;RB3 IN RXCAN
;RB4 IN
;RB5 IN
;RB6 ICD2
;RB7 ICD2
CLRF LATB
MOVLW B'00001000'
MOVWF TRISB
;*******PORTC*********
;RC0 OUT RC0-RC7 ALL OUT
;RC1 OUT
;RC7 OUT
CLRF LATC
MOVLW B'00000000'
MOVWF TRISC
RETURN
;**************BAUD RATE SET******************
; FOSC =4MHZ
; NOMINAL BIT TIME = 8 TQ
; TQ=2*(BAUD RATE +1)/FOSC
; SYN =1 TQ,PRO=1TQ,PHE1=3TQ,PHE2=3TQ
; BAUD RATE= 250KB/S
; BAUD RATE PRESCALER=00000
; fosc =4mhz MAX_baud rate=250kb/s
; If fosc=16Mhz ,the max_band=1Mkb/s
;01.05,使用600米长的总线,发现接受不到数据。估计是波特率太高,换低的波特率
;*********************************************
;BAUD_RATE ;250KB/S
; CONFIGURE_MODE
; MOVLW B'00000000' ;BAUD RATE SET
; MOVWF BRGCON1
; MOVLW B'10010000'
; MOVWF BRGCON2
; MOVLW B'00000010'
; MOVWF BRGCON3
; RETURN
;**************BAUD RATE SET******************
; FOSC =4MHZ
; NOMINAL BIT TIME = 8 TQ
; TQ=2*(BAUD RATE +1)/FOSC
; SYN =1 TQ,PRO=1TQ,PHE1=3TQ,PHE2=3TQ
; BAUD RATE= 50KB/S
; BAUD RATE PRESCALER=00100
; fosc =4mhz MAX_baud rate=250kb/s
; If fosc=16Mhz ,the max_band=1Mkb/s
;************************************************
BAUD_RATE ;50KB/S
CONFIGURE_MODE
MOVLW B'00000100' ;BAUD RATE SET
MOVWF BRGCON1
MOVLW B'10010000'
MOVWF BRGCON2
MOVLW B'00000010'
MOVWF BRGCON3
RETURN
;**********CLEAR BANK************************
CLR_BANK
LFSR FSR0,00H ;BANK 0
NEXT CLRF POSTINC0
BTFSS FSR0H,0
GOTO NEXT
LFSR FSR0,100H
NEXT1 CLRF POSTINC0 ;BANK1
BTFSS FSR0H,1
GOTO NEXT1
LFSR FSR0,200H
NEXT2 CLRF POSTINC0 ;BANK 2
BTFSS FSR0H,0
GOTO NEXT2
LFSR FSR0,0F00H
NEXT3 CLRF POSTINC0 ;BANK 15
BTFSS FSR0L,7
GOTO NEXT3
RETURN
END 结束
#INCLUDE
;发送远程帧,然后接收;***********RAM DEFINE*******************
CBLOCK 10H
TEMP_CANCON ;
TEMP_CANSTAT;
W_TEMP
DELAY2 ; DELAY 延时
DELAY1 ; DELAY
COUNT ; 查表
RX_COUNT ; 接收的字节数
_PORTA ; PORTA缓冲器
ENDC
;*************LOCAL MACROS***************
CONFIGURE_MODE MACRO
BSF CANCON,REQOP2
ENDM
NORMAL_MODE MACRO
BCF CANCON,REQOP2
BCF CANCON,REQOP1
BCF CANCON,REQOP0
BCF CANCON,ABAT
ENDM
LOOPBACK_MODE MACRO
BCF CANCON,REQOP2
BSF CANCON,REQOP1
BCF CANCON,REQOP0
BCF CANCON,ABAT
ENDM
DIS_ALL_TX MACRO
BSF CANCON,ABAT
ENDM
ENABLE_ALL_TX MACRO
BCF CANCON,ABAT
ENDM
;**************DIFINE***********************
#DEFINE _TXREQ0 TXB0CON,TXREQ
#DEFINE _TXB0IF PIR3,TXB0IF
#DEFINE _RXFUL0 RXB0CON,RXFUL
#DEFINE _RXFUL1 RXB1CON,RXFUL
;******************复位矢量中断向量*************
ORG 000h
NOP
GOTO MAIN
ORG 0008h
GOTO INTSER
INTSER
;**************利用查表来调查中断源*************
MOVWF W_TEMP
MOVFF CANCON,TEMP_CANCON ;保护寄存器
MOVFF CANSTAT,TEMP_CANSTAT;
MOVF TEMP_CANSTAT,W
ANDLW b'00001110'
ADDWF PCL,F
BRA nointerrupt;
BRA errorinterrupt
BRA txb2interrupt
BRA txb1interrupt
BRA txb0interrupt
BRA rxb1interrupt
BRA RXB0_INTERRUPT
;*********txb0 中断********
txb0interrupt
BCF PIR3,TXB0IF
MOVLW 0FFH
MOVWF 20H
GOTO ACCESSBUFFERS
RETFIE
txb1interrupt
BCF PIR3,TXB1IF
GOTO ACCESSBUFFERS
RETFIE
txb2interrupt
BCF PIR3,TXB2IF
GOTO ACCESSBUFFERS
RETFIE
RXB0_INTERRUPT
BCF RXB0CON,RXFUL ;必须清零,否则会溢出到RXB1D0
BCF PIR3,RXB0IF
MOVFF RXB0D0,PORTC
; GOTO AA
; NOP
AA GOTO ACCESSBUFFERS
RETFIE
rxb1interrupt
BCF RXB1CON,RXFUL ;必须清零,否则会溢出到RXB1D0
BCF PIR3,RXB1IF
MOVFF RXB1D0,PORTC
GOTO ACCESSBUFFERS
RETFIE
nointerrupt
BCF INTCON,TMR0IF
MOVF PORTB,W
XORLW B'00000001'
MOVWF PORTB
MOVF W_TEMP,W
retfie
errorinterrupt
BCF PIR3,ERRIF
; MOVLW 0FFH
; MOVWF 22H
; GOTO MOVE
retfie
ACCESSBUFFERS
MOVF TEMP_CANCON,W
ANDLW B'11110001'
MOVWF TEMP_CANCON
MOVF TEMP_CANSTAT,W
ANDLW B'00001110'
IORWF TEMP_CANCON
MOVFF TEMP_CANCON,CANCON
MOVF CANCON,W
ANDLW B'11110001'
IORWF TEMP_CANCON
RETFIE
;*****************主程序*************************
MAIN
CALL CLR_BANK ;CLEAR ALL BANK 0,1,2,15
;**********开始进入传输初始化的设定***************
SETUP
MOVLB 0FH ;BANK 15
LFSR FSR0,40H ;接收缓冲器 LFSR FSR1,RXB0D0 ;接收寄存器
MOVLW B'11000000' ;ENABLE ALL
MOVWF INTCON ;enable gie
MOVLW B'00000001' ;ONLY ENABLE RXB0IE
MOVWF PIE3
CALL SET_PORT ;set port
CALL TXB0_IDENTIFIER ;TXB0 FILTER
CALL RXB0_FILTER0 ;RXB0 FILTER0
CALL BAUD_RATE ;250KB/S
NORMAL_MODE ;NORMAL MODE
; LOOPBACK_MODE
MOVLW 0FH
MOVWF TXB0D0
AABB BSF _TXREQ0 循环发送远程帧, 要是在TXB0DLC里面改成数据帧,可以发送数据
BTFSS _TXB0IF
GOTO $-2
BCF _TXB0IF
CALL DELAY521MS
GOTO AABB
;******************RXB0 FILTER0****************
;RXB0_FILTER0
; STANDARD FRAME
;*********************************************
RXB0_FILTER0
CONFIGURE_MODE
BCF RXB0CON,RXM1
BCF RXB0CON,RXM0
;0,0 FILTER 有效
;0,1 ONLY STANDARD FRAME
;1,1 RECEIVE ALL
;1,0 ONLY EXTERN FRAME
MOVLW B'10101111'
MOVWF RXF0SIDH ;进行过滤器的设定,只能再配置位模式进行
MOVLW b'11100000'
MOVWF RXF0SIDL
MOVLW B'11111111' ;识别位XXXXX000111
MOVWF RXM0SIDH
MOVLW B'11111111' ;全部起作用
MOVWF RXM0SIDL ;进行屏蔽位设定,全部为11
RETURN
;*********设置TXB0 IDENTIFIER***********************
;TXB0_IDENTIFIER
;***************************************************
TXB0_IDENTIFIER
BCF TXB0CON,TXPRI1
BCF TXB0CON,TXPRI0 ;high interrupt
MOVLW B'10101111'
MOVWF TXB0SIDH
MOVLW B'11100000' ;标志位是XXXXX000111
MOVWF TXB0SIDL
MOVLW B'01000001'
MOVWF TXB0DLC ;数据帧 6,txrtr是零
RETURN
;***********SET_PORT******************************
SET_PORT
;********PORTB********
;RB0 OUT
;RB1 OUT
;RB2 OUT TXCAN
;RB3 IN RXCAN
;RB4 IN
;RB5 IN
;RB6 ICD2
;RB7 ICD2
CLRF LATB
MOVLW B'00001000'
MOVWF TRISB
;*******PORTC*********
;RC0 OUT RC0-RC7 ALL OUT
;RC1 OUT
;RC7 OUT
CLRF LATC
MOVLW B'00000000'
MOVWF TRISC
RETURN
;**************BAUD RATE SET******************
; FOSC =4MHZ
; NOMINAL BIT TIME = 8 TQ
; TQ=2*(BAUD RATE +1)/FOSC
; SYN =1 TQ,PRO=1TQ,PHE1=3TQ,PHE2=3TQ
; BAUD RATE= 250KB/S
; BAUD RATE PRESCALER=00000
; fosc =4mhz MAX_baud rate=250kb/s
; If fosc=16Mhz ,the max_band=1Mkb/s
;01.05,使用600米长的总线,发现接受不到数据。估计是波特率太高,换低的波特率
;*********************************************
;BAUD_RATE ;250KB/S
; CONFIGURE_MODE
; MOVLW B'00000000' ;BAUD RATE SET
; MOVWF BRGCON1
; MOVLW B'10010000'
; MOVWF BRGCON2
; MOVLW B'00000010'
; MOVWF BRGCON3
; RETURN
;**************BAUD RATE SET******************
; FOSC =4MHZ
; NOMINAL BIT TIME = 8 TQ
; TQ=2*(BAUD RATE +1)/FOSC
; SYN =1 TQ,PRO=1TQ,PHE1=3TQ,PHE2=3TQ
; BAUD RATE= 50KB/S
; BAUD RATE PRESCALER=00100
; fosc =4mhz MAX_baud rate=250kb/s
; If fosc=16Mhz ,the max_band=1Mkb/s
;************************************************
BAUD_RATE ;50KB/S
CONFIGURE_MODE
MOVLW B'00000100' ;BAUD RATE SET
MOVWF BRGCON1
MOVLW B'10010000'
MOVWF BRGCON2
MOVLW B'00000010'
MOVWF BRGCON3
RETURN
;**********CLEAR BANK************************
CLR_BANK
LFSR FSR0,00H ;BANK 0
NEXT CLRF POSTINC0
BTFSS FSR0H,0
GOTO NEXT
LFSR FSR0,100H
NEXT1 CLRF POSTINC0 ;BANK1
BTFSS FSR0H,1
GOTO NEXT1
LFSR FSR0,200H
NEXT2 CLRF POSTINC0 ;BANK 2
BTFSS FSR0H,0
GOTO NEXT2
LFSR FSR0,0F00H
NEXT3 CLRF POSTINC0 ;BANK 15
BTFSS FSR0L,7
GOTO NEXT3
RETURN
DELAY521MS
MOVLW d'255'
MOVWF DELAY1
LOOPA MOVLW d'255'
MOVWF DELAY2
LOOPB
nop
nop
nop
nop
nop
nop
nop
DECFSZ DELAY2
GOTO LOOPB
DECFSZ DELAY1
GOTO LOOPA
RETURN
END |
|