?? spi.c
字號(hào):
#include <ez8.h>
#include <stdio.h>
#include <sio.h>
#include "spi.h"
void TransmitSPI(void)
//waits for transmission to end
{
while((SPISTAT & TXST) == 0x00); //Wait until transmission
while((SPISTAT & TXST) == TXST); //Wait until end of transmission
}
unsigned char TransferSPI(unsigned char data)
//simultaneously transfers data from master to slave and from slave to master (from host to card and from card to host)
{
SPIDATA = data;
TransmitSPI();
data = SPIDATA;
return data;
}
void InitSPI(void)
//initializes the SPI
{
//SPI pins alternate function
PCADDR = ALT_FUN;
PCCTL |= PIN_ALT;
PCADDR = 0x00;
//SPI settings
SPICTL = (PHASE|CLKPOL|MASTER|SPI_ENABLE);
SPIMODE = (NUMBIT8|SSIO|SS_HIGH);
//Baud Rate Generator
SPIBRH = BAUD_H;
SPIBRL = BAUD_L;
}
void AssertSS()
//selects the MMC (slave)
//used at the start of an SPI transaction
{
SPIMODE &= ~SS_HIGH; //SS' assert
}
void DeassertSS()
//deselects the MMC(slave)
//used at the end of an SPI transaction
{
SPIMODE |= SS_HIGH; //SS' deassert
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -