void SpiInit(void) { SPIC1 = 0x5c; // Master mode, SPI enable. SPIC2 = 0x00; // SPIBR = 0x00; // 2MHZ PTADD_PTADD7 = 1;// Out //PTAD_PTAD7 = 1; // Initail zero }
unsigned char Read_SR(void) { unsigned char Tmp; SPID = 0x05; //M95040 Read Stat Register while (!SPIS_SPTEF); Tmp = SPID; while (!SPIS_SPRF); return Tmp; }
unsigned char EepromByteRead(unsigned int EepromAddr) { unsigned char Tmp;
SPID = 0x03; //M95040 Read Command while (!SPIS_SPTEF); SPID = EepromAddr; // M95040 Read Address while (!SPIS_SPTEF);
Tmp = SPID; while (!SPIS_SPRF); return Tmp; } void EepromByteWrite(unsigned char EepromAddr, unsigned char data) { SPID = 0x01; //M95040 Wrtie Stat Register while (!SPIS_SPTEF); SPID = 0x06; //M95040 Write Enable while (!SPIS_SPTEF);
SPID = 0x02; //M95040 Send Write Command while (!SPIS_SPTEF); SPID = EepromAddr; //Send Writen Address while (!SPIS_SPTEF);
SPID = data; //Writen 8 bit MSB while (!SPIS_SPTEF); }
[此贴子已经被作者于2008-9-1 16:48:23编辑过] |