#include"STC12C5A.h"
#define u8_t int
//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
sbit key=P1^0;
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;
}
void main()
{
init_spi();
while(1)
{
if(key==0)
WriteByte(0x01);
P0=ReadByte;
}
}
两个单片机中只有一个按下key建的时候有反映另外一个没有反映,有反映的收到的信息的都是乱码,都是为0xff
求大神解答啊
|