亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? hal_spi.c

?? 基于msp430單片機的SD卡讀寫驅動
?? C
字號:
//----------------------------------------------------------------------------
//  This file contains functions that allow the MSP430 device to access the
//  SPI interface.  There are multiple instances of each function; 
//  the one to be compiled is selected by the system variable
//  SPI_SER_INTF, defined in "hal_hardware_board.h".
//----------------------------------------------------------------------------


//----------------------------------------------------------------------------
//  void halSPISetup(void)
//
//  DESCRIPTION:
//  Configures the assigned interface to function as a SPI port and
//  initializes it.
//----------------------------------------------------------------------------
//  void halSPIWriteReg(char addr, char value)
//
//  DESCRIPTION:
//  Writes "value" to a single configuration register at address "addr".
//----------------------------------------------------------------------------
//  void halSPIWriteBurstReg(char addr, char *buffer, char count)
//
//  DESCRIPTION:
//  Writes values to multiple configuration registers, the first register being
//  at address "addr".  First data byte is at "buffer", and both addr and
//  buffer are incremented sequentially (within the CCxxxx and MSP430,
//  respectively) until "count" writes have been performed.
//----------------------------------------------------------------------------
//  char halSPIReadReg(char addr)
//
//  DESCRIPTION:
//  Reads a single configuration register at address "addr" and returns the
//  value read.
//----------------------------------------------------------------------------
//  void halSPIReadBurstReg(char addr, char *buffer, char count)
//
//  DESCRIPTION:
//  Reads multiple configuration registers, the first register being at address
//  "addr".  Values read are deposited sequentially starting at address
//  "buffer", until "count" registers have been read.
//----------------------------------------------------------------------------
//  char halSPIReadStatus(char addr)
//
//  DESCRIPTION:
//  Special read function for reading status registers.  Reads status register
//  at register "addr" and returns the value read.
//----------------------------------------------------------------------------
//  void halSPIStrobe(char strobe)
//
//  DESCRIPTION:
//  Special write function for writing to command strobe registers.  Writes
//  to the strobe at address "addr".
//----------------------------------------------------------------------------




#ifndef _SPILIB_C
#define _SPILIB_C
//
//---------------------------------------------------------------
#include "hal_SPI.h"
#include "hal_hardware_board.h"
//#include "hal_MMC_hardware_board.h"

//#define withDMA

#ifndef DUMMY_CHAR
#define DUMMY_CHAR 0xFF
//#define DUMMY_CHAR 0x00
#endif

// SPI port functions
#if SPI_SER_INTF == SER_INTF_USART0

void halSPISetup(void)
{
  UCTL0 = CHAR + SYNC + MM + SWRST;         // 8-bit SPI Master **SWRST**
  UTCTL0 = CKPL + SSEL1 + SSEL0 + STC;      // SMCLK, 3-pin mode
  UBR00 = 0x02;                             // UCLK/2
  UBR10 = 0x00;                             // 0
  UMCTL0 = 0x00;                            // No modulation
  ME1 |= USPIE0;                            // Enable USART0 SPI mode
  UCTL0 &= ~SWRST;                          // Initialize USART state machine
}

#elif SPI_SER_INTF == SER_INTF_USART1

void halSPISetup(void)
{
  /*
  UCTL1 = CHAR + SYNC + MM + SWRST;         // 8-bit SPI Master **SWRST**
  UTCTL1 = CKPL + SSEL1 + SSEL0 + STC;      // SMCLK, 3-pin mode
  UBR01 = 0x02;                             // UCLK/2
  UBR11 = 0x00;                             // 0
  UMCTL1 = 0x00;                            // No modulation
  ME2 |= USPIE1;                            // Enable USART1 SPI mode
  UCTL1 &= ~SWRST;                          // Initialize USART state machine
  */
  //SPI 8bit master
  U1CTL |=SWRST;
  U1CTL |=CHAR+SYNC+MM; //8-bit master spi mode
  U1TCTL  |=SSEL1+STC+CKPH;    //baud rate generated by SMCLK(8M)
  U1BR0 =0X02;//0x04;        //BAUD RATE =SMCLK/8   1Mhz?
  U1BR1 =0x00;
  U1MCTL  =0x00;
  ME2 |=USPIE1;
  U1CTL &=~SWRST;
  IFG2  &=~(UTXIFG1+URXIFG1); //clear interrupt flags 
}

#elif SPI_SER_INTF == SER_INTF_USCIA0

void halSPISetup(void)
{
  UCA0CTL0 = UCMST+UCCKPL+UCMSB+UCSYNC;     // 3-pin, 8-bit SPI master
  UCA0CTL1 = UCSSEL_2 + UCSWRST;            // SMCLK
  UCA0BR0 |= 0x02;                          // UCLK/2
  UCA0BR1 = 0;
  UCA0MCTL = 0;
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
}

#elif SPI_SER_INTF == SER_INTF_USCIA1

void halSPISetup(void)
{
  
  UCA1CTL0 = UCMST+UCCKPL+UCMSB+UCSYNC;     // 3-pin, 8-bit SPI master
  UCA1CTL1 = UCSSEL_2 + UCSWRST;            // SMCLK
  UCA1BR0 |= 0x02;                          // UCLK/2
  UCA1BR1 = 0;
  UCA1MCTL = 0;
  UCA1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  
 
}

#elif SPI_SER_INTF == SER_INTF_USCIB0

void halSPISetup(void)
{
  UCB0CTL0 = UCMST+UCCKPL+UCMSB+UCSYNC;     // 3-pin, 8-bit SPI master
  UCB0CTL1 = UCSSEL_2+UCSWRST;              // SMCLK
  UCB0BR0 |= 0x02;                          // UCLK/2
  UCB0BR1 = 0;
  //UCB0MCTL = 0;
  UCB0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
}

#elif SPI_SER_INTF == SER_INTF_USCIB1

void halSPISetup(void)
{
  UCB1CTL0 = UCMST+UCCKPL+UCMSB+UCSYNC;     // 3-pin, 8-bit SPI master
  UCB1CTL1 = UCSSEL_2+UCSWRST;              // SMCLK
  UCB1BR0 |= 0x02;                          // UCLK/2
  UCB1BR1 = 0;
  UCB1MCTL = 0;
  UCB1CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
}

#elif SPI_SER_INTF == SER_INTF_USI

void halSPISetup(void)
{
  USICTL0 = USIPE7+USIPE6+USIPE5+USIMST+USIOE+UCSWRST; // Port, SPI master
  USICKCTL = USISSEL_2 + USICKPL;           // SCLK = SMCLK
  USICTL0 &= ~USISWRST;                     // USI released for operation

  USISRL = 0x00;                            // Ensure SDO low instead of high,
  USICNT = 1;                               // to avoid conflict with CCxxxx
}

#elif SPI_SER_INTF == SER_INTF_BITBANG

void spi_bitbang_out(unsigned char);
unsigned char spi_bitbang_in();
unsigned char spi_bitbang_in_data;

void halSPISetup(void)
{
}

// Output eight-bit value using selected bit-bang pins
void spi_bitbang_out(unsigned char value)
{
  char x;

  for(x=8;x>0;x--)
  {

    if(value & 0x80)                        // If bit is high...
      MMC_PxOUT |= MMC_SIMO;// Set SIMO high...
    else
      MMC_PxOUT &= ~MMC_SIMO;//Set SIMO low...
    value = value << 1;                     // Rotate bits

    MMC_PxOUT &= ~MMC_UCLK; // Set clock low
    MMC_PxOUT |= MMC_UCLK;  // Set clock high
  }
}

// Input eight-bit value using selected bit-bang pins
unsigned char spi_bitbang_in()
{
  char x=0;
  int y;

  for(y=8;y>0;y--)
  {
    MMC_PxOUT &= ~MMC_UCLK; // Set clock low
    MMC_PxOUT |= MMC_UCLK;  // Set clock high

    x = x << 1;                             // Rotate bits
    if(MMC_PxIN & MMC_SOMI)                 // If bit is high...
      x |= 0x01;                            // input bit high
  }
  spi_bitbang_in_data = x;
  return(x);
}
// Input eight-bit value using selected bit-bang pins
unsigned char spi_bitbang_inout(unsigned char value)
{
  char x=0;
  int y;

  for(y=8;y>0;y--)
  {
    if(value & 0x80)                        // If bit is high...
      MMC_PxOUT |= MMC_SIMO;// Set SIMO high...
    else
      MMC_PxOUT &= ~MMC_SIMO;//Set SIMO low...
    value = value << 1;                     // Rotate bits

    MMC_PxOUT &= ~MMC_UCLK; // Set clock low
    MMC_PxOUT |= MMC_UCLK;  // Set clock high

    x = x << 1;                             // Rotate bits
    if(MMC_PxIN & MMC_SOMI)                 // If bit is high...
      x |= 0x01;                            // input bit high
  }
  spi_bitbang_in_data = x;
  return(x);
}
#endif


