那位高手有STC12C5A60s2单片机的SPI调试程序? 谢谢!!

如题所述

///////////spi.h/////////////////////////////
#ifndef
SPI_H
#define
SPI_H
#include
<stc12le5a60s2.h>
#include
<spi.h>
//sfr
P4
=
0xe8;
//STC12LE5A60S2单片机自带SPI控制器连接
//sbit
VCC1
=
P2^0;//
VCC1
NO
USE
//sbit
SON
=
P1^6
;//
MISO
//sbit
SIN
=
P1^5
;//
MOSI
//sbit
SCKN
=
P1^7
;
//
SCK
sbit
CSN
=
P1^4
;//
28J60
--
CS
//sbit
RSTN
=
P3^5
;
//RST,
no
use
//sbit
INTN
=
P3^3
;
//
INT,
no
use
void
init_spi(void);
void
WriteByte(u8_t
temp);
u8_t
ReadByte(void);
#endif
////////////////////////////////////////////////////////////////
///////////////////////////spi.c/////////////////////////////
#include<spi.h>
//STC12LE5A60S2单片机自带SPI控制器连接
void
init_spi(void)
{
//SSIG
=
1;
//忽略SS脚
//SPEN
=
1;
//允许SPI工作
//DORD
=
0;
//先传高位MSB
//MSTR
=
1;
//设置单片机为主机
SPCTL
=
0xD0;
//SPI
Control
Register
SSIG
SPEN
DORD
MSTR
CPOL
CPHA
SPR1
SPR0
0000,0100
SPSTAT
=
0xC0;
//
//IE2
|=
0x02;
//允许SPI中断控制位
}
void
WriteByte(u8_t
temp)
{
SPDAT
=
temp;
while(!(SPSTAT
&
0x80));
SPSTAT
=
0xC0;
}
u8_t
ReadByte(void)
{
idata
u8_t
temp;
//SPSTAT
=
0xC0;
SPDAT
=
0x00;
while(!(SPSTAT
&
0x80));
temp
=
SPDAT;
SPSTAT
=
0xC0;
return
temp;
}
////////////////////////////////////////////////////////////////
温馨提示:答案为网友推荐,仅供参考