home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 135 / dpcs0599.iso / PIC / count84.asm next >
Encoding:
Assembly Source File  |  1999-02-19  |  1.4 KB  |  57 lines

  1. ;This program runs on the PICDBD-1 demo board.
  2. ;In the Demo board, Port B is connected to 8 LEDs. 
  3. ;RA1 is connected to a switch (S3). This program increments
  4. ;the file register count each time S3 is pressed.
  5. ;The value of count is displayed on the LEDs connected
  6. ;to Port B.
  7. ;Net result is that Leds should increment in a binary
  8. ;manner every time S3 is pressed.
  9.  
  10.     list p=16F84, f=inhx8m
  11. ;
  12. ;Define addresses of registers
  13. ;
  14. STATUS    equ    03h
  15. PORTA    equ    05h
  16. TRISA    equ    05h
  17. PORTB    equ    06h
  18. TRISB    equ    06h
  19. ;
  20. ;Define bit positions in registers
  21. ;
  22. RP0    equ    5
  23. ;
  24. ;Define RAM locations
  25. ;
  26. COUNT   equ     0Ch
  27. ;
  28. ;
  29.     org     00h             ;reset vector.
  30.     goto    Start
  31.  
  32.     org     05h
  33.  
  34. Start    bsf     STATUS,RP0      ;Select bank 1
  35.         movlw   b'00000000'     ;Initialise Port B - all outputs
  36.         movwf   TRISB
  37.         movlw   b'11111111'     ;Initialise Port A - all inputs
  38.         movwf   TRISA
  39.         bcf     STATUS,RP0      ;Select bank 0
  40.     clrf    COUNT           ;clear count
  41.     
  42. Loop    btfss   PORTA,1         ;see if RA1 pressed
  43.     goto    IncCnt            ;yes then inc count
  44. EndLoop    goto    Loop            ;else check again
  45.  
  46. IncCnt    incf    COUNT           ;inc count
  47.     movf    COUNT,w         ;
  48.     movwf   PORTB           ;display on port b
  49.  
  50. Release    btfss   PORTA,1         ;wait for key release
  51.     goto    Release            ;not release then wait
  52. EndRel    goto    Loop            ;else check key press again
  53. ;
  54.     end
  55.  
  56.  
  57.