home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 9 / AU_CD9.iso / Cover_Discs / Back_Issues / 1998_13 / Regulars / RTR / LEDtst next >
Text File  |  1998-10-09  |  8KB  |  264 lines

  1.  ;Multiplexed LED matrix display test
  2.  ;For an 10 MHz clock
  3.  ;A0 - Serial out
  4.  ;A1 - Serial in
  5.  ;A2 - CTS allows serial input
  6.  ;A3 - RTS output held until this is low
  7.  
  8.  ;Note for 16F84 invert the state of the PWRTE
  9.       LIST P=16C84
  10.        
  11.  
  12.  C       EQU     0
  13.  PCL     EQU     2
  14.  Z       EQU     2
  15.  PORTB   EQU     6
  16.  PORTA   EQU     5
  17.  TRISB   EQU     86H
  18.  TRISA   EQU     85H
  19.  EECON1  EQU     88H
  20.  EEDATA  EQU     8
  21.  INTCON  EQU     0bH
  22.  EEADR   EQU     9
  23.  STATUS  EQU     3
  24.  RP0     EQU     5
  25.  INC     EQU     1
  26.  cts     EQU     2
  27.  rts     EQU     3
  28.  ; Output bits
  29.  cdat    EQU     1      ;Coloum data
  30.  cck     EQU     2      ;Coloum clock
  31.  rclr    EQU     3      ;Row clear
  32.  rck     EQU     4      ;Row clock
  33.  rdat    EQU     5      ;Row data
  34.  
  35.  sBuf    EQU    0ch     ;Serial send buffer
  36.  Scount  EQU    0dh     ;Tempory Counter
  37.  Cdown   EQU    0eh     ;Time delay countdown
  38.  rBuf    EQU    0fh     ;Recieve buffer
  39.  ScanNo  EQU    10h     ;Number of row we are on
  40.  RowC    EQU    11h     ;Row counter
  41.  Sstore  EQU    12h     ;Scrole store
  42.  Com1    EQU    13h     ;Command 1
  43.  Com2    EQU    14h     ;Command 2
  44.  save_w  EQU    15h     ;save w reg
  45.  save_s  EQU    16H     ;save status
  46.  save_p  EQU    17h     ;save port LEDs
  47.  DisBuf  EQU    1Ah     ;Display buffer
  48.  
  49.  
  50. ;
  51.    ORG 0
  52.         GOTO    Start
  53.   ORG 4
  54.         movwf   save_w          ;save w and s regs
  55.         swapf   STATUS,w        ;swapf doesn't affect Z like movf
  56.         movwf   save_s
  57.         movf    PORTB,w         ;Save state of LEDs
  58.         movwf   save_p
  59.         clrf    PORTB           ;Turn LEDs off
  60.  
  61.         call    Rx              ;Recieve byte
  62.         incf    Com2,f          ;Increment the data to put in
  63.         call    sleft           ;Scroll left command
  64.  
  65. out     movf    save_p,w
  66.         movwf   PORTB           ;Turn LEDs back on        
  67.         swapf   save_s,w
  68.         movwf   STATUS          ; restore registers
  69.         swapf   save_w,f
  70.         swapf   save_w,w
  71.         bcf     INTCON,1        ;Clear edge interrupt
  72.         retfie
  73.  
  74.              
  75. ;Recieve a serial byte
  76. Rx      movlw   8               ;Number of data bits to get
  77.         movwf   Scount
  78. Sb      btfsc   PORTA,1         ;Hold until start bit
  79.         goto    Sb
  80.         call    hDelay          ;Half a baud delay
  81. Rnb     bcf     STATUS,C        ;Clear the carry bit
  82.         rrf     rBuf,f          ;Prepare for next bit  
  83.         call    rDelay          ;Full baud delay for recieve
  84.         btfsc   PORTA,1         ;Test input
  85.         bsf     rBuf,7          ;Set if needed
  86.         decfsz  Scount,f        ;See if finished
  87.         goto    Rnb             ;Round again if not
  88.         call    rDelay          ;Allow for stop bit to start
  89.         movf    rBuf,w          ;Put recieved chractor into W
  90.         return
  91.         
  92.  
  93. ;Send a serial byte
  94. Send    btfsc   PORTA,rts       ;Only proceed when rts is low
  95.         goto    Send
  96.         movlw   9               ;Number of data bits to send
  97.         movwf   Scount
  98.         bcf     PORTA,0         ;Start bit
  99.         call    cDelay          ;Extra delay compensation
  100. Sloop   call    Delay
  101.         btfsc   sBuf,0          ;Set the next bit
  102.         bsf     PORTA,0
  103.         btfss   sBuf,0
  104.         bcf     PORTA,0
  105.         rrf     sBuf,f          ;Shift for next time
  106.         decfsz  Scount,f
  107.         goto    Sloop           ;Round until finished
  108.         bsf     PORTA,0         ;Stop bit
  109.         call    cDelay          ;Extra delay compensation
  110.         call    Delay
  111.         call    Delay
  112.         call    cDelay          ;For good measure
  113.         return
  114.         
  115. cDelay  movlw   2               ;Small delay at end of send
  116.         movwf   Cdown           
  117.         goto    Dloop
  118.         
  119. hDelay  movlw   21              ;half delay for serial recieve 10MHz clock
  120.         movwf   Cdown           ; 19,200 Baud rate
  121.         goto    Dloop
  122.         
  123. rDelay  movlw   38              ;Delay for serial recieve 10MHz clock
  124.         movwf   Cdown           ; 19,200 Baud rate
  125.         goto    Dloop
  126.         
  127. Delay   movlw   39              ;Delay for serial send 10MHz clock
  128.         movwf   Cdown           ; 19,200 Baud rate
  129. Dloop   decfsz  Cdown,f
  130.         goto    Dloop
  131.         return
  132.         
  133.  
  134. Start
  135.         BSF     STATUS,RP0      ;SELECT REGISTER BANK 1
  136.         MOVLW   1Ah             ;Bits 4,3 & 2 inputs
  137.         MOVWF   TRISA^80H
  138.         MOVLW   1               ;Bit 0 input rest outputs
  139.         MOVWF   TRISB^80H
  140.         MOVLW   3               ;16 prescaler -ve edge interrupt
  141.         MOVWF   1               ;Option register
  142.         MOVLW   90H             ;Enable bit 0 interrupt
  143.         MOVWF   INTCON
  144.  
  145.         BCF     STATUS,RP0      ;SELECT REGISTER BANK 0
  146.         
  147.         BSF     PORTA,0         ;Serial at Mark
  148.         BCF     PORTA,cts       ;CTS enabled
  149.         CLRF    PORTB
  150.         CLRF    ScanNo
  151.         CLRF    Com2
  152.         
  153. ;Just put some test data into some memory
  154.         movlw   0AAh
  155.         movwf    DisBuf
  156.         movwf    DisBuf!1
  157.         movwf    DisBuf!2
  158.         
  159.         movwf    DisBuf!6
  160.         movwf    DisBuf!7
  161.         movwf    DisBuf!8
  162.         
  163.         movwf    DisBuf!12
  164.         movwf    DisBuf!13
  165.         movwf    DisBuf!14
  166.         
  167.         movwf    DisBuf!18
  168.         movwf    DisBuf!19
  169.         movwf    DisBuf!20
  170.  
  171.         movlw   055h
  172.         movwf    DisBuf!3
  173.         movwf    DisBuf!4
  174.         movwf    DisBuf!5
  175.         
  176.         movwf    DisBuf!9
  177.         movwf    DisBuf!10
  178.         movwf    DisBuf!11
  179.         
  180.         movwf    DisBuf!15
  181.         movwf    DisBuf!16
  182.         movwf    DisBuf!17
  183.   
  184. Main    btfss   0bh,2           ;Test timer
  185.         GOTO    Main            ;Loop until time
  186.         bcf     0bh,2           ;Clear it for next time
  187.         incf    ScanNo,f
  188.         movlw   7               ;See if it is at end
  189.         subwf   ScanNo,w
  190.         btfsc   STATUS,Z        ;Wrap it round after 7
  191.         clrf    ScanNo
  192.         call    scan 
  193.         GOTO    Main
  194.         
  195. scan    clrf    PORTB           ; Blank out row
  196.         bcf     STATUS,C
  197.         rlf     ScanNo,w        ;Scan No * 3 + DisBuf = reg address
  198.         addwf   ScanNo,w
  199.         addlw   DisBuf
  200.         movwf   4               ;to indirect register
  201.         call    rbout           ;Output first byte
  202.         incf    4,f             ;Next byte
  203.         call    rbout
  204.         incf    4,f             ;Last byte
  205.         call    hrout
  206.         movf    ScanNo,w
  207.         movwf   RowC             ;Row Count
  208.         incf    RowC,f           ;One more pulse
  209.         bcf     STATUS,C
  210.         rlf     RowC,f
  211.         rlf     RowC,f
  212.         rlf     RowC,w
  213.         movwf   PORTB
  214.         return
  215.         
  216. hrout   movlw   4               ;Only 4 bits out
  217.         GOTO    he        
  218. rbout   movlw   8               ;number of shifts to do
  219. he      movwf   RowC            ;shift store
  220.         movf    0,w             ;get byte to send
  221.         movwf   Sstore          ;store it
  222. rloop   rrf     Sstore,f        ;get next bit into carry
  223.         bcf     PORTB,cdat      ;Get data line right
  224.         btfsc   STATUS,C
  225.         bsf     PORTB,cdat
  226.         bsf     PORTB,cck       ;Toggle clock
  227.         bcf     PORTB,cck
  228.         decfsz  RowC,f          ;All bits done?
  229.         GOTO    rloop
  230.         return
  231.         
  232. ;Commands
  233.         
  234. sleft   movlw   DisBuf          ;Scroll memory left
  235.         movwf   4               ;into indirect register
  236.         movlw   7               ;Number of rows to scroll
  237.         movwf   sBuf            ;Temp storage
  238.         bcf     STATUS,C
  239. slloop  rlf     0,f             ;Move first byte
  240.         incf    4,f
  241.         rlf     0,f             ;Move second byte
  242.         incf    4,f
  243.         rlf     0,f             ;Move last byte
  244.         bcf     0,4             ;Blank bit fallen off the end
  245.         incf    4,f             ;Move on for next time
  246.         decfsz  sBuf,f          ;Loop until all 7 rows are out
  247.         goto    slloop
  248.         btfsc   Com2,0          ;Now put new data in
  249.         bsf     DisBuf,0
  250.         btfsc   Com2,1
  251.         bsf     DisBuf!3,0
  252.         btfsc   Com2,2
  253.         bsf     DisBuf!6,0
  254.         btfsc   Com2,3
  255.         bsf     DisBuf!9,0
  256.         btfsc   Com2,4
  257.         bsf     DisBuf!12,0
  258.         btfsc   Com2,5
  259.         bsf     DisBuf!15,0
  260.         btfsc   Com2,6
  261.         bsf     DisBuf!18,0
  262.         return
  263.         end                
  264.