//Send one byte via SPI
unsigned char spiSendByte(const unsigned char data)
{
  while((U1TCTL&TXEPT)!=0X01);
  //while (halSPITXREADY ==0);    // wait while not ready for TX
  halSPI_SEND(data);            // write
  while (halSPIRXREADY ==0);    // wait for RX buffer (full)
  return (halSPIRXBUF);
}


//Read a frame of bytes via SPI
unsigned char spiReadFrame(unsigned char* pBuffer, unsigned int size)
{
#ifndef withDMA
  unsigned long i = 0;
  // clock the actual data transfer and receive the bytes; spi_read automatically finds the Data Block
   
   //receive a dummy char
  /*
    while (halSPITXREADY ==0);   // wait while not ready for TX
    halSPI_SEND(DUMMY_CHAR);     // dummy write
    while (halSPIRXREADY ==0);   // wait for RX buffer (full)
    pBuffer[0] = halSPIRXBUF;*/
    //----------------------------------------------------------
   for (i = 0; i < size; i++){
    while (halSPITXREADY ==0);   // wait while not ready for TX
    halSPI_SEND(DUMMY_CHAR);     // dummy write
    while (halSPIRXREADY ==0);   // wait for RX buffer (full)
    pBuffer[i] = halSPIRXBUF;
  }
#else
        U1IFG &= ~(URXIFG1 + URXIFG1);      /* clear flags */
        /* Get the block */
        /* DMA trigger is UART1 receive for both DMA0 and DMA1 */
        DMACTL0 &= ~(DMA0TSEL_15 | DMA1TSEL_15);
        DMACTL0 |= (DMA0TSEL_9 | DMA1TSEL_9);
        /* Source DMA address: receive register.  */
        DMA0SA = U1RXBUF_;
        /* Destination DMA address: the user data buffer. */
        DMA0DA = (unsigned short)pBuffer;
        /* The size of the block to be transferred */
        DMA0SZ = size;
        /* Configure the DMA transfer*/
        DMA0CTL =
          DMAIE   |                         /* Enable interrupt */
          DMADT_0 |                         /* Single transfer mode */
          DMASBDB |                         /* Byte mode */
          DMAEN |                           /* Enable DMA */
          DMADSTINCR1 | DMADSTINCR0;        /* Increment the destination address */

        /* We depend on the DMA priorities here.  Both triggers occur at
           the same time, since the source is identical.  DMA0 is handled
           first, and retrieves the byte.  DMA1 is triggered next, and
           sends the next byte. */
        /* Source DMA address: constant 0xFF (don't increment)*/
        DMA1SA = U1TXBUF_;
        /* Destination DMA address: the transmit buffer. */
        DMA1DA = U1TXBUF_;
        /* Increment the destination address */
        /* The size of the block to be transferred */
        DMA1SZ = count-1;
        /* Configure the DMA transfer*/
        DMA1CTL =
          DMADT_0 |                         /* Single transfer mode */
          DMASBDB |                         /* Byte mode DMADSTBYTE 1:byte 0:word*/
          DMAEN;                            /* Enable DMA */

        /* Kick off the transfer by sending the first byte */
        halMMC_SEND(0xFF);
        _EINT(); //LPM0;  // wait till done
#endif
  return(0);
}


//Send a frame of bytes via SPI
unsigned char spiSendFrame(unsigned char* pBuffer, unsigned int size)
{
#ifndef withDMA
  unsigned long i = 0;
  // clock the actual data transfer and receive the bytes; spi_read automatically finds the Data Block
  for (i = 0; i < size; i++){
    while (halSPITXREADY ==0);   // wait while not ready for TX
    halSPI_SEND(pBuffer[i]);     // write
    while (halSPIRXREADY ==0);   // wait for RX buffer (full)
    pBuffer[i] = halSPIRXBUF;
  }
#else
      /* Get the block */
      /* DMA trigger is UART send */
      DMACTL0 &= ~(DMA0TSEL_15);
      DMACTL0 |= (DMA0TSEL_9);
      /* Source DMA address: the data buffer.  */
      DMA0SA = (unsigned short)pBuffer;
      /* Destination DMA address: the UART send register. */
      DMA0DA = U1TXBUF_;
      /* The size of the block to be transferred */
      DMA0SZ = count;
      /* Configure the DMA transfer*/
      DMA0CTL =
        DMAREQ  |                           /* start transfer */
        DMADT_0 |                           /* Single transfer mode */
        DMASBDB |                           /* Byte mode */
        DMAEN |                             /* Enable DMA */
        DMASRCINCR1 | DMASRCINCR0;          /* Increment the source address */
#endif
  return(0);
}


#ifdef withDMA
#ifdef __IAR_SYSTEMS_ICC__
#if __VER__ < 200
interrupt[DACDMA_VECTOR] void DMA_isr(void)
#else
#pragma vector = DACDMA_VECTOR
__interrupt void DMA_isr(void)
#endif
#endif

#ifdef __CROSSWORKS__
void DMA_isr(void)   __interrupt[DACDMA_VECTOR]
#endif

#ifdef __TI_COMPILER_VERSION__
__interrupt void DMA_isr(void);
DMA_ISR(DMA_isr)
__interrupt void DMA_isr(void)
#endif
{
  DMA0CTL &= ~(DMAIFG);
  //LPM3_EXIT;
}
#endif


//---------------------------------------------------------------------
#endif /* _SPILIB_C */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲成a人片在线不卡一二三区| 成人av动漫在线| 国产91丝袜在线18| 欧美日本精品一区二区三区| 国产夜色精品一区二区av| 亚洲国产日韩精品| 成人av电影在线| 精品sm在线观看| 日韩av电影天堂| 欧美在线观看视频一区二区三区| 久久久久国产一区二区三区四区| 日本不卡不码高清免费观看| 色一区在线观看| 中文字幕第一区二区| 黄网站免费久久| 91精品国产综合久久国产大片| 中文字幕亚洲成人| 丁香桃色午夜亚洲一区二区三区| 日韩精品影音先锋| 日韩va欧美va亚洲va久久| 欧美日韩精品一区二区三区 | 久久精品人人做人人综合 | 亚洲最大的成人av| 成人动漫一区二区| 中文字幕高清不卡| 成人免费的视频| 中文字幕中文字幕中文字幕亚洲无线| 久久av老司机精品网站导航| 欧美一区二区三区免费大片| 日韩av中文字幕一区二区三区| 欧美久久一二三四区| 午夜在线电影亚洲一区| 9191成人精品久久| 青草国产精品久久久久久| 欧美一区二区精品| 久久国产精品99久久久久久老狼| 日韩区在线观看| 久久99精品视频| 久久久久国产免费免费| 成人污污视频在线观看| 中文字幕在线观看一区| 91啦中文在线观看| 亚洲成年人网站在线观看| 欧美福利视频一区| 久久疯狂做爰流白浆xx| 26uuu久久综合| 99久久夜色精品国产网站| 一区二区三区在线看| 欧美精品在线视频| 黑人精品欧美一区二区蜜桃| 国产精品久久久久一区二区三区| av成人免费在线观看| 亚洲国产wwwccc36天堂| 欧美一区二区三区免费| 丁香一区二区三区| 尤物在线观看一区| 日韩欧美在线影院| 国产成人aaa| 亚洲成人一区在线| 久久综合色之久久综合| zzijzzij亚洲日本少妇熟睡| 午夜不卡av免费| 中文无字幕一区二区三区 | 成人动漫一区二区三区| 亚洲国产美女搞黄色| 精品理论电影在线| 92国产精品观看| 免费在线看一区| 国产精品福利av| 欧美一级国产精品| 99热国产精品| 国产精品一区二区x88av| 亚洲精品成人精品456| 日韩精品一区二区三区在线| 色婷婷激情一区二区三区| 久久99国产精品成人| 亚洲黄色尤物视频| 国产亚洲精品资源在线26u| 欧美日韩成人一区| 91在线视频在线| 国产成人免费视频精品含羞草妖精 | 91精品国产丝袜白色高跟鞋| 99视频一区二区三区| 狠狠色狠狠色综合系列| 亚洲一区二区精品3399| 久久久99久久精品欧美| 6080日韩午夜伦伦午夜伦| 99久久精品免费看国产| 国产福利91精品一区| 久久av老司机精品网站导航| 亚洲.国产.中文慕字在线| 中文字幕在线观看不卡| 亚洲精品一线二线三线无人区| 欧美日韩午夜影院| 在线视频综合导航| 成+人+亚洲+综合天堂| 国产在线精品不卡| 免费成人在线网站| 日韩精品电影一区亚洲| 亚洲成人7777| 亚洲一区二区三区国产| 一区二区三区蜜桃| 亚洲乱码中文字幕综合| 亚洲少妇屁股交4| 综合婷婷亚洲小说| 中文字幕av一区二区三区高| 中文一区二区完整视频在线观看| 国产日本亚洲高清| 中文字幕 久热精品 视频在线| 国产午夜精品一区二区三区视频| 精品国产99国产精品| 精品久久免费看| 久久久久久亚洲综合影院红桃| 久久久久久久电影| 中文字幕不卡在线观看| 亚洲欧洲日韩综合一区二区| 亚洲天天做日日做天天谢日日欢| 国产精品免费aⅴ片在线观看| 国产精品嫩草99a| 一区二区三区欧美日| 亚洲v中文字幕| 免费欧美在线视频| 精品影院一区二区久久久| 国产一区二区三区免费看| 成人午夜精品在线| 91在线porny国产在线看| 日本精品一级二级| 欧美福利视频导航| 久久久无码精品亚洲日韩按摩| 国产三级一区二区三区| 国产精品久久久久三级| 亚洲精品欧美激情| 日本欧美一区二区三区| 国产精品亚洲一区二区三区妖精| 成人av集中营| 88在线观看91蜜桃国自产| 精品国产一区久久| 国产精品你懂的在线欣赏| 夜夜嗨av一区二区三区网页| 美女视频一区在线观看| 成人性生交大片免费看中文| 欧美性色黄大片| 精品成人a区在线观看| 亚洲男帅同性gay1069| 首页欧美精品中文字幕| 国产伦精品一区二区三区免费迷| av中文字幕在线不卡| 日韩一区二区三区视频| 国产精品蜜臀在线观看| 日本午夜精品一区二区三区电影| 丰满岳乱妇一区二区三区| 欧美午夜在线观看| 亚洲国产精品成人综合色在线婷婷 | 日韩欧美成人午夜| 亚洲欧洲精品一区二区三区| 水蜜桃久久夜色精品一区的特点 | 国产成人午夜电影网| 欧美三级在线看| 欧美国产禁国产网站cc| 天使萌一区二区三区免费观看| 国产一区二区不卡在线| 欧美美女视频在线观看| 国产精品人人做人人爽人人添| 日本免费新一区视频| 一本色道久久综合亚洲aⅴ蜜桃| 亚洲已满18点击进入久久| 懂色av中文一区二区三区| 日本91福利区| 91热门视频在线观看| 久久综合久久久久88| 香蕉加勒比综合久久| 一本色道久久综合亚洲91 | 精品在线一区二区三区| 欧美三日本三级三级在线播放| 国产精品久久久久久久久免费樱桃| 免费成人在线观看| 在线不卡一区二区| 亚洲综合免费观看高清完整版 | 欧美性生活大片视频| 17c精品麻豆一区二区免费| 狠狠色丁香久久婷婷综合丁香| 337p亚洲精品色噜噜| 一区二区三区在线观看视频| 99在线精品视频| 中文字幕日本不卡| 波多野结衣中文字幕一区| 久久网这里都是精品| 久久精品国产精品亚洲综合| 欧美精品三级在线观看| 亚洲成人免费视| 欧美理论片在线| 视频一区二区三区中文字幕| 欧美在线不卡一区| 亚洲电影在线播放| 欧美日韩免费视频| 亚洲成年人影院| 日韩欧美综合一区| 国产综合成人久久大片91| 久久综合久久综合久久综合| 国产成人在线视频网址|