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

📄 842slave.asm

📁 aduc842原程序代码 ad公司芯片应用笔记
💻 ASM
字号:
;********************************************************************
;
; Author        : ADI - Apps            www.analog.com/MicroConverter
;
; Date          : October 2003
;
; File          : SPIslave.asm
;
; Hardware      : ADuC842/ADuC843
;
; Include File  : UARTIO.asm - serial I/O routines
;
; Description   : Demonstrates an example slave mode SPI interface.
;                 Code is intended for use with companion code file
;                 '842mstr.asm' running on a second MicroConverter
;                 chip.  Chips must have SCLK, MOSI, MISO, & GND pins
;                 connected together, and P3.5 pin on master must
;                 connect to SS pin on slave.
;
;                 If using the ADuC842 eval board, you can
;                 simply connect the 5-pin SPI header directly
;                 to that of the master board.  
;
;                 Once hardware is connected, download code to both
;                 master & slave devices ('842mstr' to the master,
;                 '842slave' to the slave).  Reset the slave first,
;                 and then the master.  The slave will sit with the
;                 LED off until the master starts exchanging data
;                 with it at which time its LED will start blinking
;                 in sync (or 180皁ut of phase) with that of the
;                 master.  When first launched, both master and slave
;                 are transmitting zeros repeatedly on the SPI port.
;                 Pressing the INT0 button on either master or slave
;                 increments the value it is transmitting.  Received
;                 SPI data is relayed out the UART and can be viewed
;                 on any VT100 terminal or terminal emulator at
;                 9600baud/8bits/noparity/1stopbit.  Characters sent
;                 from the terminal to the MicroConverter will update
;                 the value being transmitted by SPI.
;
;********************************************************************

$MOD842         ; Use 8052 & ADuC842 predefined symbols

LED     EQU     P3.4            ; P3.4 drives red LED on eval board

;____________________________________________________________________
                                   ; DEFINE VARIABLES IN INTERNAL RAM
DSEG
ORG 0060h
INPUT:     DS   1               ; data byte received by SPI
OUTPUT:    DS   1               ; data byte to send by SPI

;____________________________________________________________________
                                                  ; BEGINNING OF CODE
CSEG

ORG 0000h
        JMP     MAIN            ; jump to main program

;____________________________________________________________________
                                             ; INTERRUPT VECTOR SPACE
ORG 0003h ; (.................... INT0 ISR)

        INC     OUTPUT
        RETI

ORG 003Bh ; (.................... SPI ISR)

        MOV     INPUT,SPIDAT    ; get data just received by SPI
        MOV     SPIDAT,OUTPUT   ; update next byte to transmit
        CLR     C               ; clear C indicates transfer complete
        RETI

;====================================================================
                                                       ; MAIN PROGRAM
ORG 004Bh

MAIN:
	MOV	PLLCON,#03H
        MOV     SP,#007h

; CONFIGURE UART...
	MOV	T3CON,#083h
	Mov	T3FD,#02Dh
	MOV	SCON,#052h

; CONFIGURE SPI...

        MOV     SPICON,#024h    ; configure SPI port for:
                                ;   CPHA=1, CPOL=0, slave
        MOV     IEIP2,#1        ; enable SPI interrupt

; CONFIGURE INTERRUPT 0...

        SETB    IT0             ; INT0 edge triggered
        SETB    EX0             ; enable INT0 interrupt

; ENABLE INTERRUPTS & ENTER MAIN LOOP...

        MOV     OUTPUT,#0       ; set initial value for output byte..
        MOV     SPIDAT,#0       ; ..including very fisrt output byte
        SETB    EA              ; enable inturrupts

LOOP:   CPL     LED             ; flash the LED on the eval board
        SETB    C
        JC      $               ; wait here to receive SPI transfer
        MOV     A,INPUT         ; send value received by SPI..
        CALL    SENDVAL         ; ..out the UART as 2 hex chars
        MOV     DPTR,#SEPERATOR ; send line-feed & crdg-return..
        CALL    SENDSTRING      ; ..out the UART
        JNB     RI,LOOP         ; repeat (unless UART data received)

; WHEN UART DATA RECEIVED, MOVE DATA TO SPI OUTPUT...

        MOV     OUTPUT,SBUF     ; update OUTPUT byte to new value
        CLR     RI              ; must clear RI
        JMP     LOOP            ; back to main loop

;____________________________________________________________________
                                            ; SUBROUTINE INCLUDE FILE

$INCLUDE(UARTIO.asm)

;____________________________________________________________________
                                                   ; TEXT DATA TABLES

SEPERATOR:      DB 10,13,0

;____________________________________________________________________

END

⌨️ 快捷键说明

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