spi.c

来自「pic单片机驱动mcp2510源代码」· C语言 代码 · 共 46 行

C
46
字号
/*
** 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 + =
减小字号Ctrl + -
显示快捷键?