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

📄 spi.lst

📁 汽车无钥进入系统设计,基于PIC单片机16F639,包括电路图和源码
💻 LST
📖 第 1 页 / 共 2 页
字号:
MPASM  5.14                           SPI.ASM   9-26-2008  8:07:52         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00001 ;/*
                      00002 ;       SPI.asm
                      00003 ;       Jan Ornter
                      00004 ;
                      00005 ;       DATE:   11-9-2005
                      00006 ;       VER.:   1.0
                      00007 ;
                      00008 ;       This class provides functions for the modified physical SPI-Layer
                      00009 ;
                      00010 ;*/
                      00011 
                      00012 
                      00013 
                      00014 #include Project.inc    
                      00001 
                      00002 
                      00003         list p=16F636                           ; list directive to define processor
                      00004         #include <p16f636.inc>      ; processor specific variable definitions
                      00001         LIST
                      00002 ; P16F636.INC  Standard Header File, Version 1.00    Microchip Technology, Inc.
                      00317         LIST
                      00005 
                      00006         ERRORLEVEL 0,-302,-312  ; Messages, Warnings and Errors Printed
                      00007                                         ; Ignore [301] => Processor Mismatch. 
                      00008                                         ; Ignore [302] => Register in operand not in bank 0. 
                      00009                                                                 ; Ignore [312] => Pagesel not needed for
                             Device
                      00015 ;       when overriding these values, you will have to change the source code
                      00016 #define AFECS           PORTC,1         ; Chip select output
                      00017 #define SCK                     PORTC,2         ; SPI Clock Output
                      00018 #define SDIO            PORTC,3         ; Serial output
                      00019 
                      00020         udata
0000                  00021 SPI.BufferH res 1
0001                  00022 SPI.BufferL res 1
                      00023 
                      00024 
                      00025 SPI_ovr udata_ovr
0000                  00026 Count00 res 1
                      00027 
                      00028 flag_ovr        udata_ovr
0000                  00029 flag    res 1           ;using bit 0
                      00030 
  0000                00031         global SPI.BufferH, SPI.BufferL
  0000                00032         global SPI.Read, SPI.Write
                      00033 
                      00034         code
                      00035 
                      00036 ;/*
                      00037 ;       This macro reads two Bytes from the SPI-Bus.
                      00038 ;       Put the Read command and the address in the SPI.BufferH and SPI.BufferL Registers.
                      00039 ;       Then call SPI.Read.
                      00040 ;       Then read the returned values in SPI.BufferH and SPI.BufferL.
MPASM  5.14                           SPI.ASM   9-26-2008  8:07:52         PAGE  2


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00041 ;
                      00042 ;
                      00043 ;       @param SPI.BufferH The most significant Byte of the Data
                      00044 ;       @param SPI.BufferL The least significant Byte of the Data
                      00045 ;
                      00046 ;
                      00047 ;       @return SPI.BufferH The most significant Byte of the Data
                      00048 ;       @return SPI.BufferL The least significant Byte of the Data
                      00049 ;
                      00050 ;       @example
                      00051 ;       pagesel SPI.BufferH
                      00052 ;       movlw   0xf0
                      00053 ;       movwf   SPI.BufferH
                      00054 ;       movlw   0x0f
                      00055 ;       movwf   SPI.BufferL
                      00056 ;       call    SPI.Read
                      00057 ;       @end-ex
                      00058 ;       @ex-desc This sends 0xf00f over the SPI-Bus, and reads the answer to SPI.BufferH and SPI.BufferL
                            .
                      00059 ;
                      00060 ;       @status Tested
                      00061 ;
                      00062 ;       @stacklevel 1
                      00063 ;
                      00064 ;
                      00065 ;*/
0000                  00066 SPI.Read
0000   ???? ????      00067         banksel flag
0002   1400           00068         bsf             flag,0
0003   2???           00069         goto    SPI.ShiftOutBuffer
                      00070 
                      00071 ;/*
                      00072 ;       This macro shifts data out of the MCU through the SPI-Interface.
                      00073 ;
                      00074 ;
                      00075 ;       @param SPI.BufferH The most significant Byte of the Data
                      00076 ;       @param SPI.BufferL The least significant Byte of the Data
                      00077 ;
                      00078 ;       @example
                      00079 ;       pagesel SPI.BufferH
                      00080 ;       movlw   0xf0
                      00081 ;       movwf   SPI.BufferH
                      00082 ;       movlw   0x0f
                      00083 ;       movwf   SPI.BufferL
                      00084 ;       call    SPI.Write
                      00085 ;       @end-ex
                      00086 ;       @ex-desc This sends 0xf00f over the SPI-Bus
                      00087 ;
                      00088 ;       @status Tested
                      00089 ;
                      00090 ;       @stacklevel 1
                      00091 ;
                      00092 ;
MPASM  5.14                           SPI.ASM   9-26-2008  8:07:52         PAGE  3


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00093 ;*/
0004                  00094 SPI.Write
0004   ???? ????      00095         banksel flag
0006   1000           00096         bcf             flag,0
                      00097 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      00098 ; Subroutine: ShiftOutSPIBuffer
                      00099 ;   
                      00100 ; Description: This routine is used to shift data out of the microcontroller
                      00101 ;                                       onto the SPI bus.
                      00102 ;
                      00103 ;Notes:
                      00104 ;1.     This routine assumes 16-bit data is in SSPBufH and SSPBufL already.
                      00105 ;3.     Control the ports as follows:
                      00106 ;               Clear SCK/ALERT
                      00107 ;               Clear chip select
                      00108 ;Loop
                      00109 ;               Set or clear LFDATA/SDIO pin.
                      00110 ;               Set SCK/ALERT
                      00111 ;               Clear SCK/ALERT
                      00112 ;               Goto Loop 16 times
                      00113 ;               Set chip select
                      00114 ;Count00
                      00115 ;
                      00116 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      00117 ;
                      00118 ;       This method shifts data out of the MCU through the SPI-Interface.
                      00119 ;
                      00120 ;
                      00121 ;       @param SPI.BufferH The most significant Byte of the Data
                      00122 ;       @param SPI.BufferL The least significant Byte of the Data
                      00123 ;
                      00124 ;       @example
                      00125 ;       pagesel SPI.BufferH
                      00126 ;       movlw   0xf0
                      00127 ;       movwf   SPI.BufferH
                      00128 ;       movlw   0x0f
                      00129 ;       movwf   SPI.BufferL
                      00130 ;       call    SPI.ShiftOutBuffer
                      00131 ;       @end-ex
                      00132 ;       @ex-desc This sends 0xf00f over the SPI-Bus
                      00133 ;
                      00134 ;       @status Tested
                      00135 ;
                      00136 ;       @stacklevel 1
                      00137 ;
                      00138 ;
                      00139 ;
