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

📄 812mstr.lst

📁 aduc812精典源代码下载,适合初学者
💻 LST
📖 第 1 页 / 共 2 页
字号:
812MSTR                                                                                                       PAGE 1

                       1    ;********************************************************************
                       2    ;
                       3    ; Author        : ADI - Apps            www.analog.com/MicroConverter
                       4    ;
                       5    ; Date          : 7 March 2000
                       6    ;
                       7    ; File          : SPImstr.asm
                       8    ;
                       9    ; Hardware      : ADuC812
                      10    ;
                      11    ; Include File  : UARTIO.asm - serial I/O routines
                      12    ;
                      13    ; Description   : Demonstrates an example master mode SPI interface.
                      14    ;                 Code is intended for use with companion code file
                      15    ;                 'SPIslave.asm' running on a second MicroConverter
                      16    ;                 chip.  Chips must have SCLK, MOSI, MISO, & GND pins
                      17    ;                 connected together, and P3.5 pin on master must
                      18    ;                 connect to SS pin on slave.
                      19    ;
                      20    ;                 If using the ADuC812 eval board, you can simply
                      21    ;                 connect the 10-pin J5 header (SPI/I2C) directly to
                      22    ;                 that of the slave board.  However, on the master
                      23    ;                 board you must also ensure that LK5 is REMOVED, and
                      24    ;                 you'll have to manually jumper P3.5 to J3/pin7 (the
                      25    ;                 SS pin of the SPI/I2C header).  To configure the
                      26    ;                 slave board, refer to 'SPIslave.asm'.
                      27    ;
                      28    ;                 Once hardware is connected, download code to both
                      29    ;                 master & slave devices ('SPImstr' to the master,
                      30    ;                 'SPIslave' to the slave).  Reset the slave first,
                      31    ;                 and then the master.  The slave will sit with the
                      32    ;                 LED off until the master starts exchanging data
                      33    ;                 with it at which time its LED will start blinking
                      34    ;                 in sync (or 180皁ut of phase) with that of the
                      35    ;                 master.  When first launched, both master and slave
                      36    ;                 are transmitting zeros repeatedly on the SPI port.
                      37    ;                 Pressing the INT0 button on either master or slave
                      38    ;                 increments the value it is transmitting.  Received
                      39    ;                 SPI data is relayed out the UART and can be viewed
                      40    ;                 on any VT100 terminal or terminal emulator at
                      41    ;                 9600baud/8bits/noparity/1stopbit.  Characters sent
                      42    ;                 from the terminal to the MicroConverter will update
                      43    ;                 the value being transmitted by SPI.
                      44    ;               
                      45    ;********************************************************************
                      46    
                      47    $MOD812         ; Use 8052 & ADuC812 predefined symbols
                      48    
  00B4                49    LED     EQU     P3.4            ; P3.4 drives red LED on eval board
  00B5                50    SS      EQU     P3.5            ; P3.5 drives slave device's SS pin
                      51    
                      52    ;____________________________________________________________________
                      53                                       ; DEFINE VARIABLES IN INTERNAL RAM
----                  54    DSEG
0060                  55    ORG 0060h
0060                  56    INPUT:     DS   1               ; data byte received by SPI
0061                  57    OUTPUT:    DS   1               ; data byte to send by SPI
                      58    
812MSTR                                                                                                       PAGE 2

                      59    ;____________________________________________________________________
                      60                                                      ; BEGINNING OF CODE
----                  61    CSEG
                      62    
0000                  63    ORG 0000h
0000 02004B           64            JMP     MAIN            ; jump to main program
                      65    
                      66    ;____________________________________________________________________
                      67                                                 ; INTERRUPT VECTOR SPACE
0003                  68    ORG 0003h ; (.................... INT0 ISR)
                      69    
0003 0561             70            INC     OUTPUT
0005 32               71            RETI
                      72    
003B                  73    ORG 003Bh ; (.................... SPI ISR)
                      74    
003B D2B5             75            SETB    SS              ; pull slave's SS pin high
003D 85F760           76            MOV     INPUT,SPIDAT
0040 32               77            RETI
                      78    
                      79    ;====================================================================
                      80                                                           ; MAIN PROGRAM
004B                  81    ORG 004Bh
                      82    
004B                  83    MAIN:
                      84    
004B 758107           85            MOV     SP,#007h
                      86    
                      87    ; CONFIGURE UART...
                      88    
004E 759852           89            MOV     SCON,#52h       ; configure UART for 9600baud..
0051 758920           90            MOV     TMOD,#20h       ; ..assuming 11.0592MHz crystal
0054 758DFD           91            MOV     TH1,#-3
0057 D28E             92            SETB    TR1
                      93    
                      94    ; CONFIGURE SPI...
                      95    
