//SPI 初始化
void SSPINIT(void)
{
TRISBbits.TRISB1 = 0;
TRISCbits.TRISC2 = 0;
TRISCbits.TRISC5 = 0;
TRISCbits.TRISC4 = 1;
TRISCbits.TRISC3 = 0;
SSPCON1bits.CKP = 0;
SSPSTATbits.CKE = 1;
SSPSTATbits.SMP = 0;
SSPCON1bits.WCOL = 0;
SSPCON1bits.SSPOV = 0;
SSPCON1bits.SSPEN = 1;
SSPCON1bits.SSPM3 = 0;
SSPCON1bits.SSPM2 = 0;
SSPCON1bits.SSPM1 = 1;
SSPCON1bits.SSPM0 = 0;
}
//发送一个字节
//返回值为SPI总线读取的值
uchar TX_REG (unsigned char reg)
{
SSPBUF = reg;
while(!SSPSTATbits.BF);/*busy or not*/
return SSPBUF;
}
最近比较忙,暂不做详细解释
文章评论(0条评论)
登录后参与讨论