Guest User

Untitled

a guest
Apr 8th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 3.80 KB | None | 0 0
  1.         LIST        P=16F628A, r=dec, w=-302
  2.         include     "P16F628A.INC"  ; Include header file
  3.         __CONFIG    _LVP_OFF & _BOREN_OFF & _MCLRE_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_OSC_NOCLKOUT
  4. ;------------------------------------------------------------
  5.         cblock      0x20    ; Beginn General Purpose-Register
  6. ;-------------------------- counters   
  7. ;place this at very top of codw
  8.  
  9.                 COUNT
  10.                 count1
  11.                 count2
  12.                 count3
  13.                 INTCOUNT
  14. ;--------------------------
  15.         endc
  16. ;--------------------------
  17.  
  18.         cblock      0x70
  19.                 W_TEMP
  20.                 STATUS_TEMP
  21.                 PCLATH_TEMP
  22.         endc
  23.  
  24.  
  25. #DEFINE     pwmu        PORTB,3
  26. ;--- Reset --------------------------------------------------
  27.         org     h'00'
  28.         goto        init        ; reset -> init
  29. ;--- Interrupt ----------------------------------------------
  30.         org     h'04'
  31. ;--------------------------
  32.         movwf       W_TEMP
  33.         swapf       STATUS,W
  34.         banksel     0
  35.         movwf       STATUS_TEMP
  36.         movfw       PCLATH
  37.         movwf       PCLATH_TEMP
  38.  
  39.         decfsz      INTCOUNT,F
  40.         goto        $+5
  41.  
  42.         movlw       1
  43.         xorwf       PORTA,F
  44.         movlw       5
  45.         movwf       INTCOUNT
  46.         clrf        TMR0
  47.         bcf     INTCON,T0IF
  48.  
  49. ISREx       movfw       PCLATH_TEMP
  50.         movwf       PCLATH
  51.         swapf       STATUS_TEMP,W
  52.         movwf       STATUS
  53.         swapf       W_TEMP,F
  54.         swapf       W_TEMP,W
  55.         retfie
  56.  
  57. init
  58.  
  59.             CLRF        PORTA                   ; Initialise PORT A by setting ouput data latches
  60.             CLRF        PORTB                   ; Initialise PORT B by setting ouput data latches
  61.         movlw       5
  62.         movwf       INTCOUNT
  63.             MOVLW       H'07'                   ; Turn Comparators off and enable pins for I/O functions
  64.             MOVWF       CMCON                   ;
  65.             BCF         STATUS, RP1             ; Bank 1
  66.             BSF         STATUS, RP0             ; Bank 1
  67.             MOVLW       B'11111110'             ; RA<7:6>, Inputs. RA<5:2> Outputs. RA<1:0> Inputs.
  68.             MOVWF       TRISA                   ;
  69.  
  70.             MOVLW       B'00000000'             ; RB<7:4> Inputs. RB<3:2> Ouputs.  RB<0:1> Inputs.
  71.             MOVWF       TRISB                   ;
  72.         movlw       0xD7            ;timer 0 1:256 prescale, tmr0 clock source = Tcy
  73.         movwf       OPTION_REG
  74.  
  75.             BCF         STATUS, RP1             ; Bank 0
  76.             BCF         STATUS, RP0             ; Bank 0
  77.         clrf        TMR0
  78.         bcf     INTCON,T0IF
  79.         bsf     INTCON,T0IE
  80.         bsf     INTCON,GIE
  81.         call        pause           ; wait 126ms
  82.         call        set_timer
  83.  
  84. ;--------------------------
  85.  
  86. Reset       movlw       99          ;set increment counter
  87.         movwf       COUNT
  88.         movlw       1           ;set CCPR1L to 1
  89.         movwf       CCPR1L
  90.         call        pause           ;wait 126mS
  91.         incf        CCPR1L,F        ;increment CCPR1L
  92.         decfsz      COUNT,F         ;do 99 times
  93.         goto        $-3
  94.         call        pause           ;wait 126mS
  95.         decfsz      CCPR1L,F        ;decrement CCPR1L
  96.         goto        $-2         ;do 99 times
  97.         goto        Reset           ;start over
  98.        
  99.  
  100.  
  101.  
  102.  
  103. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  104. set_timer
  105.         clrf        T2CON
  106.         clrf        TMR2       
  107.         bsf     STATUS,RP0
  108.         movlw       0xFF
  109.         movwf       PR2     ; compare with 255
  110.         bcf     STATUS,RP0
  111.         movlw       0x02
  112.         movwf       CCPR1L
  113.         movlw       0x03
  114.         movwf       T2CON    ; prescaler 1:16 and postscaler 1:1
  115.         movlw       0x3C
  116.         movwf       CCP1CON
  117.         bsf     T2CON,TMR2ON    ;turn on timer, see pic16f628 datasheet
  118.         return
  119.  
  120. ;************************************************************************
  121. ;     Delay                                                              *
  122. ;************************************************************************
  123. pause       movlw       0x01     ;126 ms   
  124.         movwf       count3
  125. d3      movlw       0x0F    ;63 ms
  126.         movwf       count1
  127. d1      movlw       0xFA    ; 1ms  
  128.         movwf       count2
  129. d2      nop
  130.         decfsz      count2,F   
  131.         goto        d2     
  132.         decfsz      count1,F   
  133.         goto        d1     
  134.         decfsz      count3,F    
  135.         goto        d3          
  136.         retlw       0x00
  137. ;============================================================
  138. usi     bsf     STATUS,RP0  ; Bank 1
  139.         movlw       0xFF ; all input
  140.         movwf       TRISA
  141.         movlw       0x00
  142.         movwf       TRISB ; all output
  143.         bcf     STATUS,RP0  ; Bank 0
  144.         return
  145. ;============================================================
  146.     end
  147. ;============================================================
Add Comment
Please, Sign In to add comment