📄 spi.c
字号:
#ifdef PH_932
#include <reg915.h>
#include "spi.h"
#include "message.h"
// flag to indicate if SPI is currently involved in a transfer or not
// stops a write to the SPI bus while a write is in progress
#define INFORMATION_CNT 4
#define DISC_TYPE_POSI 0
#define INPUT_MODE_POSI 1
#define SAMPLE_FREQ_POSI 2
#define WORD_LENGTH_POSI 3
static bit mspibusy;
bit spi_valid = 0;
char information[INFORMATION_CNT];
char spi_cnt = 0;
unsigned char spi_cmd = 0;
/***********************************************************************
DESC: SPI Interrupt Service Routine
Called when byte transmitted and/or byte received
or if mode changed to slave by Slave Select pin
RETURNS: Nothing
************************************************************************/
void spi_isr () interrupt 9 using 3
{
// clear SPIF bit by writing 1 to it
SPSTAT |= 0x80;
spi_cmd = SPDAT;
/* spi_valid = 1;*/
/*
while(RI == 1);
SBUF = SPDAT;
while(TI == 0);
TI = 0;
*/
// SPI not busy
mspibusy = 0;
} // spi_isr
/***********************************************************************
DESC: Initializes the SPI peripheral
SPI Clock frequency = 250 kHz
Set EA to 1 after calling
RETURNS: Nothing
************************************************************************/
void spi_init()
{
// set MOSI, MISO, /SS and SPICLK as quasi-bidirectional
P2M1 &= 0xC3;
P2M2 &= 0xC3;
// configure SPI
SPCTL = 0x4C;
// SPI initially not busy
mspibusy = 0;
// set SPI interrupt priority to 0
IP1 &= ~0x08;
IP1H &= ~0x08;
// enable SPI interrupt
ESPI = 1;
} // spi_init
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -