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

📄 832mstr.lst

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

                       1    ;********************************************************************
                       2    ;
                       3    ; Author        : ADI - Apps            www.analog.com/MicroConverter
                       4    ;
                       5    ; Date          : April 2002
                       6    ;
                       7    ; File          : 832mstr.asm
                       8    ;
                       9    ; Hardware      : ADuC832
                      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    ;                 '832slave.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/I2C header directly
                      22    ;                 to that of the master board.  However, you must
                      23    ;                 also ensure that link 5('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
  00B5                48    SS      EQU     P3.5            ; P3.5 drives slave device's SS pin
                      49    
                      50    ;____________________________________________________________________
                      51                                       ; DEFINE VARIABLES IN INTERNAL RAM
----                  52    DSEG
0060                  53    ORG 0060h
0060                  54    INPUT:     DS   1               ; data byte received by SPI
0061                  55    OUTPUT:    DS   1               ; data byte to send by SPI
                      56    
                      57    ;____________________________________________________________________
                      58                                                      ; BEGINNING OF CODE
832MSTR                                                                                                       PAGE 2

----                  59    CSEG
                      60    
0000                  61    ORG 0000h
0000 02004B           62            JMP     MAIN            ; jump to main program
                      63    
                      64    ;____________________________________________________________________
                      65                                                 ; INTERRUPT VECTOR SPACE
0003                  66    ORG 0003h ; (.................... INT0 ISR)
                      67    
0003 0561             68            INC     OUTPUT
0005 32               69            RETI
                      70    
003B                  71    ORG 003Bh ; (.................... SPI ISR)
                      72    
003B D2B5             73            SETB    SS              ; pull slave's SS pin high
003D 85F760           74            MOV     INPUT,SPIDAT
0040 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 75F837           92            MOV     SPICON,#037h    ; configure SPI port for:
                      93                                    ;   Fosc/64, CPHA=1, CPOL=0, master
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 D2AF            104            SETB    EA              ; enable inturrupts
                     105    
0066 B2B4            106    LOOP:   CPL     LED             ; flash the LED on the eval board
0068 E561            107            MOV     A,OUTPUT        ; byte to send via SPI into ACC
006A 120085          108            CALL    SENDSPI         ; trigger SPI send/receive transfer
006D 12008B          109            CALL    DELAY           ; pause 100ms
0070 E560            110            MOV     A,INPUT         ; send value received by SPI..
0072 1200BF          111            CALL    SENDVAL         ; ..out the UART as 2 ASCII chars
0075 90013A          112            MOV     DPTR,#SEPERATOR ; send line-feed & crdg-return..
0078 12009F          113            CALL    SENDSTRING      ; ..out the UART
007B 3098E8          114            JNB     RI,LOOP         ; repeat (unless UART data received)
                     115    
                     116    ; WHEN UART DATA RECEIVED, MOVE DATA TO SPI OUTPUT...
832MSTR                                                                                                       PAGE 3

                     117    
007E 859961          118            MOV     OUTPUT,SBUF     ; update OUTPUT byte to new value
0081 C298            119            CLR     RI              ; must clear RI
0083 80E1            120            JMP     LOOP            ; back to main loop
                     121    
                     122    ;____________________________________________________________________
                     123                                                            ; SUBROUTINES
                     124    
0085                 125    SENDSPI:        ; sends the value in ACC out the SPI port.  also
                     126                    ; receives simultaneously into SPIDAT.  SPI interrupt
                     127                    ; is triggered when transfer is complete.
                     128    
0085 C2B5            129            CLR     SS              ; must pull slave's SS pin low first
0087 8561F7          130            MOV     SPIDAT,OUTPUT   ; trigger data transfer
008A 22              131            RET
                     132    
                     133    ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                     134    
008B                 135    DELAY:          ; delays approximately 100ms
                     136    
008B C0E0            137            PUSH    ACC
008D C0F0            138            PUSH    B
008F 7422            139            MOV     A,#022h         ; 
0091 75F0FF          140    DLY1:   MOV     B,#0FFh         ; 
0094 D5F0FD          141            DJNZ    B,$             ; 
0097 D5E0F7          142            DJNZ    ACC,DLY1        ; 
009A D0F0            143            POP     B
009C D0E0            144            POP     ACC
009E 22              145            RET
                     146    
                     147    ;____________________________________________________________________
                     148                                                ; SUBROUTINE INCLUDE FILE
                     149    
                =1   150    $INCLUDE(UARTIO.asm)
                =1   151    ;********************************************************************
                =1   152    ;
                =1   153    ; Author        : ADI - Apps            www.analog.com/MicroConverter
                =1   154    ;
                =1   155    ; Date          : January 2001
                =1   156    ;
                =1   157    ; File          : UARTIO.asm
                =1   158    ;
                =1   159    ; Hardware      : any 8051 based microcontroller or MicroConverter
                =1   160    ;
                =1   161    ; Description   : standard UART I/O subroutines.  total size of this
                =1   162    ;                 code when assembled is 155 bytes.  routines for use
                =1   163    ;                 external to this file are:
                =1   164    ;
                =1   165    ;                 SENDSTRING - sends a string of characters
                =1   166    ;                 SENDCHAR   - sends a single character
                =1   167    ;                 SENDVAL    - sends a byte as 2 ASCII characters
                =1   168    ;                 HEX2ASCII  - converts from HEX to ASCII
                =1   169    ;                 ASCII2HEX  - converts from ASCII to HEX
                =1   170    ;                 GETCHAR    - gets a single character
                =1   171    ;                 GETVAL     - gets a byte as 2 ASCII characters
                =1   172    ;
                =1   173    ;********************************************************************
                =1   174    
832MSTR                                                                                                       PAGE 4

                =1   175    ;____________________________________________________________________
                =1   176                                                             ; SENDSTRING
                =1   177    
009F            =1   178    SENDSTRING:     ; sends ASCII string to UART starting at location
                =1   179                    ; DPTR and ending with a null (0) value
                =1   180    
009F C0E0       =1   181            PUSH    ACC
00A1 C0F0       =1   182            PUSH    B

⌨️ 快捷键说明

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