📄 spi.c
字号:
/*
** Copyright (C)1999 KVASER AB, http://www.kvaser.com
** This code may be freely distrubuted and used if the source is indicated.
**
*/
// #define PORTBIT(adr, bit) ((unsigned)(&adr)*8+(bit))
#include <pic.h>
#include "..\inc\std.h"
#include "..\inc\spi.h"
/* This function sets the SPI unit to communicate with Memory and MCP2510 */
#define CKP_high 0x10
#define SSPEN 0x20
#define SPI_master_F4 0x00
#define SPI_master_F16 0x01
#define SPI_master_F64 0x02
#define SPI_master_TMR2 0x03
/* This function sets the SPI to work with MCP2510 and 25LCxx Memory */
void SPI_init_hw( void)
{
TRISC = 0x90; // all bits are outputs except SDI and RX
PORTC = 0; // initialize port c
memCS = 1; // Deselect memory
mcpCS = 1; // Deselect MCP2510
hold = 1; // Normally high if low stop action with SPI memory
SSPCON = SSPEN+SPI_master_F16+CKP_high; //SPI enabled, master, clk/16, clock=low
SSPSTAT = 0x0;
}
/* This function produce a byte on the SPI communication */
uchar SPI_putch(uchar outdata)
{
SSPBUF = outdata; // place data in buffer to send
while ( STAT_BF == 0 )
continue ; // Will put error checking here later
return SSPBUF; // Return data returned from
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -