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

📄 832slave.lst

📁 aduc842原程序代码 ad公司芯片应用笔记
💻 LST
📖 第 1 页 / 共 2 页
字号:
832SLAVE                                                                                                      PAGE 1

                       1    ;********************************************************************
                       2    ;
                       3    ; Author        : ADI - Apps            www.analog.com/MicroConverter
                       4    ;
                       5    ; Date          : April 2002
                       6    ;
                       7    ; File          : SPIslave.asm
                       8    ;
                       9    ; Hardware      : ADuC832
                      10    ;
                      11    ; Include File  : UARTIO.asm - serial I/O routines
                      12    ;
                      13    ; Description   : Demonstrates an example slave mode SPI interface.
                      14    ;                 Code is intended for use with companion code file
                      15    ;                 '832mstr.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 ADuC832 eval board, you can
                      21    ;                 simply connect the 10-pin SPI header directly
                      22    ;                 to that of the master board.  However, you must
                      23    ;                 also ensure that LK5 ('SS master') is REMOVED on
                      24    ;                 the slave board, and INSERTED on the master board.
                      25    ;
                      26    ;                 Once hardware is connected, download code to both
                      27    ;                 master & slave devices ('832mstr' to the master,
                      28    ;                 '832slave' to the slave).  Reset the slave first,
                      29    ;                 and then the master.  The slave will sit with the
                      30    ;                 LED off until the master starts exchanging data
                      31    ;                 with it at which time its LED will start blinking
                      32    ;                 in sync (or 180皁ut of phase) with that of the
                      33    ;                 master.  When first launched, both master and slave
                      34    ;                 are transmitting zeros repeatedly on the SPI port.
                      35    ;                 Pressing the INT0 button on either master or slave
                      36    ;                 increments the value it is transmitting.  Received
                      37    ;                 SPI data is relayed out the UART and can be viewed
                      38    ;                 on any VT100 terminal or terminal emulator at
                      39    ;                 9600baud/8bits/noparity/1stopbit.  Characters sent
                      40    ;                 from the terminal to the MicroConverter will update
                      41    ;                 the value being transmitted by SPI.
                      42    ;
                      43    ;********************************************************************
                      44    
                      45    $MOD832         ; Use 8052 & ADuC832 predefined symbols
                      46    
  00B4                47    LED     EQU     P3.4            ; P3.4 drives red LED on eval board
                      48    
                      49    ;____________________________________________________________________
                      50                                       ; DEFINE VARIABLES IN INTERNAL RAM
----                  51    DSEG
0060                  52    ORG 0060h
0060                  53    INPUT:     DS   1               ; data byte received by SPI
0061                  54    OUTPUT:    DS   1               ; data byte to send by SPI
                      55    
                      56    ;____________________________________________________________________
                      57                                                      ; BEGINNING OF CODE
----                  58    CSEG
832SLAVE                                                                                                      PAGE 2

                      59    
0000                  60    ORG 0000h
0000 02004B           61            JMP     MAIN            ; jump to main program
                      62    
                      63    ;____________________________________________________________________
                      64                                                 ; INTERRUPT VECTOR SPACE
0003                  65    ORG 0003h ; (.................... INT0 ISR)
                      66    
0003 0561             67            INC     OUTPUT
0005 32               68            RETI
                      69    
003B                  70    ORG 003Bh ; (.................... SPI ISR)
                      71    
003B 85F760           72            MOV     INPUT,SPIDAT    ; get data just received by SPI
003E 8561F7           73            MOV     SPIDAT,OUTPUT   ; update next byte to transmit
0041 C3               74            CLR     C               ; clear C indicates transfer complete
0042 32               75            RETI
                      76    
                      77    ;====================================================================
                      78                                                           ; MAIN PROGRAM
004B                  79    ORG 004Bh
                      80    
004B                  81    MAIN:
                      82    
004B 758107           83            MOV     SP,#007h
                      84    
                      85    ; CONFIGURE UART...
004E 759E82           86            MOV     T3CON,#082h
0051 759D2D           87            Mov     T3FD,#02Dh
0054 759852           88            MOV     SCON,#052h
                      89    
                      90    ; CONFIGURE SPI...
                      91    
0057 75F824           92            MOV     SPICON,#024h    ; configure SPI port for:
                      93                                    ;   CPHA=1, CPOL=0, slave
005A 75A901           94            MOV     IEIP2,#1        ; enable SPI interrupt
                      95    
                      96    ; CONFIGURE INTERRUPT 0...
                      97    
005D D288             98            SETB    IT0             ; INT0 edge triggered
005F D2A8             99            SETB    EX0             ; enable INT0 interrupt
                     100    
                     101    ; ENABLE INTERRUPTS & ENTER MAIN LOOP...
                     102    
0061 756100          103            MOV     OUTPUT,#0       ; set initial value for output byte..
0064 75F700          104            MOV     SPIDAT,#0       ; ..including very fisrt output byte
0067 D2AF            105            SETB    EA              ; enable inturrupts
                     106    
0069 B2B4            107    LOOP:   CPL     LED             ; flash the LED on the eval board
006B D3              108            SETB    C
006C 40FE            109            JC      $               ; wait here to receive SPI transfer
006E E560            110            MOV     A,INPUT         ; send value received by SPI..
0070 1200A3          111            CALL    SENDVAL         ; ..out the UART as 2 hex chars
0073 90011E          112            MOV     DPTR,#SEPERATOR ; send line-feed & crdg-return..
0076 120083          113            CALL    SENDSTRING      ; ..out the UART
0079 3098ED          114            JNB     RI,LOOP         ; repeat (unless UART data received)
                     115    
                     116    ; WHEN UART DATA RECEIVED, MOVE DATA TO SPI OUTPUT...
832SLAVE                                                                                                      PAGE 3

                     117    
007C 859961          118            MOV     OUTPUT,SBUF     ; update OUTPUT byte to new value
007F C298            119            CLR     RI              ; must clear RI
0081 80E6            120            JMP     LOOP            ; back to main loop
                     121    
                     122    ;____________________________________________________________________
                     123                                                ; SUBROUTINE INCLUDE FILE
                     124    
                =1   125    $INCLUDE(UARTIO.asm)
                =1   126    ;********************************************************************
                =1   127    ;
                =1   128    ; Author        : ADI - Apps            www.analog.com/MicroConverter
                =1   129    ;
                =1   130    ; Date          : January 2001
                =1   131    ;
                =1   132    ; File          : UARTIO.asm
                =1   133    ;
                =1   134    ; Hardware      : any 8051 based microcontroller or MicroConverter
                =1   135    ;
                =1   136    ; Description   : standard UART I/O subroutines.  total size of this
                =1   137    ;                 code when assembled is 155 bytes.  routines for use
                =1   138    ;                 external to this file are:
                =1   139    ;
                =1   140    ;                 SENDSTRING - sends a string of characters
                =1   141    ;                 SENDCHAR   - sends a single character
                =1   142    ;                 SENDVAL    - sends a byte as 2 ASCII characters
                =1   143    ;                 HEX2ASCII  - converts from HEX to ASCII
                =1   144    ;                 ASCII2HEX  - converts from ASCII to HEX
                =1   145    ;                 GETCHAR    - gets a single character
                =1   146    ;                 GETVAL     - gets a byte as 2 ASCII characters
                =1   147    ;
                =1   148    ;********************************************************************
                =1   149    
                =1   150    ;____________________________________________________________________
                =1   151                                                             ; SENDSTRING
                =1   152    
0083            =1   153    SENDSTRING:     ; sends ASCII string to UART starting at location
                =1   154                    ; DPTR and ending with a null (0) value
                =1   155    
0083 C0E0       =1   156            PUSH    ACC
0085 C0F0       =1   157            PUSH    B
0087 E4         =1   158            CLR     A
0088 F5F0       =1   159            MOV     B,A
008A E5F0       =1   160    IO0010: MOV     A,B
008C 05F0       =1   161            INC     B
008E 93         =1   162            MOVC    A,@A+DPTR
008F 6005       =1   163            JZ      IO0020
0091 12009B     =1   164            CALL    SENDCHAR
0094 80F4       =1   165            JMP     IO0010
0096 D0F0       =1   166    IO0020: POP     B
0098 D0E0       =1   167            POP     ACC
                =1   168    
009A 22         =1   169            RET

⌨️ 快捷键说明

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