📄 lab6.lst
字号:
MPASM 5.06 LAB6.ASM 5-28-2007 15:28:23 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.06 LAB6.ASM 5-28-2007 15:28:23 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.06 LAB6.ASM 5-28-2007 15:28:23 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 ; *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -