模块说明: c51单片机的i/o模拟spi操作
创建时间:
2005/03/09
创建者: xichen
********************************************************************************/
#ifndef SPI_H #define SPI_H
sbit SPIS_N = P2^1; sbit SPIC = P2^3; sbit SPID = P2^2; sbit SPIQ = P2^4;
extern void spi_reset(); extern void spi_write(unsigned char spi_bValue); extern unsigned char spi_read();
#endif /*******************************************************************************
模块说明: c51单片机的i/o模拟spi操作
创建时间:
2005/03/09
创建者: xichen
********************************************************************************/
#include "includes.h"
#define set_spi_cs() SPIS_N =1 #define clr_spi_cs() SPIS_N =0 #define set_spi_clk() SPIC =1 #define clr_spi_clk() SPIC =0 #define set_spi_di() SPID =1 #define clr_spi_di() SPID =0 #define read_spi_do() SPIQ
//------------------------------------------ void spi_reset() { set_spi_cs(); } //----------------------------------------- void spi_write(unsigned char spi_bValue) { unsigned char no;
clr_spi_cs();
for (no=0;no<8;no++) { clr_spi_clk();
if ((spi_bValue &0x80)==0x80) set_spi_di(); else clr_spi_di();
set_spi_clk();
spi_bValue = (spi_bValue <<1); } } //---------------------------------------------- unsigned char spi_read() { unsigned char no,spi_bValue;
clr_spi_cs();
for (no=0;no<8;no++) { clr_spi_clk();
spi_bValue = (spi_bValue <<1);
set_spi_clk();
if (read_spi_do() ==1)
spi_bValue |=0x01; else
spi_bValue &=~0x01;
}
return spi_bValue; } |