0059 75F837           96            MOV     SPICON,#037h    ; configure SPI port for:
                      97                                    ;   Fosc/64, CPHA=1, CPOL=0, master
                      98    
                      99    ;==> NOTE:  it is important that CPHA and CPOL be the same for both
                     100    ;           the master and all slave devices.  otherwise, data will
                     101    ;           be transitioning at the same time as it's being latched.
                     102    
005C 75A901          103            MOV     IE2,#1          ; enable SPI interrupt
                     104    
                     105    ; CONFIGURE INTERRUPT 0...
                     106    
005F D288            107            SETB    IT0             ; INT0 edge triggered
0061 D2A8            108            SETB    EX0             ; enable INT0 interrupt
                     109    
                     110    ; ENABLE INTERRUPTS & ENTER MAIN LOOP...
                     111    
0063 756100          112            MOV     OUTPUT,#0       ; set initial value for output byte
0066 D2AF            113            SETB    EA              ; enable inturrupts
                     114    
0068 B2B4            115    LOOP:   CPL     LED             ; flash the LED on the eval board
006A E561            116            MOV     A,OUTPUT        ; byte to send via SPI into ACC
812MSTR                                                                                                       PAGE 3

006C 120087          117            CALL    SENDSPI         ; trigger SPI send/receive transfer
006F 12008D          118            CALL    DELAY           ; pause 100ms
0072 E560            119            MOV     A,INPUT         ; send value received by SPI..
0074 1200C1          120            CALL    SENDVAL         ; ..out the UART as 2 hex chars
0077 90013C          121            MOV     DPTR,#SEPERATOR ; send line-feed & crdg-return..
007A 1200A1          122            CALL    SENDSTRING      ; ..out the UART
007D 3098E8          123            JNB     RI,LOOP         ; repeat (unless UART data received)
                     124    
                     125    ; WHEN UART DATA RECEIVED, MOVE DATA TO SPI OUTPUT...
                     126    
0080 859961          127            MOV     OUTPUT,SBUF     ; update OUTPUT byte to new value
0083 C298            128            CLR     RI              ; must clear RI
0085 80E1            129            JMP     LOOP            ; back to main loop
                     130    
                     131    ;____________________________________________________________________
                     132                                                            ; SUBROUTINES
                     133    
0087                 134    SENDSPI:        ; sends the value in ACC out the SPI port.  also
                     135                    ; receives simultaneously into SPIDAT.  SPI interrupt
                     136                    ; is triggered when transfer is complete.
                     137    
0087 C2B5            138            CLR     SS              ; must pull slave's SS pin low first
0089 8561F7          139            MOV     SPIDAT,OUTPUT   ; trigger data transfer
008C 22              140            RET
                     141    
                     142    ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                     143    
008D                 144    DELAY:          ; delays approximately 100ms
                     145    
008D C0E0            146            PUSH    ACC
008F C0F0            147            PUSH    B
0091 74C8            148            MOV     A,#200          ; 200 * 500us = 100ms
0093 75F0E5          149    DLY1:   MOV     B,#229          ; 229 * 2.17us = 500us
0096 D5F0FD          150            DJNZ    B,$             ; sit here for 500us
0099 D5E0F7          151            DJNZ    ACC,DLY1        ; repeat 200 times (100ms delay)
009C D0F0            152            POP     B
009E D0E0            153            POP     ACC
00A0 22              154            RET
                     155    
                     156    ;____________________________________________________________________
                     157                                                ; SUBROUTINE INCLUDE FILE
                     158    
                =1   159    $INCLUDE(UARTIO.asm)
                =1   160    ;********************************************************************
                =1   161    ;
                =1   162    ; Author        : ADI - Apps            www.analog.com/MicroConverter
                =1   163    ;
                =1   164    ; Date          : 12 October 1999
                =1   165    ;
                =1   166    ; File          : UARTIO.hex
                =1   167    ;
                =1   168    ; Hardware      : any 8051 based microcontroller or MicroConverter
                =1   169    ;
                =1   170    ; Description   : standard UART I/O subroutines.  total size of this
                =1   171    ;                 code when assembled is 155 bytes.  routines for use
                =1   172    ;                 external to this file are:
                =1   173    ;
                =1   174    ;                 SENDSTRING - sends a string of characters
812MSTR                                                                                                       PAGE 4

                =1   175    ;                 SENDCHAR   - sends a single character
                =1   176    ;                 SENDVAL    - sends a byte as 2 ASCII characters
                =1   177    ;                 HEX2ASCII  - converts from HEX to ASCII
                =1   178    ;                 ASCII2HEX  - converts from ASCII to HEX
                =1   179    ;                 GETCHAR    - gets a single character
                =1   180    ;                 GETVAL     - gets a byte as 2 ASCII characters
                =1   181    ;
                =1   182    ;********************************************************************
                =1   183    
                =1   184    ;____________________________________________________________________
                =1   185                                                             ; SENDSTRING
                =1   186    
00A1            =1   187    SENDSTRING:     ; sends ASCII string to UART starting at location

⌨️ 快捷键说明

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