TIMER COUNT를 사용하여 들어오는 신호의 길이를 확인하고 데이터 입력을 받아 저장하는 부분입니다.
RF 수신에서 주로 사용하였습니다.
GET_RXD_RF
MOVLW .7
MOVWF TEMP2
CALL START_TMR0_8US
BTFSC INTCON, T0IF
RETLW .0;에러
CLRWDT
BTFSS RXD_RECEIVER;RXD_RF;싱크헤드시작지점찾기위해H체크
GOTO $-4
CHK_SYNCHEAD_START;┐싱크헤드시작지점하강에지찾음
CALL START_TMR0_8US
BTFSC INTCON,T0IF
RETLW .0;에러
CLRWDT
BTFSC RXD_RECEIVER;RXD_RF
GOTO $-4
CHK_SYNCHEAD_TIME;└────┘싱크헤드구간측정
CALL START_TMR0_8US
BTFSC INTCON,T0IF
RETLW .0;에러
CLRWDT
BTFSS RXD_RECEIVER; RXD_RF
GOTO $-4
MOVF TMR0,W
MOVWF BUF_TMR0
MOVLW .188
SUBWF BUF_TMR0,W
BTFSS STATUS,CF;1500US보다짧으면에러
RETLW .0;에러
MOVLW .250
SUBWF BUF_TMR0,W
BTFSC STATUS,CF;2000US보다길면에러
RETLW .0;에러
CHK_STARTBIT_H;스타트비트H구간시간체크 ┌┐
CALL START_TMR0_4US
BTFSC INTCON,T0IF
RETLW .0;에러
CLRWDT
BTFSC RXD_RECEIVER;RXD_RF
GOTO $-4
MOVF TMR0,W
MOVWF BUF_TMR0
MOVLW .60
SUBWF BUF_TMR0,W
BTFSS STATUS,CF;240US보다짧으면에러
RETLW .0;에러
MOVLW .125
SUBWF BUF_TMR0,W
BTFSC STATUS,CF;500US보다길면에러
RETLW .0;에러
MOVLW BUF_RXD_RF
MOVWF FSR
CHK_EDGE_RXD_RF
INCF FSR
MOVLW .8
MOVWF TEMP1
CHK_EDGE_RXD_RF2
CALL DELAY_500US
CALL START_TMR0_2US
BTFSC RXD_RECEIVER;RXD_RF
GOTO CHK_DOWNEDGE
CHK_UPEDGE
BTFSC INTCON,T0IF
RETLW .0;에러
CLRWDT
BTFSS RXD_RECEIVER;RXD_RF
GOTO $-4
; GOTO $-2
MOVF TMR0,W
MOVWF BUF_TMR0
MOVLW RCONPULSE_SHORT;.50
SUBWF BUF_TMR0,W
BTFSS STATUS,CF;100US보다짧으면에러
RETLW .0;에러
MOVLW .250
SUBWF BUF_TMR0,W
BTFSC STATUS,CF;500US보다길면에러
RETLW .0;에러
BCF STATUS,CF
GOTO GET1BYTE_RXD_RF
CHK_DOWNEDGE
BTFSC INTCON,T0IF
RETLW .0;에러
CLRWDT
BTFSC RXD_RECEIVER;RXD_RF
GOTO $-4
; GOTO $-2
MOVF TMR0,W
MOVWF BUF_TMR0
MOVLW RCONPULSE_SHORT;.50
SUBWF BUF_TMR0,W
BTFSS STATUS,CF;100US보다짧으면에러
RETLW .0;에러
MOVLW RCONPULSE_LONG;.200
SUBWF BUF_TMR0,W
BTFSC STATUS,CF;400US보다길면에러
RETLW .0;에러
BSF STATUS,CF
GET1BYTE_RXD_RF
RRF BUF_RXD_RF
DECFSZ TEMP1
GOTO CHK_EDGE_RXD_RF2
MOVF BUF_RXD_RF,W
MOVWF INDF
DECFSZ TEMP2
GOTO CHK_EDGE_RXD_RF
RETLW .1
START_TMR0_2US
MOVLW B'00000000' ;TMR0 PRE(1:2)타이머0를2분주(4MHz=0.25US,*4CLK,*2분주=2US)
GOTO START_TMR0_INIT
START_TMR0_4US
MOVLW B'00000001' ;TMR0 PRE(1:4)타이머0를4분주(4MHz=0.25US,*4CLK,*4분주=4US)
GOTO START_TMR0_INIT
START_TMR0_8US
MOVLW B'00000010' ;TMR0 PRE(1:8)타이머0를8분주(4MHz=0.25US,*4CLK,*8분주=8US)
START_TMR0_INIT
CLRWDT
SELBANK1
MOVWF OPTIONR
SELBANK0
BCF INTCON,T0IF
CLRF TMR0
BCF INTCON,GIE;전체INT사용중지
BCF INTCON,T0IE;T0INT사용중지
RETURN
'초보의 아웅다웅 설계하기 > PIC' 카테고리의 다른 글
시뮬레이터 실행하기 (0) | 2011.07.12 |
---|---|
포트 설정하기 (0) | 2010.08.03 |
13. 레지스터 설정하기 (0) | 2010.08.02 |
12. 레지스터 정의하기 (0) | 2010.08.02 |
11. 포트 정의하기 (0) | 2010.08.02 |