Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 3.48 KB | None | 0 0
  1. ; *******************************************************************
  2. ; Lesson 3 - "Rotate"
  3. ;
  4. ; This lesson will introduce shifting instructions as well as bit-oriented skip operations to
  5. ; move the LED display.
  6. ;
  7. ; LEDs rotate from right to left at a rate of 1.5s
  8. ;
  9. ;
  10. ; PIC: 16F1829
  11. ; Assembler: MPASM v5.43
  12. ; IDE: MPLABX v1.10
  13. ;
  14. ; Board: PICkit 3 Low Pin Count Demo Board
  15. ; Date: 6.1.2012
  16. ;
  17. ; *******************************************************************
  18. ; * See Low Pin Count Demo Board User's Guide for Lesson Information*
  19. ; *******************************************************************
  20.  
  21. #include <p16F1829.inc>
  22.      __CONFIG _CONFIG1, (_FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF);
  23.      __CONFIG _CONFIG2, (_WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF);
  24.  
  25.     errorlevel -302                     ;supress the 'not in bank0' warning
  26.     cblock 0x70                         ;shared memory location that is accessible from all banks
  27. Delay1                                  ;define two file registers for the delay loop in shared memory
  28. Delay2
  29. Count
  30.      endc
  31.  
  32.     ; -------------------LATC-----------------
  33.     ; Bit#:  -7---6---5---4---3---2---1---0---
  34.     ; LED:   ---------------|DS4|DS3|DS2|DS1|-
  35.     ; -----------------------------------------
  36.  
  37.     ORG 0                               ;start of code
  38. Start:
  39.      banksel        ANSELA
  40.      bcf            ANSELA,2
  41.      banksel        OSCCON              ;bank1
  42.      movlw          b'00111000'         ;set cpu clock speed of 500KHz
  43.      movwf          OSCCON              ;move contents of the working register into OSCCON
  44.      clrf           TRISC               ;make all of PORTC an output
  45.      banksel        LATC                ;select the bank where LATC is (bank2)
  46.      movlw          b'00000001'         ;start the rotation by setting DS4 ON
  47.      movwf          LATC                ;write contents of the working register to the latch
  48.      banksel        TRISA
  49.      bsf            TRISA,2
  50.      banksel        LATC
  51.      movlw          0
  52.      movwf          Count
  53.  
  54. OndelayLoop:
  55.      decfsz         Delay1,f            ;Waste time.
  56.      goto           OndelayLoop         ;The Inner loop takes 3 instructions per loop * 256 loopss = 768 instructions
  57.      decfsz         Delay2,f            ;The outer loop takes an additional 3 instructions per lap * 256 loops
  58.      goto           OndelayLoop         ;(768+3) * 256 = 197376 instructions / 125K instructions per second = 1.579 sec.
  59. MainLoop:
  60.     banksel         LATC
  61.     btfss           Count,F
  62.     btfss           PORTA, 2
  63.     goto            RotateRight
  64.  
  65. RotateLeft:
  66.    banksel         LATC
  67.    incf            Count,1               ;increase Count every loop.
  68.    lsrf            LATC,F              ;shift the LEDs and turn on the next LED to the right
  69.    btfsc           STATUS,C            ;did the bit rotate into the carry (i.e. was DS1 just lit?)
  70.    bsf             LATC,3             ;yes, it did and now start the sequence over again by turning on DS
  71.    goto            OndelayLoop            ;repeat this program forever
  72.  
  73. RotateRight:
  74.     banksel         LATC
  75.     decfsz          Count
  76.     goto            MainLoop
  77.     lslf            LATC,F              ;logical shift left file LATC.
  78.     btfsc           LATC,4             ;check if DS4 was lit.
  79.     bsf             LATC,0
  80.     goto            OndelayLoop
  81.  
  82.     end                                 ;end code section
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement