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

📄 842mstr.lst

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

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

0000                  59    ORG 0000h
0000 02004B           60            JMP     MAIN            ; jump to main program
                      61    
                      62    ;____________________________________________________________________
                      63                                                 ; INTERRUPT VECTOR SPACE
0003                  64    ORG 0003h ; (.................... INT0 ISR)
                      65    
0003 0561             66            INC     OUTPUT
0005 32               67            RETI
                      68    
003B                  69    ORG 003Bh ; (.................... SPI ISR)
                      70    
003B D2B5             71            SETB    SS              ; pull slave's SS pin high
003D 85F760           72            MOV     INPUT,SPIDAT
0040 32               73            RETI
                      74    
                      75    ;====================================================================
                      76                                                           ; MAIN PROGRAM
004B                  77    ORG 004Bh
                      78    
004B                  79    MAIN:
                      80    
004B 758107           81            MOV     SP,#007h
                      82    
                      83    ; CONFIGURE UART...
004E 759E83           84            MOV     T3CON,#083h
0051 759D2D           85            MOV     T3FD,#02Dh
0054 759852           86            MOV     SCON,#052h
                      87    
                      88    ; CONFIGURE SPI...
                      89    
0057 75F837           90            MOV     SPICON,#037h    ; configure SPI port for:
                      91                                    ;   Fosc/64, CPHA=1, CPOL=0, master
005A 75A901           92            MOV     IEIP2,#1        ; enable SPI interrupt
                      93    
                      94    ; CONFIGURE INTERRUPT 0...
                      95    
005D D288             96            SETB    IT0             ; INT0 edge triggered
005F D2A8             97            SETB    EX0             ; enable INT0 interrupt
                      98    
                      99    ; ENABLE INTERRUPTS & ENTER MAIN LOOP...
                     100    
0061 756100          101            MOV     OUTPUT,#0       ; set initial value for output byte
0064 D2AF            102            SETB    EA              ; enable inturrupts
                     103    
0066 B2B4            104    LOOP:   CPL     LED             ; flash the LED on the eval board
0068 E561            105            MOV     A,OUTPUT        ; byte to send via SPI into ACC
006A 12009D          106            CALL    SENDSPI         ; trigger SPI send/receive transfer
006D 1200A3          107            CALL    DELAY           ; pause 10ms
0070 1200A3          108            CALL    DELAY           ; pause 10ms
0073 1200A3          109            CALL    DELAY           ; pause 10ms
0076 1200A3          110            CALL    DELAY           ; pause 10ms
0079 1200A3          111            CALL    DELAY           ; pause 10ms
007C 1200A3          112            CALL    DELAY           ; pause 10ms
007F 1200A3          113            CALL    DELAY           ; pause 10ms
0082 1200A3          114            CALL    DELAY           ; pause 10ms
0085 1200A3          115            CALL    DELAY           ; pause 10ms
0088 E560            116            MOV     A,INPUT         ; send value received by SPI..
842MSTR                                                                                                       PAGE 3

008A 1200D7          117            CALL    SENDVAL         ; ..out the UART as 2 ASCII chars
008D 900152          118            MOV     DPTR,#SEPERATOR ; send line-feed & crdg-return..
0090 1200B7          119            CALL    SENDSTRING      ; ..out the UART
0093 3098D0          120            JNB     RI,LOOP         ; repeat (unless UART data received)
                     121    
                     122    ; WHEN UART DATA RECEIVED, MOVE DATA TO SPI OUTPUT...
                     123    
0096 859961          124            MOV     OUTPUT,SBUF     ; update OUTPUT byte to new value
0099 C298            125            CLR     RI              ; must clear RI
009B 80C9            126            JMP     LOOP            ; back to main loop
                     127    
                     128    ;____________________________________________________________________
                     129                                                            ; SUBROUTINES
                     130    
009D                 131    SENDSPI:        ; sends the value in ACC out the SPI port.  also
                     132                    ; receives simultaneously into SPIDAT.  SPI interrupt
                     133                    ; is triggered when transfer is complete.
                     134    
009D C2B5            135            CLR     SS              ; must pull slave's SS pin low first
009F 8561F7          136            MOV     SPIDAT,OUTPUT   ; trigger data transfer
00A2 22              137            RET
                     138    
                     139    ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                     140    
00A3                 141    DELAY:          ; delays approximately 10ms
                     142    
00A3 C0E0            143            PUSH    ACC
00A5 C0F0            144            PUSH    B
00A7 741B            145            MOV     A,#01Bh         ; 
00A9 75F0FF          146    DLY1:   MOV     B,#0FFh         ; 
00AC D5F0FD          147            DJNZ    B,$             ; 
00AF D5E0F7          148            DJNZ    ACC,DLY1        ; 
00B2 D0F0            149            POP     B
00B4 D0E0            150            POP     ACC
00B6 22              151            RET
                     152    
                     153    ;____________________________________________________________________
                     154                                                ; SUBROUTINE INCLUDE FILE
                     155    
                =1   156    $INCLUDE(UARTIO.asm)
                =1   157    ;********************************************************************
                =1   158    ;
                =1   159    ; Author        : ADI - Apps            www.analog.com/MicroConverter
                =1   160    ;
                =1   161    ; Date          : January 2001
                =1   162    ;
                =1   163    ; File          : UARTIO.asm
                =1   164    ;
                =1   165    ; Hardware      : any 8051 based microcontroller or MicroConverter
                =1   166    ;
                =1   167    ; Description   : standard UART I/O subroutines.  total size of this
                =1   168    ;                 code when assembled is 155 bytes.  routines for use
                =1   169    ;                 external to this file are:
                =1   170    ;
                =1   171    ;                 SENDSTRING - sends a string of characters
                =1   172    ;                 SENDCHAR   - sends a single character
                =1   173    ;                 SENDVAL    - sends a byte as 2 ASCII characters
                =1   174    ;                 HEX2ASCII  - converts from HEX to ASCII
842MSTR                                                                                                       PAGE 4

                =1   175    ;                 ASCII2HEX  - converts from ASCII to HEX
                =1   176    ;                 GETCHAR    - gets a single character
                =1   177    ;                 GETVAL     - gets a byte as 2 ASCII characters
                =1   178    ;
                =1   179    ;********************************************************************
                =1   180    
                =1   181    ;____________________________________________________________________
                =1   182                                                             ; SENDSTRING
                =1   183    
00B7            =1   184    SENDSTRING:     ; sends ASCII string to UART starting at location
                =1   185                    ; DPTR and ending with a null (0) value

⌨️ 快捷键说明

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