0007                  00140 SPI.ShiftOutBuffer      
0007   1683 1303      00141         banksel TRISC
0009   0807           00142         movf    TRISC,w
000A   39F1           00143         andlw   b'11110001'
000B   0087           00144         movwf   TRISC
000C   3010           00145         movlw   .16
MPASM  5.14                           SPI.ASM   9-26-2008  8:07:52         PAGE  4


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

000D   ???? ????      00146         banksel Count00
000F   00??           00147         movwf   Count00
0010   1283 1303      00148         banksel PORTC
0012   1107           00149         bcf             SCK
0013   1087           00150         bcf             AFECS
                      00151 
0014                  00152 ShiftOutLoop
0014   ???? ????      00153         banksel SPI.BufferH
0016   0D??           00154         rlf             SPI.BufferL, f
0017   0D??           00155         rlf             SPI.BufferH, f
0018   1283 1303      00156         banksel PORTC
001A   1C03           00157         btfss   STATUS,C
001B   1187           00158         bcf             SDIO
001C   1803           00159         btfsc   STATUS,C                
001D   1587           00160         bsf             SDIO
                      00161 
001E   1507           00162         bsf             SCK
001F   0000           00163         nop
0020   0000           00164         nop
0021   1107           00165         bcf             SCK
                      00166 
                      00167 ;       CLRWDT
0022   ???? ????      00168         banksel Count00
0024   0B??           00169         decfsz  Count00, f
0025   2???           00170         goto    ShiftOutLoop
0026   1283 1303      00171         banksel PORTC
0028   1487           00172         bsf             AFECS
0029   1507           00173         bsf             SCK
002A   ???? ????      00174         banksel flag
002C   1C00           00175         btfss   flag,0
002D   2???           00176         goto    SPI.end
                      00177 
                      00178 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      00179 ; Subroutine: ShiftInSPIBuffer
                      00180 ;   
                      00181 ; Description: This routine is used to shift data into the microcontroller
                      00182 ;                                       from the SPI bus.
                      00183 ;
                      00184 ;Notes:
                      00185 ;1.     This routine loads 16-bit data into the SSPBufH and SSPBufL registers.
                      00186 ;3.     Control the ports as follows:
                      00187 ;               Clear SCK/ALERT
                      00188 ;               Clear chip select
                      00189 ;Loop
                      00190 ;               Set SCK/ALERT
                      00191 ;               Shift in the LFDATA/SDIO pin value.
                      00192 ;               Clear SCK/ALERT
                      00193 ;               Goto Loop 16 times
                      00194 ;               Set chip select
                      00195 ;Count00
                      00196 ;
                      00197 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      00198 ;
MPASM  5.14                           SPI.ASM   9-26-2008  8:07:52         PAGE  5


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00199 ;       This method shifts data from the SPI-Bus into the MCU
                      00200 ;
                      00201 ;
                      00202 ;       @return SPI.BufferH The most significant Byte of the Data
                      00203 ;       @return SPI.BufferL The least significant Byte of the Data
                      00204 ;
                      00205 ;       @example
                      00206 ;       call    SPI.ShiftInBuffer
                      00207 ;       banksel SPI.BufferH
                      00208 ;       movf    SPI.BufferH,w
                      00209 ;       banksel RegH
                      00210 ;       movwf   RegH
                      00211 ;       banksel SPI.BufferH
                      00212 ;       movf    SPI.BufferL,w
                      00213 ;       banksel RegL
                      00214 ;       movwf   RegL
                      00215 ;       @end-ex
                      00216 ;       @ex-desc This stores the data from the SPI-Bus in RegH and RegL.
                      00217 ;
                      00218 ;       @status Tested
                      00219 ;
                      00220 ;       @stacklevel 1
                      00221 ;
                      00222 ;
                      00223 
002E                  00224 SPI.ShiftInBuffer
002E   1683 1303      00225         banksel TRISC
0030   1587           00226         bsf             TRISC,3                 ;Set SDIO as an input

⌨️ 快捷键说明

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