Advertisement
Guest User

Untitled

a guest
Dec 18th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;
  2. ;      2011.10.11:  author:  Rob Hoogerwoord
  3. ;
  4. ;      2013.10.29:  removed errors in the annotation [RH]
  5. ;
  6. ;      This routine continuously reads the intput buttons and copies them to the
  7. ;      LED outputs. In addition, if Button 0 is pressed this increases a modulo
  8. ;      16 counter which is displayed at the right-most digit of the display,
  9. ;      and, similarly, if Button 1 is pressed this increases a modulo 16 counter
  10. ;      which is displayed at the second right-most digit of the display.
  11. ;
  12. ;
  13. @CODE
  14.  
  15.    IOAREA      EQU  -16  ;  address of the I/O-Area, modulo 2^18
  16.     INPUT      EQU    7  ;  position of the input buttons (relative to IOAREA)
  17.    OUTPUT      EQU   11  ;  relative position of the power outputs
  18.    DSPDIG      EQU    9  ;  relative position of the 7-segment display's digit selector
  19.   DSPSEG      EQU    8  ;  relative position of the 7-segment display's segments
  20.  
  21.   begin :      BRA  main         ;  skip subroutine Hex7Seg
  22. ;  
  23. ;      Routine Hex7Seg maps a number in the range [0..15] to its hexadecimal
  24. ;      representation pattern for the 7-segment display.
  25. ;      R0 : upon entry, contains the number
  26. ;      R1 : upon exit,  contains the resulting pattern
  27. ;
  28. Hex7Seg     :  BRS  Hex7Seg_bgn  ;  push address(tbl) onto stack and proceed at "bgn"
  29. Hex7Seg_tbl : CONS  %01111110    ;  7-segment pattern for '0'
  30.               CONS  %00110000    ;  7-segment pattern for '1'
  31.               CONS  %01101101    ;  7-segment pattern for '2'
  32.               CONS  %01111001    ;  7-segment pattern for '3'
  33.               CONS  %00110011    ;  7-segment pattern for '4'
  34.               CONS  %01011011    ;  7-segment pattern for '5'
  35.               CONS  %01011111    ;  7-segment pattern for '6'
  36.               CONS  %01110000    ;  7-segment pattern for '7'
  37.               CONS  %01111111    ;  7-segment pattern for '8'
  38.               CONS  %01111011    ;  7-segment pattern for '9'
  39.               CONS  %01110111    ;  7-segment pattern for 'A'
  40.               CONS  %00011111    ;  7-segment pattern for 'b'
  41.               CONS  %01001110    ;  7-segment pattern for 'C'
  42.               CONS  %00111101    ;  7-segment pattern for 'd'
  43.               CONS  %01001111    ;  7-segment pattern for 'E'
  44.               CONS  %01000111    ;  7-segment pattern for 'F'
  45. Hex7Seg_bgn:   AND  R0  %01111   ;  R0 := R0 MOD 16 , just to be safe...
  46.               LOAD  R1  [SP++]   ;  R1 := address(tbl) (retrieve from stack)
  47.               LOAD  R1  [R1+R0]  ;  R1 := tbl[R0]
  48.                RTS
  49. ;
  50. ;      The body of the main program
  51. ;
  52.    main :     LOAD  R5  IOAREA   ;  R5 := "address of the area with the I/O-registers"
  53.               LOAD  R2  0        ;  R2 is counter nr. 0, initially 0
  54.               LOAD  R3  0        ;  R3 is counter nr. 1, initially 0
  55. ;
  56.    loop :     LOAD  R0  [R5+INPUT]  ;   read Input Buttons
  57.               STOR  R0  [R5+OUTPUT] ;  write this to Output LEDs
  58.                CMP  R0  1        ;  test if Button 0 is pressed, and no other ones
  59.                BNE  next         ;  if not then skip this part, continue at "next"
  60.                ADD  R2  1        ;  increment counter nr. 0
  61.                AND  R2  %01111   ;  take it modulo 16
  62.               LOAD  R0  R2       ;  copy counter 0 into R0; R2 must be preserved
  63.                BRS  Hex7Seg      ;  translate (value in) R0 into a display pattern
  64.               STOR  R1  [R5+DSPSEG] ; and place this in the Display Element
  65.               LOAD  R1  %000001  ;  R1 := the bitpattern identifying Digit 0
  66.               STOR  R1  [R5+DSPDIG] ; activate Display Element nr. 0
  67.                BRA  loop         ;  repeat ad infinitum...
  68. ;
  69.    next :      CMP  R0  2        ;  test if Button 1 is pressed, and no other ones
  70.                BNE  loop         ;  if not then skip this part
  71.                ADD  R3  1        ;  increment counter nr. 1
  72.                AND  R3  %01111   ;  take it modulo 16
  73.               LOAD  R0  R3       ;  copy counter 1 into R0; R3 must be preserved
  74.                BRS  Hex7Seg      ;  translate (value in) R0 into a display pattern
  75.               STOR  R1  [R5+DSPSEG] ; and place this in the Display Element
  76.               LOAD  R1  %000010  ;  R1 := the bitpattern identifying Digit 1
  77.               STOR  R1  [R5+DSPDIG] ; activate Display Element nr. 1
  78.                BRA  loop         ;  repeat ad infinitum...
  79. @END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement