⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lab6.lst

📁 pic单片机资料
💻 LST
📖 第 1 页 / 共 3 页
字号:
MPASM  5.02                          LAB6.ASM   4-13-2006  17:15:28         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00001         #INCLUDE p16F877A.inc           ; Include the standard definitions
                      00001         LIST
                      00002 ; P16F877A.INC  Standard Header File, Version 1.00    Microchip Technology, Inc.
                      00400         LIST
                      00002         #INCLUDE 701PIC.inc             ; Include MACROs from MASTER’s 03, PIC 102 class
                      00001 ; please note, this file is not finshed (comments, etc), 
                      00002 ; but the code does work.
                      00003 
                      00004 
                      00005 LEDEnable       MACRO   BitPattern
                      00006         BANKSEL TRISB
                      00007         movlw   BitPattern
                      00008         movwf   TRISB
                      00009         BANKSEL PORTB
                      00010         ENDM
                      00011         
                      00012 LEDOn           MACRO   LEDNumber
                      00013         movlw   1 << LEDNumber
                      00014         iorwf   PORTB,F
                      00015         ENDM
                      00016 
                      00017 LEDOff          MACRO   LEDNumber
                      00018         movlw   H'FF' - ((1 << LEDNumber) & H'00FF')
                      00019         andwf   PORTB,F
                      00020         ENDM
                      00021 
                      00022 Wait4Ever       MACRO
                      00023         goto    $
                      00024         ENDM
                      00025  
                      00026 ; Sets Piezo to beep at desired frequency, must declare
                      00027 ; Frequency and #DEFINE "DEVICE_FREQ_HZ".  To control beep,
                      00028 ; use "PiezoOn" and "PiezoOff" macros
                      00029 PiezoEnable     MACRO   Freq
                      00030         BANKSEL TRISC
                      00031         bcf             TRISC,2
                      00032         movlw   ((DEVICE_FREQ_HZ/D'64')/Freq)-1
                      00033         movwf   PR2
                      00034         movlw   ((DEVICE_FREQ_HZ/D'128')/Freq)
                      00035         BANKSEL CCPR1L
                      00036         movwf   CCPR1L
                      00037         movlw   0x06            ; Turn on TMR2 (for PWM) 
                      00038         movwf   T2CON           ; and /16 prescale
                      00039         ENDM
                      00040 
                      00041 PiezoOn         MACRO
                      00042         movlw   H'0C'
                      00043         movwf   CCP1CON
                      00044         ENDM
                      00045 
                      00046 PiezoOff        MACRO
                      00047         clrf    CCP1CON
                      00048         ENDM
MPASM  5.02                          LAB6.ASM   4-13-2006  17:15:28         PAGE  2


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00049 
                      00050 
                      00051 ; *************************************************************************
                      00052 ; * MACRO       This Macro loads literal values into the variables Dly3 
                      00053 ; * Dly32       through Dly0 and then calls DoDly32 to run the delay.
                      00054 ; *             This is the macro DEFINITION.  The code is pasted in 
                      00055 ; *             place of the macro call later in the code.
                      00056 ; *             Be sure to ensure all variables are in the same bank.
                      00057 ; *
                      00058 ; * USAGE (for 4 MHz clock):
                      00059 ; *     Dly32   D'2'            ; * 2 loops x 40 us = 40 us           
                      00060 ; *     Dly32   D'5000'         ; * 5000 loops x 20 us = 100 ms       
                      00061 ; *     Dly32   D'50000'        ; * 50000 loops x 20 us = 1 s         
                      00062 ; *     Dly32   D'50000'*D'60'  ; * 60 x 1 second loops = 1 min   
                      00063 ; *     Dly32   D'45000000'     ; * 4.5 million loops x 20 us = 90 s  
                      00064 ; *************************************************************************
                      00065 Dly32   MACRO DLY
                      00066                 
                      00067         BANKSEL Dly3
                      00068         movlw   (DLY-1) & H'FF'         ; * Take the delay value argument 
                      00069         movwf   Dly0                    ; * from the macro, precalculate 
                      00070         movlw   (DLY-1) >>D'08' & H'FF' ; * the required 4 RAM values and
                      00071         movwf   Dly1                    ; * load the The RAM values Dly3 
                      00072         movlw   (DLY-1) >>D'16' & H'FF' ; * though Dly0.
                      00073         movwf   Dly2                    ; * Bytes are shifted and anded
                      00074         movlw   (DLY-1) >>D'24' & H'FF' ; * by the assembler to make 
                      00075         movwf   Dly3                    ; * user calculations easier
                      00076 
                      00077         nop     ; 7 cycle delay for precision delay value
                      00078         nop ;
                      00079         nop ;
                      00080         nop ;
                      00081         nop ;
                      00082         nop ;
                      00083         nop ;
                      00084 
                      00085         call    DoDly32 ; Call DoDly32 to run the delay loop.
                      00086         ENDM            ; End of the Macro Definition
                      00087 ; *************************************************************************
                      00088 
                      00089 ISRSave MACRO                           ; PUSH W and STATUS
                      00090         movwf   W_TEMP                  ; 
                      00091         movf    STATUS,W                ; (swapf will also work here)
                      00092         movwf   STATUS_TEMP             ;
                      00093         ENDM
                      00094 
                      00095 ISRRestore MACRO                                ; POP W and STATUS
                      00096         movf    STATUS_TEMP,W   ; (swapf will also work here)
                      00097         movwf   STATUS                  ;
                      00098         swapf   W_TEMP,F                ; movf changes STATUS bit Z, but 
                      00099         swapf   W_TEMP,W                ; swapf does not change STATUS
                      00100         ENDM
                      00101 
MPASM  5.02                          LAB6.ASM   4-13-2006  17:15:28         PAGE  3


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00102 
0400                  00103         ORG             0x400           ; Arbitrary location to put subroutines
                      00104                                                 ; location must be past the end of your main code!
                      00105 
0400   2800           00106         goto    Start
                      00107 ; *************************************************************************
                      00108 ; * SUBROUTINE  This subroutine provides a 32 bit delay loop.  
                      00109 ; * DoDly32     It uses the macro "Dly32" with 4 arguments to load
                      00110 ; *             the desired delay value.  See the application note for
                      00111 ; *             details.
                      00112 ; *
                      00113 ; * USAGE:      Run the "Dly32" macro which then calls this routine 
                      00114 ; *             automatically.
                      00115 ; *             You must ensure that all variables are in the same bank.
                      00116 ; *************************************************************************
0401                  00117 DoDly32
0401   30FF           00118         movlw   H'FF'           ; Start with -1 in W  
                      00119 
0402   07A0           00120         addwf   Dly0,F          ; LSB decrement
0403   1803           00121         btfsc   STATUS,C        ; was the carry flag set?
0404   0103           00122         clrw                        ; if so, 0 is put in W
                      00123 
0405   07A1           00124         addwf   Dly1,F          ; else, we continue.
0406   1803           00125         btfsc   STATUS,C        ; etc.
0407   0103           00126         clrw                        ; if so, 0 is put in W
                      00127 
0408   07A2           00128         addwf   Dly2,F          ; 
0409   1803           00129         btfsc   STATUS,C        ; etc.
040A   0103           00130         clrw                        ; if so, 0 is put in W
                      00131 
040B   07A3           00132         addwf   Dly3,F          ;
040C   1803           00133         btfsc   STATUS,C        ; etc.
040D   0103           00134         clrw                        ; if so, 0 is put in W
                      00135 
