Guest User

Untitled

a guest
Apr 13th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 5.38 KB | None | 0 0
  1. ;*************************************************************************************************
  2. ;**                                                                                             **
  3. ;**                             Header Information                                              **
  4. ;**                                                                                             **
  5. ;*************************************************************************************************
  6.  
  7.                 list            p=16F877A, r=dec, w=-302
  8.                 include         <P16F877A.INC>
  9.                 __config        _LVP_OFF & _BOREN_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC
  10.  
  11. ;*************************************************************************************************
  12. ;**                                                                                             **
  13. ;**                             Variable Declarations                                           **
  14. ;**                                                                                             **
  15. ;*************************************************************************************************
  16.  
  17.                 cblock          0x70
  18.                                 W_TEMP
  19.                                 STATUS_TEMP
  20.                                 PCLATH_TEMP
  21.                                 COUNT1
  22.                                 COUNT2
  23.                                 COUNT3
  24.                 endc
  25.  
  26. ;*************************************************************************************************
  27. ;**                                                                                             **
  28. ;**                             Start of Main Code                                              **
  29. ;**                                                                                             **
  30. ;*************************************************************************************************
  31.  
  32.                 org             0x000               ;reset vector
  33.                 goto            START
  34.  
  35. ;*************************************************************************************************
  36. ;**                                                                                             **
  37. ;**                             Interrupt Handler                                               **
  38. ;**                                                                                             **
  39. ;*************************************************************************************************
  40.  
  41.                 org             0x004               ;interrupt vector
  42. ;interrupt context save
  43.                 movwf           W_TEMP          
  44.                 swapf           STATUS,W
  45.                 banksel         0
  46.                 movwf           STATUS_TEMP
  47.                 movfw           PCLATH
  48.                 movwf           PCLATH_TEMP
  49.  
  50. ;place interrupt code here
  51.  
  52. ;interrupt context restore
  53.  
  54. ISRExit         movfw           PCLATH_TEMP
  55.                 movwf           PCLATH
  56.                 swapf           STATUS_TEMP,W
  57.                 movwf           STATUS
  58.                 swapf           W_TEMP,F
  59.                 swapf           W_TEMP,W
  60.                 retfie
  61.  
  62. ;*************************************************************************************************
  63. ;**                                                                                             **
  64. ;**                            Initialization Routine                                           **
  65. ;**                                                                                             **
  66. ;*************************************************************************************************
  67.  
  68. START           clrf            PORTA           ;init ports
  69.                 clrf            PORTB
  70.                 clrf            PORTC
  71.                 clrf            PORTD
  72.                 clrf            PORTE
  73.                 banksel         ADCON1          ;bank 1
  74.                 movlw           6               ;all ports digital I/O mode
  75.                 movwf           ADCON1
  76.                 clrf            TRISA           ;all ports output
  77.                 clrf            TRISB
  78.                 clrf            TRISC
  79.                 clrf            TRISD
  80.                 clrf            TRISE
  81.                 banksel         0               ;bank 0
  82.  
  83. MAIN            ;main code starts here
  84.  
  85. ;*************************************************************************************************
  86. ;**                                                                                             **
  87. ;**                             Subroutines                                                     **
  88. ;**                                                                                             **
  89. ;*************************************************************************************************
  90.  
  91. ;fixed delay
  92.  
  93. DELAY           movlw           0xFF
  94.                 movwf           COUNT1
  95.                 decfsz          COUNT1,F
  96.                 goto            $-1
  97.                 return
  98.  
  99. ;variable delay (load value into W prior to calling this delay)
  100.  
  101. VarDelay        movwf           COUNT2
  102.                 call            DELAY
  103.                 decfsz          COUNT2,F
  104.                 goto            $-2
  105.                 return
  106.  
  107.                 end
Add Comment
Please, Sign In to add comment