Home » Archimedes archive » Acorn User » AU 1998-12.adf » Regulars » RTR/SerialIO

RTR/SerialIO

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1998-12.adf » Regulars
Filename: RTR/SerialIO
Read OK:
File size: 11DB bytes
Load address: 0000
Exec address: 0000
File contents
 ;Serial I/O User Port
 ;For an 10 MHz clock
 ;A0 - Serial out
 ;A1 - Serial in
 ;A2 - CTS allows serial input
 ;A3 - RTS output held until this is low
 ;A4 - I/O mode 0 = Input mode   1 = Output mode
 
 ;Note for 16F84 invert the state of the PWRTE
      LIST P=16C84
       
 
 C       EQU     0
 PCL     EQU     2
 Z       EQU     2
 PORTB   EQU     6
 PORTA   EQU     5
 TRISB   EQU     86H
 TRISA   EQU     85H
 EECON1  EQU     88H
 EEDATA  EQU     8
 EEADR   EQU     9
 STATUS  EQU     3
 RP0     EQU     5
 INC     EQU     1
 cts     EQU     2
 rts     EQU     3
 sBuf    EQU    0ch     ;Serial send buffer
 Scount  EQU    0dh     ;Tempory Counter
 Cdown   EQU    0eh     ;Time delay countdown
 rBuf    EQU    0fh     ;Recieve buffer

;
   ORG 0
        GOTO    Start
        
;Recieve a serial byte
Rx      bcf     PORTA,cts       ;Allow for incomming data
        movlw   8               ;Number of data bits to get
        movwf   Scount
Sb      btfsc   PORTA,1         ;Hold until start bit
        goto    Sb
        bsf     PORTA,cts       ;Stop any more incomming
        call    hDelay          ;Half a baud delay
Rnb     bcf     STATUS,C        ;Clear the carry bit
        rrf     rBuf,f          ;Prepare for next bit  
        call    rDelay          ;Full baud delay for recieve
        btfsc   PORTA,1         ;Test input
        bsf     rBuf,7          ;Set if needed
        decfsz  Scount,f        ;See if finished
        goto    Rnb             ;Round again if not
        call    rDelay          ;Allow for stop bit to start
        return
        

;Send a serial byte
Send    btfsc   PORTA,rts       ;Only proceed when rts is low
        goto    Send
        movlw   9               ;Number of data bits to send
        movwf   Scount
        bcf     PORTA,0         ;Start bit
        call    cDelay          ;Extra delay compensation
Sloop   call    Delay
        btfsc   sBuf,0          ;Set the next bit
        bsf     PORTA,0
        btfss   sBuf,0
        bcf     PORTA,0
        rrf     sBuf,f          ;Shift for next time
        decfsz  Scount,f
        goto    Sloop           ;Round until finished
        bsf     PORTA,0         ;Stop bit
        call    cDelay          ;Extra delay compensation
        call    Delay
        call    Delay
        call    cDelay          ;For good measure
        return
        
cDelay  movlw   2               ;Small delay at end of send
        movwf   Cdown           
        goto    Dloop
        
hDelay  movlw   21              ;half delay for serial recieve 10MHz clock
        movwf   Cdown           ; 19,200 Baud rate
        goto    Dloop
        
rDelay  movlw   38              ;Delay for serial recieve 10MHz clock
        movwf   Cdown           ; 19,200 Baud rate
        goto    Dloop
        
Delay   movlw   39              ;Delay for serial send 10MHz clock
        movwf   Cdown           ; 19,200 Baud rate
Dloop   decfsz  Cdown,f
        goto    Dloop
        return
        

Start
        BSF     STATUS,RP0      ;SELECT REGISTER BANK 1
        MOVLW   1Ah             ;Bits 4,3 & 2 inputs
        MOVWF   TRISA^80H
        BCF     STATUS,RP0      ;SELECT REGISTER BANK 0
        BTFSC   PORTA,4         ;See if in input or output mode
        GOTO    InLoop
        
        BSF     STATUS,RP0      ;SELECT REGISTER BANK 1
        MOVLW   0               ;All port B to outputs
        MOVWF   TRISB^80H
        BCF     STATUS,RP0      ;SELECT REGISTER BANK 0
        
        BSF     PORTA,0         ;Serial at Mark
        BSF     PORTA,cts       ;CTS disabled
          

outMain
      call      Rx              ;Get byte to output
      movf      rBuf,w          ;Byte to send
      movwf     PORTB           ;Output it
      movf      PORTB,w         ;Get output state
      movwf     sBuf            ;Ready to output it
      call      Send            ;Send it back to computer
      goto      outMain

InLoop               
       BSF     STATUS,RP0      ;SELECT REGISTER BANK 1
       MOVLW   0ffh            ;All port B to inputs
       MOVWF   TRISB^80H
       BCF     1,7             ;Enable pull up resistors
       BCF     STATUS,RP0      ;SELECT REGISTER BANK 0
        
       BSF     PORTA,0         ;Serial at Mark
       BSF     PORTA,cts       ;CTS disabled
          

inMain
      call      Rx              ;Get byte to initiate read
      movf      PORTB,w         ;Get input state
      movwf     sBuf            ;Ready to output it
      call      Send            ;Send it back to computer
      goto      inMain
        end                
00000000  20 3b 53 65 72 69 61 6c  20 49 2f 4f 20 55 73 65  | ;Serial I/O Use|
00000010  72 20 50 6f 72 74 0a 20  3b 46 6f 72 20 61 6e 20  |r Port. ;For an |
00000020  31 30 20 4d 48 7a 20 63  6c 6f 63 6b 0a 20 3b 41  |10 MHz clock. ;A|
00000030  30 20 2d 20 53 65 72 69  61 6c 20 6f 75 74 0a 20  |0 - Serial out. |
00000040  3b 41 31 20 2d 20 53 65  72 69 61 6c 20 69 6e 0a  |;A1 - Serial in.|
00000050  20 3b 41 32 20 2d 20 43  54 53 20 61 6c 6c 6f 77  | ;A2 - CTS allow|
00000060  73 20 73 65 72 69 61 6c  20 69 6e 70 75 74 0a 20  |s serial input. |
00000070  3b 41 33 20 2d 20 52 54  53 20 6f 75 74 70 75 74  |;A3 - RTS output|
00000080  20 68 65 6c 64 20 75 6e  74 69 6c 20 74 68 69 73  | held until this|
00000090  20 69 73 20 6c 6f 77 0a  20 3b 41 34 20 2d 20 49  | is low. ;A4 - I|
000000a0  2f 4f 20 6d 6f 64 65 20  30 20 3d 20 49 6e 70 75  |/O mode 0 = Inpu|
000000b0  74 20 6d 6f 64 65 20 20  20 31 20 3d 20 4f 75 74  |t mode   1 = Out|
000000c0  70 75 74 20 6d 6f 64 65  0a 20 0a 20 3b 4e 6f 74  |put mode. . ;Not|
000000d0  65 20 66 6f 72 20 31 36  46 38 34 20 69 6e 76 65  |e for 16F84 inve|
000000e0  72 74 20 74 68 65 20 73  74 61 74 65 20 6f 66 20  |rt the state of |
000000f0  74 68 65 20 50 57 52 54  45 0a 20 20 20 20 20 20  |the PWRTE.      |
00000100  4c 49 53 54 20 50 3d 31  36 43 38 34 0a 20 20 20  |LIST P=16C84.   |
00000110  20 20 20 20 0a 20 0a 20  43 20 20 20 20 20 20 20  |    . . C       |
00000120  45 51 55 20 20 20 20 20  30 0a 20 50 43 4c 20 20  |EQU     0. PCL  |
00000130  20 20 20 45 51 55 20 20  20 20 20 32 0a 20 5a 20  |   EQU     2. Z |
00000140  20 20 20 20 20 20 45 51  55 20 20 20 20 20 32 0a  |      EQU     2.|
00000150  20 50 4f 52 54 42 20 20  20 45 51 55 20 20 20 20  | PORTB   EQU    |
00000160  20 36 0a 20 50 4f 52 54  41 20 20 20 45 51 55 20  | 6. PORTA   EQU |
00000170  20 20 20 20 35 0a 20 54  52 49 53 42 20 20 20 45  |    5. TRISB   E|
00000180  51 55 20 20 20 20 20 38  36 48 0a 20 54 52 49 53  |QU     86H. TRIS|
00000190  41 20 20 20 45 51 55 20  20 20 20 20 38 35 48 0a  |A   EQU     85H.|
000001a0  20 45 45 43 4f 4e 31 20  20 45 51 55 20 20 20 20  | EECON1  EQU    |
000001b0  20 38 38 48 0a 20 45 45  44 41 54 41 20 20 45 51  | 88H. EEDATA  EQ|
000001c0  55 20 20 20 20 20 38 0a  20 45 45 41 44 52 20 20  |U     8. EEADR  |
000001d0  20 45 51 55 20 20 20 20  20 39 0a 20 53 54 41 54  | EQU     9. STAT|
000001e0  55 53 20 20 45 51 55 20  20 20 20 20 33 0a 20 52  |US  EQU     3. R|
000001f0  50 30 20 20 20 20 20 45  51 55 20 20 20 20 20 35  |P0     EQU     5|
00000200  0a 20 49 4e 43 20 20 20  20 20 45 51 55 20 20 20  |. INC     EQU   |
00000210  20 20 31 0a 20 63 74 73  20 20 20 20 20 45 51 55  |  1. cts     EQU|
00000220  20 20 20 20 20 32 0a 20  72 74 73 20 20 20 20 20  |     2. rts     |
00000230  45 51 55 20 20 20 20 20  33 0a 20 73 42 75 66 20  |EQU     3. sBuf |
00000240  20 20 20 45 51 55 20 20  20 20 30 63 68 20 20 20  |   EQU    0ch   |
00000250  20 20 3b 53 65 72 69 61  6c 20 73 65 6e 64 20 62  |  ;Serial send b|
00000260  75 66 66 65 72 0a 20 53  63 6f 75 6e 74 20 20 45  |uffer. Scount  E|
00000270  51 55 20 20 20 20 30 64  68 20 20 20 20 20 3b 54  |QU    0dh     ;T|
00000280  65 6d 70 6f 72 79 20 43  6f 75 6e 74 65 72 0a 20  |empory Counter. |
00000290  43 64 6f 77 6e 20 20 20  45 51 55 20 20 20 20 30  |Cdown   EQU    0|
000002a0  65 68 20 20 20 20 20 3b  54 69 6d 65 20 64 65 6c  |eh     ;Time del|
000002b0  61 79 20 63 6f 75 6e 74  64 6f 77 6e 0a 20 72 42  |ay countdown. rB|
000002c0  75 66 20 20 20 20 45 51  55 20 20 20 20 30 66 68  |uf    EQU    0fh|
000002d0  20 20 20 20 20 3b 52 65  63 69 65 76 65 20 62 75  |     ;Recieve bu|
000002e0  66 66 65 72 0a 0a 3b 0a  20 20 20 4f 52 47 20 30  |ffer..;.   ORG 0|
000002f0  0a 20 20 20 20 20 20 20  20 47 4f 54 4f 20 20 20  |.        GOTO   |
00000300  20 53 74 61 72 74 0a 20  20 20 20 20 20 20 20 0a  | Start.        .|
00000310  3b 52 65 63 69 65 76 65  20 61 20 73 65 72 69 61  |;Recieve a seria|
00000320  6c 20 62 79 74 65 0a 52  78 20 20 20 20 20 20 62  |l byte.Rx      b|
00000330  63 66 20 20 20 20 20 50  4f 52 54 41 2c 63 74 73  |cf     PORTA,cts|
00000340  20 20 20 20 20 20 20 3b  41 6c 6c 6f 77 20 66 6f  |       ;Allow fo|
00000350  72 20 69 6e 63 6f 6d 6d  69 6e 67 20 64 61 74 61  |r incomming data|
00000360  0a 20 20 20 20 20 20 20  20 6d 6f 76 6c 77 20 20  |.        movlw  |
00000370  20 38 20 20 20 20 20 20  20 20 20 20 20 20 20 20  | 8              |
00000380  20 3b 4e 75 6d 62 65 72  20 6f 66 20 64 61 74 61  | ;Number of data|
00000390  20 62 69 74 73 20 74 6f  20 67 65 74 0a 20 20 20  | bits to get.   |
000003a0  20 20 20 20 20 6d 6f 76  77 66 20 20 20 53 63 6f  |     movwf   Sco|
000003b0  75 6e 74 0a 53 62 20 20  20 20 20 20 62 74 66 73  |unt.Sb      btfs|
000003c0  63 20 20 20 50 4f 52 54  41 2c 31 20 20 20 20 20  |c   PORTA,1     |
000003d0  20 20 20 20 3b 48 6f 6c  64 20 75 6e 74 69 6c 20  |    ;Hold until |
000003e0  73 74 61 72 74 20 62 69  74 0a 20 20 20 20 20 20  |start bit.      |
000003f0  20 20 67 6f 74 6f 20 20  20 20 53 62 0a 20 20 20  |  goto    Sb.   |
00000400  20 20 20 20 20 62 73 66  20 20 20 20 20 50 4f 52  |     bsf     POR|
00000410  54 41 2c 63 74 73 20 20  20 20 20 20 20 3b 53 74  |TA,cts       ;St|
00000420  6f 70 20 61 6e 79 20 6d  6f 72 65 20 69 6e 63 6f  |op any more inco|
00000430  6d 6d 69 6e 67 0a 20 20  20 20 20 20 20 20 63 61  |mming.        ca|
00000440  6c 6c 20 20 20 20 68 44  65 6c 61 79 20 20 20 20  |ll    hDelay    |
00000450  20 20 20 20 20 20 3b 48  61 6c 66 20 61 20 62 61  |      ;Half a ba|
00000460  75 64 20 64 65 6c 61 79  0a 52 6e 62 20 20 20 20  |ud delay.Rnb    |
00000470  20 62 63 66 20 20 20 20  20 53 54 41 54 55 53 2c  | bcf     STATUS,|
00000480  43 20 20 20 20 20 20 20  20 3b 43 6c 65 61 72 20  |C        ;Clear |
00000490  74 68 65 20 63 61 72 72  79 20 62 69 74 0a 20 20  |the carry bit.  |
000004a0  20 20 20 20 20 20 72 72  66 20 20 20 20 20 72 42  |      rrf     rB|
000004b0  75 66 2c 66 20 20 20 20  20 20 20 20 20 20 3b 50  |uf,f          ;P|
000004c0  72 65 70 61 72 65 20 66  6f 72 20 6e 65 78 74 20  |repare for next |
000004d0  62 69 74 20 20 0a 20 20  20 20 20 20 20 20 63 61  |bit  .        ca|
000004e0  6c 6c 20 20 20 20 72 44  65 6c 61 79 20 20 20 20  |ll    rDelay    |
000004f0  20 20 20 20 20 20 3b 46  75 6c 6c 20 62 61 75 64  |      ;Full baud|
00000500  20 64 65 6c 61 79 20 66  6f 72 20 72 65 63 69 65  | delay for recie|
00000510  76 65 0a 20 20 20 20 20  20 20 20 62 74 66 73 63  |ve.        btfsc|
00000520  20 20 20 50 4f 52 54 41  2c 31 20 20 20 20 20 20  |   PORTA,1      |
00000530  20 20 20 3b 54 65 73 74  20 69 6e 70 75 74 0a 20  |   ;Test input. |
00000540  20 20 20 20 20 20 20 62  73 66 20 20 20 20 20 72  |       bsf     r|
00000550  42 75 66 2c 37 20 20 20  20 20 20 20 20 20 20 3b  |Buf,7          ;|
00000560  53 65 74 20 69 66 20 6e  65 65 64 65 64 0a 20 20  |Set if needed.  |
00000570  20 20 20 20 20 20 64 65  63 66 73 7a 20 20 53 63  |      decfsz  Sc|
00000580  6f 75 6e 74 2c 66 20 20  20 20 20 20 20 20 3b 53  |ount,f        ;S|
00000590  65 65 20 69 66 20 66 69  6e 69 73 68 65 64 0a 20  |ee if finished. |
000005a0  20 20 20 20 20 20 20 67  6f 74 6f 20 20 20 20 52  |       goto    R|
000005b0  6e 62 20 20 20 20 20 20  20 20 20 20 20 20 20 3b  |nb             ;|
000005c0  52 6f 75 6e 64 20 61 67  61 69 6e 20 69 66 20 6e  |Round again if n|
000005d0  6f 74 0a 20 20 20 20 20  20 20 20 63 61 6c 6c 20  |ot.        call |
000005e0  20 20 20 72 44 65 6c 61  79 20 20 20 20 20 20 20  |   rDelay       |
000005f0  20 20 20 3b 41 6c 6c 6f  77 20 66 6f 72 20 73 74  |   ;Allow for st|
00000600  6f 70 20 62 69 74 20 74  6f 20 73 74 61 72 74 0a  |op bit to start.|
00000610  20 20 20 20 20 20 20 20  72 65 74 75 72 6e 0a 20  |        return. |
00000620  20 20 20 20 20 20 20 0a  0a 3b 53 65 6e 64 20 61  |       ..;Send a|
00000630  20 73 65 72 69 61 6c 20  62 79 74 65 0a 53 65 6e  | serial byte.Sen|
00000640  64 20 20 20 20 62 74 66  73 63 20 20 20 50 4f 52  |d    btfsc   POR|
00000650  54 41 2c 72 74 73 20 20  20 20 20 20 20 3b 4f 6e  |TA,rts       ;On|
00000660  6c 79 20 70 72 6f 63 65  65 64 20 77 68 65 6e 20  |ly proceed when |
00000670  72 74 73 20 69 73 20 6c  6f 77 0a 20 20 20 20 20  |rts is low.     |
00000680  20 20 20 67 6f 74 6f 20  20 20 20 53 65 6e 64 0a  |   goto    Send.|
00000690  20 20 20 20 20 20 20 20  6d 6f 76 6c 77 20 20 20  |        movlw   |
000006a0  39 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |9               |
000006b0  3b 4e 75 6d 62 65 72 20  6f 66 20 64 61 74 61 20  |;Number of data |
000006c0  62 69 74 73 20 74 6f 20  73 65 6e 64 0a 20 20 20  |bits to send.   |
000006d0  20 20 20 20 20 6d 6f 76  77 66 20 20 20 53 63 6f  |     movwf   Sco|
000006e0  75 6e 74 0a 20 20 20 20  20 20 20 20 62 63 66 20  |unt.        bcf |
000006f0  20 20 20 20 50 4f 52 54  41 2c 30 20 20 20 20 20  |    PORTA,0     |
00000700  20 20 20 20 3b 53 74 61  72 74 20 62 69 74 0a 20  |    ;Start bit. |
00000710  20 20 20 20 20 20 20 63  61 6c 6c 20 20 20 20 63  |       call    c|
00000720  44 65 6c 61 79 20 20 20  20 20 20 20 20 20 20 3b  |Delay          ;|
00000730  45 78 74 72 61 20 64 65  6c 61 79 20 63 6f 6d 70  |Extra delay comp|
00000740  65 6e 73 61 74 69 6f 6e  0a 53 6c 6f 6f 70 20 20  |ensation.Sloop  |
00000750  20 63 61 6c 6c 20 20 20  20 44 65 6c 61 79 0a 20  | call    Delay. |
00000760  20 20 20 20 20 20 20 62  74 66 73 63 20 20 20 73  |       btfsc   s|
00000770  42 75 66 2c 30 20 20 20  20 20 20 20 20 20 20 3b  |Buf,0          ;|
00000780  53 65 74 20 74 68 65 20  6e 65 78 74 20 62 69 74  |Set the next bit|
00000790  0a 20 20 20 20 20 20 20  20 62 73 66 20 20 20 20  |.        bsf    |
000007a0  20 50 4f 52 54 41 2c 30  0a 20 20 20 20 20 20 20  | PORTA,0.       |
000007b0  20 62 74 66 73 73 20 20  20 73 42 75 66 2c 30 0a  | btfss   sBuf,0.|
000007c0  20 20 20 20 20 20 20 20  62 63 66 20 20 20 20 20  |        bcf     |
000007d0  50 4f 52 54 41 2c 30 0a  20 20 20 20 20 20 20 20  |PORTA,0.        |
000007e0  72 72 66 20 20 20 20 20  73 42 75 66 2c 66 20 20  |rrf     sBuf,f  |
000007f0  20 20 20 20 20 20 20 20  3b 53 68 69 66 74 20 66  |        ;Shift f|
00000800  6f 72 20 6e 65 78 74 20  74 69 6d 65 0a 20 20 20  |or next time.   |
00000810  20 20 20 20 20 64 65 63  66 73 7a 20 20 53 63 6f  |     decfsz  Sco|
00000820  75 6e 74 2c 66 0a 20 20  20 20 20 20 20 20 67 6f  |unt,f.        go|
00000830  74 6f 20 20 20 20 53 6c  6f 6f 70 20 20 20 20 20  |to    Sloop     |
00000840  20 20 20 20 20 20 3b 52  6f 75 6e 64 20 75 6e 74  |      ;Round unt|
00000850  69 6c 20 66 69 6e 69 73  68 65 64 0a 20 20 20 20  |il finished.    |
00000860  20 20 20 20 62 73 66 20  20 20 20 20 50 4f 52 54  |    bsf     PORT|
00000870  41 2c 30 20 20 20 20 20  20 20 20 20 3b 53 74 6f  |A,0         ;Sto|
00000880  70 20 62 69 74 0a 20 20  20 20 20 20 20 20 63 61  |p bit.        ca|
00000890  6c 6c 20 20 20 20 63 44  65 6c 61 79 20 20 20 20  |ll    cDelay    |
000008a0  20 20 20 20 20 20 3b 45  78 74 72 61 20 64 65 6c  |      ;Extra del|
000008b0  61 79 20 63 6f 6d 70 65  6e 73 61 74 69 6f 6e 0a  |ay compensation.|
000008c0  20 20 20 20 20 20 20 20  63 61 6c 6c 20 20 20 20  |        call    |
000008d0  44 65 6c 61 79 0a 20 20  20 20 20 20 20 20 63 61  |Delay.        ca|
000008e0  6c 6c 20 20 20 20 44 65  6c 61 79 0a 20 20 20 20  |ll    Delay.    |
000008f0  20 20 20 20 63 61 6c 6c  20 20 20 20 63 44 65 6c  |    call    cDel|
00000900  61 79 20 20 20 20 20 20  20 20 20 20 3b 46 6f 72  |ay          ;For|
00000910  20 67 6f 6f 64 20 6d 65  61 73 75 72 65 0a 20 20  | good measure.  |
00000920  20 20 20 20 20 20 72 65  74 75 72 6e 0a 20 20 20  |      return.   |
00000930  20 20 20 20 20 0a 63 44  65 6c 61 79 20 20 6d 6f  |     .cDelay  mo|
00000940  76 6c 77 20 20 20 32 20  20 20 20 20 20 20 20 20  |vlw   2         |
00000950  20 20 20 20 20 20 3b 53  6d 61 6c 6c 20 64 65 6c  |      ;Small del|
00000960  61 79 20 61 74 20 65 6e  64 20 6f 66 20 73 65 6e  |ay at end of sen|
00000970  64 0a 20 20 20 20 20 20  20 20 6d 6f 76 77 66 20  |d.        movwf |
00000980  20 20 43 64 6f 77 6e 20  20 20 20 20 20 20 20 20  |  Cdown         |
00000990  20 20 0a 20 20 20 20 20  20 20 20 67 6f 74 6f 20  |  .        goto |
000009a0  20 20 20 44 6c 6f 6f 70  0a 20 20 20 20 20 20 20  |   Dloop.       |
000009b0  20 0a 68 44 65 6c 61 79  20 20 6d 6f 76 6c 77 20  | .hDelay  movlw |
000009c0  20 20 32 31 20 20 20 20  20 20 20 20 20 20 20 20  |  21            |
000009d0  20 20 3b 68 61 6c 66 20  64 65 6c 61 79 20 66 6f  |  ;half delay fo|
000009e0  72 20 73 65 72 69 61 6c  20 72 65 63 69 65 76 65  |r serial recieve|
000009f0  20 31 30 4d 48 7a 20 63  6c 6f 63 6b 0a 20 20 20  | 10MHz clock.   |
00000a00  20 20 20 20 20 6d 6f 76  77 66 20 20 20 43 64 6f  |     movwf   Cdo|
00000a10  77 6e 20 20 20 20 20 20  20 20 20 20 20 3b 20 31  |wn           ; 1|
00000a20  39 2c 32 30 30 20 42 61  75 64 20 72 61 74 65 0a  |9,200 Baud rate.|
00000a30  20 20 20 20 20 20 20 20  67 6f 74 6f 20 20 20 20  |        goto    |
00000a40  44 6c 6f 6f 70 0a 20 20  20 20 20 20 20 20 0a 72  |Dloop.        .r|
00000a50  44 65 6c 61 79 20 20 6d  6f 76 6c 77 20 20 20 33  |Delay  movlw   3|
00000a60  38 20 20 20 20 20 20 20  20 20 20 20 20 20 20 3b  |8              ;|
00000a70  44 65 6c 61 79 20 66 6f  72 20 73 65 72 69 61 6c  |Delay for serial|
00000a80  20 72 65 63 69 65 76 65  20 31 30 4d 48 7a 20 63  | recieve 10MHz c|
00000a90  6c 6f 63 6b 0a 20 20 20  20 20 20 20 20 6d 6f 76  |lock.        mov|
00000aa0  77 66 20 20 20 43 64 6f  77 6e 20 20 20 20 20 20  |wf   Cdown      |
00000ab0  20 20 20 20 20 3b 20 31  39 2c 32 30 30 20 42 61  |     ; 19,200 Ba|
00000ac0  75 64 20 72 61 74 65 0a  20 20 20 20 20 20 20 20  |ud rate.        |
00000ad0  67 6f 74 6f 20 20 20 20  44 6c 6f 6f 70 0a 20 20  |goto    Dloop.  |
00000ae0  20 20 20 20 20 20 0a 44  65 6c 61 79 20 20 20 6d  |      .Delay   m|
00000af0  6f 76 6c 77 20 20 20 33  39 20 20 20 20 20 20 20  |ovlw   39       |
00000b00  20 20 20 20 20 20 20 3b  44 65 6c 61 79 20 66 6f  |       ;Delay fo|
00000b10  72 20 73 65 72 69 61 6c  20 73 65 6e 64 20 31 30  |r serial send 10|
00000b20  4d 48 7a 20 63 6c 6f 63  6b 0a 20 20 20 20 20 20  |MHz clock.      |
00000b30  20 20 6d 6f 76 77 66 20  20 20 43 64 6f 77 6e 20  |  movwf   Cdown |
00000b40  20 20 20 20 20 20 20 20  20 20 3b 20 31 39 2c 32  |          ; 19,2|
00000b50  30 30 20 42 61 75 64 20  72 61 74 65 0a 44 6c 6f  |00 Baud rate.Dlo|
00000b60  6f 70 20 20 20 64 65 63  66 73 7a 20 20 43 64 6f  |op   decfsz  Cdo|
00000b70  77 6e 2c 66 0a 20 20 20  20 20 20 20 20 67 6f 74  |wn,f.        got|
00000b80  6f 20 20 20 20 44 6c 6f  6f 70 0a 20 20 20 20 20  |o    Dloop.     |
00000b90  20 20 20 72 65 74 75 72  6e 0a 20 20 20 20 20 20  |   return.      |
00000ba0  20 20 0a 0a 53 74 61 72  74 0a 20 20 20 20 20 20  |  ..Start.      |
00000bb0  20 20 42 53 46 20 20 20  20 20 53 54 41 54 55 53  |  BSF     STATUS|
00000bc0  2c 52 50 30 20 20 20 20  20 20 3b 53 45 4c 45 43  |,RP0      ;SELEC|
00000bd0  54 20 52 45 47 49 53 54  45 52 20 42 41 4e 4b 20  |T REGISTER BANK |
00000be0  31 0a 20 20 20 20 20 20  20 20 4d 4f 56 4c 57 20  |1.        MOVLW |
00000bf0  20 20 31 41 68 20 20 20  20 20 20 20 20 20 20 20  |  1Ah           |
00000c00  20 20 3b 42 69 74 73 20  34 2c 33 20 26 20 32 20  |  ;Bits 4,3 & 2 |
00000c10  69 6e 70 75 74 73 0a 20  20 20 20 20 20 20 20 4d  |inputs.        M|
00000c20  4f 56 57 46 20 20 20 54  52 49 53 41 5e 38 30 48  |OVWF   TRISA^80H|
00000c30  0a 20 20 20 20 20 20 20  20 42 43 46 20 20 20 20  |.        BCF    |
00000c40  20 53 54 41 54 55 53 2c  52 50 30 20 20 20 20 20  | STATUS,RP0     |
00000c50  20 3b 53 45 4c 45 43 54  20 52 45 47 49 53 54 45  | ;SELECT REGISTE|
00000c60  52 20 42 41 4e 4b 20 30  0a 20 20 20 20 20 20 20  |R BANK 0.       |
00000c70  20 42 54 46 53 43 20 20  20 50 4f 52 54 41 2c 34  | BTFSC   PORTA,4|
00000c80  20 20 20 20 20 20 20 20  20 3b 53 65 65 20 69 66  |         ;See if|
00000c90  20 69 6e 20 69 6e 70 75  74 20 6f 72 20 6f 75 74  | in input or out|
00000ca0  70 75 74 20 6d 6f 64 65  0a 20 20 20 20 20 20 20  |put mode.       |
00000cb0  20 47 4f 54 4f 20 20 20  20 49 6e 4c 6f 6f 70 0a  | GOTO    InLoop.|
00000cc0  20 20 20 20 20 20 20 20  0a 20 20 20 20 20 20 20  |        .       |
00000cd0  20 42 53 46 20 20 20 20  20 53 54 41 54 55 53 2c  | BSF     STATUS,|
00000ce0  52 50 30 20 20 20 20 20  20 3b 53 45 4c 45 43 54  |RP0      ;SELECT|
00000cf0  20 52 45 47 49 53 54 45  52 20 42 41 4e 4b 20 31  | REGISTER BANK 1|
00000d00  0a 20 20 20 20 20 20 20  20 4d 4f 56 4c 57 20 20  |.        MOVLW  |
00000d10  20 30 20 20 20 20 20 20  20 20 20 20 20 20 20 20  | 0              |
00000d20  20 3b 41 6c 6c 20 70 6f  72 74 20 42 20 74 6f 20  | ;All port B to |
00000d30  6f 75 74 70 75 74 73 0a  20 20 20 20 20 20 20 20  |outputs.        |
00000d40  4d 4f 56 57 46 20 20 20  54 52 49 53 42 5e 38 30  |MOVWF   TRISB^80|
00000d50  48 0a 20 20 20 20 20 20  20 20 42 43 46 20 20 20  |H.        BCF   |
00000d60  20 20 53 54 41 54 55 53  2c 52 50 30 20 20 20 20  |  STATUS,RP0    |
00000d70  20 20 3b 53 45 4c 45 43  54 20 52 45 47 49 53 54  |  ;SELECT REGIST|
00000d80  45 52 20 42 41 4e 4b 20  30 0a 20 20 20 20 20 20  |ER BANK 0.      |
00000d90  20 20 0a 20 20 20 20 20  20 20 20 42 53 46 20 20  |  .        BSF  |
00000da0  20 20 20 50 4f 52 54 41  2c 30 20 20 20 20 20 20  |   PORTA,0      |
00000db0  20 20 20 3b 53 65 72 69  61 6c 20 61 74 20 4d 61  |   ;Serial at Ma|
00000dc0  72 6b 0a 20 20 20 20 20  20 20 20 42 53 46 20 20  |rk.        BSF  |
00000dd0  20 20 20 50 4f 52 54 41  2c 63 74 73 20 20 20 20  |   PORTA,cts    |
00000de0  20 20 20 3b 43 54 53 20  64 69 73 61 62 6c 65 64  |   ;CTS disabled|
00000df0  0a 20 20 20 20 20 20 20  20 20 20 0a 0a 6f 75 74  |.          ..out|
00000e00  4d 61 69 6e 0a 20 20 20  20 20 20 63 61 6c 6c 20  |Main.      call |
00000e10  20 20 20 20 20 52 78 20  20 20 20 20 20 20 20 20  |     Rx         |
00000e20  20 20 20 20 20 3b 47 65  74 20 62 79 74 65 20 74  |     ;Get byte t|
00000e30  6f 20 6f 75 74 70 75 74  0a 20 20 20 20 20 20 6d  |o output.      m|
00000e40  6f 76 66 20 20 20 20 20  20 72 42 75 66 2c 77 20  |ovf      rBuf,w |
00000e50  20 20 20 20 20 20 20 20  20 3b 42 79 74 65 20 74  |         ;Byte t|
00000e60  6f 20 73 65 6e 64 0a 20  20 20 20 20 20 6d 6f 76  |o send.      mov|
00000e70  77 66 20 20 20 20 20 50  4f 52 54 42 20 20 20 20  |wf     PORTB    |
00000e80  20 20 20 20 20 20 20 3b  4f 75 74 70 75 74 20 69  |       ;Output i|
00000e90  74 0a 20 20 20 20 20 20  6d 6f 76 66 20 20 20 20  |t.      movf    |
00000ea0  20 20 50 4f 52 54 42 2c  77 20 20 20 20 20 20 20  |  PORTB,w       |
00000eb0  20 20 3b 47 65 74 20 6f  75 74 70 75 74 20 73 74  |  ;Get output st|
00000ec0  61 74 65 0a 20 20 20 20  20 20 6d 6f 76 77 66 20  |ate.      movwf |
00000ed0  20 20 20 20 73 42 75 66  20 20 20 20 20 20 20 20  |    sBuf        |
00000ee0  20 20 20 20 3b 52 65 61  64 79 20 74 6f 20 6f 75  |    ;Ready to ou|
00000ef0  74 70 75 74 20 69 74 0a  20 20 20 20 20 20 63 61  |tput it.      ca|
00000f00  6c 6c 20 20 20 20 20 20  53 65 6e 64 20 20 20 20  |ll      Send    |
00000f10  20 20 20 20 20 20 20 20  3b 53 65 6e 64 20 69 74  |        ;Send it|
00000f20  20 62 61 63 6b 20 74 6f  20 63 6f 6d 70 75 74 65  | back to compute|
00000f30  72 0a 20 20 20 20 20 20  67 6f 74 6f 20 20 20 20  |r.      goto    |
00000f40  20 20 6f 75 74 4d 61 69  6e 0a 0a 49 6e 4c 6f 6f  |  outMain..InLoo|
00000f50  70 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |p               |
00000f60  0a 20 20 20 20 20 20 20  42 53 46 20 20 20 20 20  |.       BSF     |
00000f70  53 54 41 54 55 53 2c 52  50 30 20 20 20 20 20 20  |STATUS,RP0      |
00000f80  3b 53 45 4c 45 43 54 20  52 45 47 49 53 54 45 52  |;SELECT REGISTER|
00000f90  20 42 41 4e 4b 20 31 0a  20 20 20 20 20 20 20 4d  | BANK 1.       M|
00000fa0  4f 56 4c 57 20 20 20 30  66 66 68 20 20 20 20 20  |OVLW   0ffh     |
00000fb0  20 20 20 20 20 20 20 3b  41 6c 6c 20 70 6f 72 74  |       ;All port|
00000fc0  20 42 20 74 6f 20 69 6e  70 75 74 73 0a 20 20 20  | B to inputs.   |
00000fd0  20 20 20 20 4d 4f 56 57  46 20 20 20 54 52 49 53  |    MOVWF   TRIS|
00000fe0  42 5e 38 30 48 0a 20 20  20 20 20 20 20 42 43 46  |B^80H.       BCF|
00000ff0  20 20 20 20 20 31 2c 37  20 20 20 20 20 20 20 20  |     1,7        |
00001000  20 20 20 20 20 3b 45 6e  61 62 6c 65 20 70 75 6c  |     ;Enable pul|
00001010  6c 20 75 70 20 72 65 73  69 73 74 6f 72 73 0a 20  |l up resistors. |
00001020  20 20 20 20 20 20 42 43  46 20 20 20 20 20 53 54  |      BCF     ST|
00001030  41 54 55 53 2c 52 50 30  20 20 20 20 20 20 3b 53  |ATUS,RP0      ;S|
00001040  45 4c 45 43 54 20 52 45  47 49 53 54 45 52 20 42  |ELECT REGISTER B|
00001050  41 4e 4b 20 30 0a 20 20  20 20 20 20 20 20 0a 20  |ANK 0.        . |
00001060  20 20 20 20 20 20 42 53  46 20 20 20 20 20 50 4f  |      BSF     PO|
00001070  52 54 41 2c 30 20 20 20  20 20 20 20 20 20 3b 53  |RTA,0         ;S|
00001080  65 72 69 61 6c 20 61 74  20 4d 61 72 6b 0a 20 20  |erial at Mark.  |
00001090  20 20 20 20 20 42 53 46  20 20 20 20 20 50 4f 52  |     BSF     POR|
000010a0  54 41 2c 63 74 73 20 20  20 20 20 20 20 3b 43 54  |TA,cts       ;CT|
000010b0  53 20 64 69 73 61 62 6c  65 64 0a 20 20 20 20 20  |S disabled.     |
000010c0  20 20 20 20 20 0a 0a 69  6e 4d 61 69 6e 0a 20 20  |     ..inMain.  |
000010d0  20 20 20 20 63 61 6c 6c  20 20 20 20 20 20 52 78  |    call      Rx|
000010e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 3b 47  |              ;G|
000010f0  65 74 20 62 79 74 65 20  74 6f 20 69 6e 69 74 69  |et byte to initi|
00001100  61 74 65 20 72 65 61 64  0a 20 20 20 20 20 20 6d  |ate read.      m|
00001110  6f 76 66 20 20 20 20 20  20 50 4f 52 54 42 2c 77  |ovf      PORTB,w|
00001120  20 20 20 20 20 20 20 20  20 3b 47 65 74 20 69 6e  |         ;Get in|
00001130  70 75 74 20 73 74 61 74  65 0a 20 20 20 20 20 20  |put state.      |
00001140  6d 6f 76 77 66 20 20 20  20 20 73 42 75 66 20 20  |movwf     sBuf  |
00001150  20 20 20 20 20 20 20 20  20 20 3b 52 65 61 64 79  |          ;Ready|
00001160  20 74 6f 20 6f 75 74 70  75 74 20 69 74 0a 20 20  | to output it.  |
00001170  20 20 20 20 63 61 6c 6c  20 20 20 20 20 20 53 65  |    call      Se|
00001180  6e 64 20 20 20 20 20 20  20 20 20 20 20 20 3b 53  |nd            ;S|
00001190  65 6e 64 20 69 74 20 62  61 63 6b 20 74 6f 20 63  |end it back to c|
000011a0  6f 6d 70 75 74 65 72 0a  20 20 20 20 20 20 67 6f  |omputer.      go|
000011b0  74 6f 20 20 20 20 20 20  69 6e 4d 61 69 6e 0a 20  |to      inMain. |
000011c0  20 20 20 20 20 20 20 65  6e 64 20 20 20 20 20 20  |       end      |
000011d0  20 20 20 20 20 20 20 20  20 20 0a                 |          .|
000011db