Re: [問題] 8051與MAX3100 SPI控制

看板ASM (組合語言)作者時間10年前 (2015/03/04 23:02), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
Maxim自身出的source code,用uart轉IrDA對接收解 你可以看它的控制方式 ;***************************************************************** ;IrDA CODE FOR MAX-3100 UART- 8051 based ; Written by: Wettroth 9/13/96- Maxim Integrated Products ; ;MAX-3100 UART demonstration and test code for the 8051 that ;bidirectionally translate IrDA to 232 and 232 to IrDA. Both the ;8051 and IrDA sides run at 9600 baud. All receivers are polled ;to keep code easy to follow. Testing was done with an HP-100 ;Palmtop for IrDA and PC running a terminal program. The primary ;purpose of the code is to demonstrate the UART. ;*************************************************************** ; CONSTANTS PCON EQU 87H ;PORT PIN DEFINITIONS- BIT BANGING IF DOUT BIT P1.0 ;data out (from uart) DIN BIT P1.1 ;data in (from UART) SCLK BIT P1.2 ;serial clock CS BIT P1.3 ;chip select- act low IRQ BIT P3.2 ;(irq) polled in this code ;RAM LOCATIONS TX1 EQU 10H ;transmit regs TX2 EQU 11H RX1 EQU 12H ;receive regs RX2 EQU 13H ;*************************************************************** ORG 0H BEGIN: MOV SP,#70H ;initialize stack CLR SCLK ;clear sclk - normally low ;initialize 8051 internal uart MOV TMOD,#20H ;t1 baud MOV TH1,#253 ;reload value baud 9600/xtal 5.5M MOV SCON,#50H ;uart- m1, tx and rx MOV PCON,#80H ;double baud rate bit MOV TCON,#40H ;start baud timer ;initialize max3100 uart- irda mode at 9600 baud MOV TX1,#0E4H ;high byte of config- R ints MOV TX2,#0CAh ;9600 baud irda mode and two stops CALL UTLK ;send to uart- write config ;************** MAIN ROUTINE LOOP ********************** LOOP: JNB IRQ,URCV ;data avail from 3100 uart? NRECV: JBC RI,RCV51 ;check for 8051 rcv- tx out irda JMP LOOP ;hang here forever ;byte recieved from 3100 uart- get it and send out 8051 uart URCV: MOV TX1,#0 ;read data MOV TX2,#0 ;read data CALL UTLK ;send to 8051 uart- get data to rx MOV A,RX2 ;get data to acc MOV SBUF,A ;send out on RS-232 side 9600 baud JMP LOOP ;back to top ;byte recieved from 8051 uart- get it and send out 3100 uart RCV51: MOV A,SBUF ;data from 8051 uart MOV TX1,#80H ;tx data MOV TX2,A ;data to irda CALL UTLK ;send to uart- send data out IrDA JMP LOOP ;back to top ;********************************************************** ;SUBROUTINES ; UTLK- talk to uart- main routine ; send 16 bits from TX1 TX2 and rcv 16 to RX1 RX2 UTLK: CLR CS ;activate cs MOV A,TX1 ;get high byte CALL BYT8 ;send out MOV RX1,A ;get recieved 1 MOV A,TX2 ;get high byte CALL BYT8 ;send out MOV RX2,A ;get recieved 2 SETB CS ;set CS high RET ;DONE ;************************* ; BYT8- shift out & in 8 bits with spi clocking- from and to acc BYT8: MOV R4,#8 ;8 bits to send SETB DIN ;make sure din is input B8LP: RLC A ;get msb of acc to carry MOV DOUT,C ;put out on pin SETB SCLK ;clock high- clock MOV C,DIN ;get data after clk high CLR SCLK ;clock low MOV ACC.0,C ;put in lsbit of a DJNZ R4,B8LP ;loop til 8 bits RET ;done ; end of code END -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.165.109.151 ※ 文章網址: https://www.ptt.cc/bbs/ASM/M.1425481340.A.C11.html
文章代碼(AID): #1KznvymH (ASM)
文章代碼(AID): #1KznvymH (ASM)