?? spi.c
字號:
/*
** Purpose: SPI init, read & write routines without interrupt.
** These routines works only as an SPI Master.
**
** Version: 1.0.0, 29:th of July 1999
**
** Author: Lars Wictorsson
** LAWICEL / SWEDEN
** http://www.lawicel.com lars@lawicel.com
**
** History: 1999-07-29 Created
*/
#include <avr.h>
#include "spi.h"
/*
** SpiInit() initializes the SPI as a master, enable it
** and set it up as requested by parameter Controlregister.
** See "spi.h" for availible parameter values, they could
** be ORed together. See AVR SPI documentation for more
** detailed information.
*/
void SpiInit(unsigned char ControlRegister)
{
DDRB |= 0xB0; // Set SCK, MOSI & SS as outputs
PORTB &= 0x5F; // clear bits MOSI, & SCK
SPCR = ControlRegister + SPE + MSTR; // Write to control register.
}
/*
** SpiWriteByte() writes a byte to the SPI and waits until
** it has been transmitted. This function doesn't
** return any value back.
*/
void SpiWriteByte(unsigned char byte)
{
SPDR = byte;
while (!(SPSR & 0x80));
byte = SPDR;
}
/*
** SpiReadByte() first writes a byte (a dummy, since
** that byte is to generate clock signals to "poll" home
** the byte from the slave. The function returns the
** received byte.
*/
unsigned char SpiReadByte(void)
{
SPDR = 0x00;
while (!(SPSR & 0x80));
return SPDR;
}
/*
** SpiReadDataReg() reads the last byte in the SPI register
** without any clock signals generated. Could be used
** as reading the last byte received.
*/
unsigned char SpiReadDataReg(void)
{
return SPDR;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -