|
本帖最后由 yz0853 于 2013-2-18 22:58 编辑
C语言:- #include <msp430x14x.h>
- void DELAY2(void)
- {
- unsigned int i;
- for(i=533;i>0;i--)
- {
- }
- }
- void DELAY12(void)
- {
- unsigned int i;
- for(i=3200;i>0;i--)
- {
- }
- }
- void DELAY200(void)
- {
- unsigned int i;
- for(i=26666;i>0;i--)
- {
- }
- }
- void main(void)
- {
- volatile unsigned int i;
- volatile unsigned int backdata;
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
-
- P5SEL |= 0x0E; // P5.1,2,3 SPI option select
- P5DIR |= 0x0B; // P5.0,1,3 output direction
- ME2 |= USPIE1; // Enable USART1 SPI
- UCTL1 |= CHAR + SYNC + MM; // 8-bit SPI Master **SWRST**
- UTCTL1 = SSEL0 + STC; // ACLK, 3-pin
- UBR01 = 0x04; // ACLK/4 for baud rate
- UBR11 = 0x00; // ACLK/4 for baud rate
- UMCTL1 = 0x00; // Clear modulation
- UCTL1 &= ~SWRST; // Initialize USART state
-
- P5OUT &= ~0x01; //使能SST25VF020
- DELAY2();
- TXBUF1 = 0x03; //发送读命令
- while(IFG2&UTXIFG1==0x00); //发送完否?
- TXBUF1=0x00; //发送读地址A23-A16
- while(IFG2&UTXIFG1==0x00); //发送完否?
- TXBUF1=0x10; //发送读地址A8-A15
- while(IFG2&UTXIFG1==0x00); //发送完否?
- TXBUF1=0x10; //发送读地址A0-A7
- while(IFG2&UTXIFG1==0x00); //发送完否?
- TXBUF1=0x33; //发送伪数据用于产生接收数据CLK
- while(IFG2&UTXIFG1==0x00); //发送完否?
- while(IFG2&URXIFG1==0x00); //接收完否?
- DELAY2();
- backdata = RXBUF1; //存放读取的数据
- DELAY2();
- P5OUT|=0x01; //禁止SST25VF020
-
- while (1);
- }
复制代码 汇编:- #include "msp430.h" ; #define controlled include file
- NAME main ; module name
- PUBLIC main ; make the main label vissible
- ; outside this module
- ORG 0FFFEh
- DC16 init ; set reset vector to 'init' label
- RSEG CSTACK ; pre-declaration of segment
- RSEG CODE ; place program in 'CODE' segment
- init: MOV #SFE(CSTACK), SP ; set up stack
- main: NOP ; main program
- MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
- P5 bis.b #0Eh,&P5SEL ; P5.1,2,3 SPI option select
- bis.b #0Bh,&P5DIR ; P5.3,1,0 output direction
- SPI1 bis.b #USPIE1,&ME2 ; Enable USART1 SPI
- bis.b #CHAR+SYNC+MM,&UCTL1 ; 8-bit SPI Master
- bis.b #SSEL0+STC,&UTCTL1 ; ACLK, 3-pin
- mov.b #04h,&UBR01 ; ACLK/4 for baud rate
- clr.b &UBR11 ; ACLK/4 for baud rate
- clr.b &UMCTL1 ; Clear modulation
- bic.b #SWRST,&UCTL1 ; **Initialize USART state machine**
- MOV #00H,R6 ;读写数据的地址:A23-A16
- MOV #10H,R7 ;读写数据的地址:A15-A8
- MOV #10H,R8 ;读写数据的地址:A7-A0
- CALL #RED
- LLLL NOP
- NOP
- JMP LLLL
- RED bic.b #01h,&P5OUT ; 使能SST25VF020芯片
- CALL #DELAY2
- mov.b #03h,&TXBUF1 ; 发送读命令
- L10 BIT.B #UTXIFG1,&IFG2 ;发送完否?
- JZ L10
- mov.b R6,&TXBUF1 ; 发送读地址A23-A16
- L11 BIT.B #UTXIFG1,&IFG2 ;发送完否?
- JZ L11
- mov.b R7,&TXBUF1 ; 发送读地址A8-A15
- L12 BIT.B #UTXIFG1,&IFG2 ;发送完否?
- JZ L12
- mov.b R8,&TXBUF1 ; 发送读地址A0-A7
- L13 BIT.B #UTXIFG1,&IFG2 ;发送完否?
- JZ L13
- MOV.B &RXBUF1,R11
- MOV.B #33H,TXBUF1 ;发送伪数据用于产生接收数据CLK
- L14 BIT.B #UTXIFG1,&IFG2 ;发送完否?
- JZ L14
- L15 bit.b #URXIFG1,&IFG2 ; RXBUF ready?
- JZ L15 ; 1 = ready
- CALL #DELAY2
- mov.b &RXBUF1,R5 ; 存放读取的数据
- CALL #DELAY2
- bis.b #01h,&P5OUT ; 禁止SST25VF020
- RET
- DELAY2 MOV #533,R15
- LOOP1 DEC R15
- JNZ LOOP1
- RET
- DELAY12 MOV #3200,R15
- LOOP2 DEC R15
- JNZ LOOP2
- RET
- DLAY200 MOV #2,R14
- LOOP3 MOV #26666,R15
- LOOP4 DEC R15
- JNZ LOOP4
- DEC R14
- JNZ LOOP3
- RET
- END
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|