list p=16c84 include "p16c84.inc" count equ 0x0c bit equ 0x0d i equ 0x0e d equ 0x0f parity equ 0x10 cardsel equ 0x11 errorlevel -302 ; Start at the reset vector org 0x000 start banksel OPTION_REG bcf OPTION_REG, NOT_RBPU banksel PORTB retmain banksel OPTION_REG bsf PORTB, 6 bsf PORTB, 7 banksel PORTB main btfss PORTB, 0 goto zerobits btfss PORTB, 1 goto card1 btfss PORTB, 2 goto card2 btfss PORTB, 3 goto card3 goto main card1 movlw 0 movwf cardsel goto testpattern card2 movlw p2-p1 movwf cardsel goto testpattern card3 movlw p3-p1 movwf cardsel goto testpattern ; --------------------------------------------------------------------------------- ; - Send 0-bits ; --------------------------------------------------------------------------------- zerobits banksel OPTION_REG bcf PORTB, 6 bcf PORTB, 7 banksel PORTB bsf PORTB, 6 bcf PORTB, 7 zb_loop call sendbit0 btfss PORTB, 0 goto zb_loop goto retmain ; --------------------------------------------------------------------------------- ; - Test pattern ; --------------------------------------------------------------------------------- testpattern banksel OPTION_REG bcf PORTB, 6 bcf PORTB, 7 banksel PORTB bsf PORTB, 6 bcf PORTB, 7 movlw 0x10 movwf i tp_init ; Send 16 0-bits call sendbit0 decfsz i, f goto tp_init movf cardsel, w movwf i clrf parity tp_loop movf i, w call getpattern andlw 0xff btfsc STATUS, Z goto tp_endloop andlw 0x0f movwf d xorwf parity, f bsf parity, 7 movlw 0x04 movwf bit tp_bit_loop btfsc d, 0 call sendbit1 btfss d, 0 call sendbit0 movlw 0x80 btfsc d, 0 xorwf parity, f rrf d, f decfsz bit, f goto tp_bit_loop btfsc parity, 7 call sendbit1 btfss parity, 7 call sendbit0 incf i, f goto tp_loop tp_endloop movlw 0x10 movwf i tp_deinit ; Send 16 0-bits call sendbit0 decfsz i, f goto tp_deinit waitforreturn0 clrf i waitforreturn btfss PORTB, 3 goto waitforreturn0 btfss PORTB, 2 goto waitforreturn0 btfss PORTB, 1 goto waitforreturn0 decfsz i, f goto waitforreturn goto retmain ; --------------------------------------------------------------------------------- ; - Send 1-bit ; --------------------------------------------------------------------------------- sendbit1 clrf count call delay movlw 0xc0 xorwf PORTB, f clrf count call delay xorwf PORTB, f return ; --------------------------------------------------------------------------------- ; - Send 0-bit ; --------------------------------------------------------------------------------- sendbit0 clrf count call delay call delay movlw 0xc0 xorwf PORTB, f return ; --------------------------------------------------------------------------------- ; - Delay count * 8 us ; --------------------------------------------------------------------------------- delay nop nop nop nop nop decfsz count, f goto delay return org 0x300 getpattern bsf PCLATH, 0 bsf PCLATH, 1 addwf PCL, f p1 dt ";199760057?6", 0 p2 dt "", 0 p3 dt "", 0 __config _CP_OFF & _PWRTE_OFF & _WDT_OFF & _XT_OSC end