040E   0420           00136         iorwf   Dly0,W          ; * Inclusive-OR all variables
040F   0421           00137         iorwf   Dly1,W          ; * together to see if we have reached 0
0410   0422           00138         iorwf   Dly2,W          ; * on all of them.
0411   0423           00139         iorwf   Dly3,W          ; *
                      00140         
0412   1D03           00141         btfss   STATUS,Z        ; Test if result of Inclusive-OR's is 0
0413   2C01           00142         goto    DoDly32         ; It was NOT zero, so continue counting
0414   3400           00143         retlw   0               ; It WAS zero, so exit this subroutine.
                      00144 ; *************************************************************************
                      00145 
                      00146 
                      00147 ; ****************************************************************
                      00148 ; *           !! YOU NEED THESE VARIABLES (if using Dly32) !!    *
                      00149 ; * You may locate them where you wish                           *
                      00150 ; ****************************************************************
  00000020            00151 Dly0    EQU     0x20    ; * Stores 4 bytes of data for the delay count
  00000021            00152 Dly1    EQU     0x21    ; * Dly0 is the least significant byte
  00000022            00153 Dly2    EQU     0x22    ; * while Dly3 is the most significant byte
  00000023            00154 Dly3    EQU     0x23    ; *
MPASM  5.02                          LAB6.ASM   4-13-2006  17:15:28         PAGE  4


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00155 ; ****************************************************************
                      00156 
                      00157 ; ****************************************************************
                      00158 ; * !! YOU NEED THESE VARIABLES (if using ISRSave or ISRRestore) *
                      00159 ; * You may locate them where you wish                           *
                      00160 ; ****************************************************************
  00000028            00161 STATUS_TEMP     EQU     0x28    ; * Stores copy of STATUS when in ISR
  00000029            00162 W_TEMP          EQU     0x29    ; * Stores copy of WREG when in ISR
                      00163 ; ****************************************************************
                      00003         #DEFINE DEVICE_FREQ_HZ D'4000000'  ; Needed by Piezo series macros
                      00004 
  00000030            00005 LEDCtr  EQU     0x30            ; Counter for LED timing
  00000031            00006 PiezoCtr        EQU     0x31            ; Counter for Piezo timing
                      00007 
0000                  00008                 ORG     H'00'           ; Reset Vector
0000                  00009 Start
0000   2810           00010                 goto    Initialize              ; Jump to Initialization code
                      00011 
0004                  00012                 ORG     H'04'           ; 中断 Vector
0004                  00013 ISR
                      00014                 ISRSave                 ; Macro to context save in ISR
0004   00A9               M         movwf   W_TEMP                  ; 
0005   0803               M         movf    STATUS,W                ; (swapf will also work here)
0006   00A8               M         movwf   STATUS_TEMP             ;
0007   110B           00015                 bcf     INTCON,TMR0IF   ; Clear the TMR0 中断 condition
0008   0AB0           00016                 incf    LEDCtr,F                ; Add 1 to LEDCtr
0009   0AB1           00017                 incf    PiezoCtr,F              ; Add 1 to PiezoCtr
000A   2050           00018                 call    DoReloadTimer   ; Reload the Timer for accurate timing
                      00019                 ISRRestore              ; Macro to context restore when leaving ISR
000B   0828               M         movf    STATUS_TEMP,W   ; (swapf will also work here)
000C   0083               M         movwf   STATUS                  ;
000D   0EA9               M         swapf   W_TEMP,F                ; movf changes STATUS bit Z, but 
000E   0E29               M         swapf   W_TEMP,W                ; swapf does not change STATUS
000F   0009           00020                 retfie                  ; Return from 中断
                      00021 
0010                  00022 Initialize
                      00023                 LEDOff  0               ; Turn off both LEDs
0010   30FE               M         movlw   H'FF' - ((1 << 0)         & H'00FF')
0011   0586               M         andwf   PORTB,F
                      00024                 LEDOff  1               ;  "
0012   30FD               M         movlw   H'FF' - ((1 << 1)         & H'00FF')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -