Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MPASM 5.66 KB | None | 0 0
  1. ;******************************************************************************
  2. ;   This file is a basic template for assembly code for a PIC18F1330. Copy    *
  3. ;   this file into your project directory and modify or add to it as needed.  *
  4. ;                                                                             *
  5. ;   Refer to the MPASM User's Guide for additional information on the         *
  6. ;   features of the assembler.                                                *
  7. ;                                                                             *                    
  8. ;                                                                             *
  9. ;******************************************************************************
  10. ;                                                                             *
  11. ;    Filename:                                                                *
  12. ;    Date:                                                                    *
  13. ;    File Version:                                                            *
  14. ;                                                                             *
  15. ;    Author:                                                                  *
  16. ;    Company:                                                                 *
  17. ;                                                                             *
  18. ;******************************************************************************
  19. ;                                                                             *
  20. ;    Files Required: P18F1330.INC                                             *
  21. ;                                                                             *
  22. ;******************************************************************************
  23.  
  24.     LIST P=18F1330      ;directive to define processor
  25.     #include <P18F1330.INC> ;processor specific variable definitions
  26.  
  27. ;******************************************************************************
  28. ;Configuration bits
  29. ;Microchip has changed the format for defining the configuration bits, please
  30. ;see the .inc file for futher details on notation.  Below are a few examples.
  31.  
  32.  
  33. ;   Oscillator Selection:
  34.     CONFIG  OSC = INTIO2             ;INTERNAL OSCILLATOR, PORT FUNCTION ON RA6
  35.  
  36. ;   Fail Safe Clock Monitor:
  37.     CONFIG  FCMEN = OFF           ;Fail Safe Clock Monitor disabled
  38.  
  39. ;   Power-Up Timer:
  40.     CONFIG      PWRT = OFF           ;Disabled
  41.  
  42.    
  43. ;Oscillator Selection
  44.     ;;  __CONFIG   _CONFIG1H, _OSC_LP_1H & _FCMEN_OFF_1H   
  45.  
  46. ;Fail Safe Monitor
  47.     ;;  __CONFIG   _CONFIG2L, _PWRT_OFF_2L
  48.  
  49.  
  50. ;******************************************************************************
  51. ;Variable definitions
  52. ; These variables are only needed if low priority interrupts are used.
  53. ; More variables may be needed to store other special function registers used
  54. ; in the interrupt routines.
  55.  
  56.         CBLOCK  0x080
  57.         WREG_TEMP   ;variable used for context saving
  58.         STATUS_TEMP ;variable used for context saving
  59.         BSR_TEMP    ;variable used for context saving
  60.  
  61.         ENDC
  62.  
  63.         CBLOCK  0x000
  64.         EXAMPLE     ;example of a variable in access RAM
  65.         COUNTER1    ;VARIABLE USED IN DELAY1
  66.         COUNTER2_1  ;VARIABLE USED IN DELAY2
  67.         COUNTER2_2  ;VARIABLE USED IN DELAY2
  68.         ENDC
  69.  
  70. ;******************************************************************************
  71. ;EEPROM data
  72. ; Data to be programmed into the Data EEPROM is defined here
  73.  
  74.         ORG 0xf00000
  75.  
  76.         DE  "Test Data",0,1,2,3,4,5
  77.  
  78. ;******************************************************************************
  79. ;Reset vector
  80. ; This code will start executing when a reset occurs.
  81.  
  82.         ORG 0x0000
  83.  
  84.         goto    Main        ;go to start of main code
  85.  
  86. ;******************************************************************************
  87. ;High priority interrupt vector
  88. ; This code will start executing when a high priority interrupt occurs or
  89. ; when any interrupt occurs if interrupt priorities are not enabled.
  90.  
  91.         ORG 0x0008
  92.  
  93.         bra HighInt     ;go to high priority interrupt routine
  94.  
  95. ;******************************************************************************
  96. ;Low priority interrupt vector and routine
  97. ; This code will start executing when a low priority interrupt occurs.
  98. ; This code can be removed if low priority interrupts are not used.
  99.  
  100.         ORG 0x0018
  101.  
  102.         movff   STATUS,STATUS_TEMP  ;save STATUS register
  103.         movff   WREG,WREG_TEMP      ;save working register
  104.         movff   BSR,BSR_TEMP        ;save BSR register
  105.  
  106. ;   *** low priority interrupt code goes here ***
  107.  
  108.  
  109.         movff   BSR_TEMP,BSR        ;restore BSR register
  110.         movff   WREG_TEMP,WREG      ;restore working register
  111.         movff   STATUS_TEMP,STATUS  ;restore STATUS register
  112.         retfie
  113.  
  114. ;******************************************************************************
  115. ;High priority interrupt routine
  116. ; The high priority interrupt code is placed here to avoid conflicting with
  117. ; the low priority interrupt vector.
  118.  
  119. HighInt:
  120.  
  121. ;   *** high priority interrupt code goes here ***
  122.  
  123.  
  124.         retfie  FAST
  125.  
  126. ;******************************************************************************
  127. ;Start of main program
  128. ; The main program code is placed here.
  129.  
  130. Main:
  131.  
  132.     MOVLW   0X01    ;select bank 1
  133.     MOVWF   BSR
  134.     MOVLW   b'00000000'
  135.     MOVWF   TRISA
  136.     GOTO    MAINLOOP
  137.     MOVLW   0X00    ;select bank 0
  138.     MOVWF   BSR
  139.  
  140. MAINLOOP:
  141.  
  142.     MOVLW   0X01
  143.     MOVWF   PORTA,RA0
  144.     CALL    DELAY1
  145.     MOVLW   0X00
  146.     MOVWF   PORTA,RA0
  147.     CALL    DELAY2
  148.     GOTO    MAINLOOP
  149.  
  150. DELAY1:
  151.  
  152.     MOVLW   0X0F
  153.     MOVWF   COUNTER1
  154.  
  155. DELAY1_0:
  156.  
  157.     DECFSZ  COUNTER1
  158.     GOTO    DELAY1_0
  159.     RETURN
  160.  
  161. DELAY2:
  162.    
  163.     MOVLW   0X0E
  164.     MOVWF   COUNTER2_1
  165.     MOVLW   0X08
  166.     MOVWF   COUNTER2_2
  167.  
  168. DELAY2_0:
  169.  
  170.     DECFSZ  COUNTER2_1
  171.     GOTO    $+2
  172.     DECFSZ  COUNTER2_2
  173.     GOTO    DELAY2_0
  174.     GOTO    $+2
  175.     NOP
  176.     NOP
  177.     RETURN
  178.  
  179.  
  180. ;******************************************************************************
  181. ;End of program
  182.  
  183.         END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement