#define FMCS_0 P1OUT |= 0x01 //FMCS=1//P1.0 #define FMCS_0 P1OUT &= ~0x01 //FMCS=0//P1.0 #define SCK_1 P1OUT |= 0x08 //SCK=1//P1.3 #define SCK_0 P1OUT &=~ 0x08 //SCK=0//P1.3 #define SI_1 P1OUT |= 0x04 //CPU向AT写1//P1.2 #define SI_0 P1OUT &=~ 0x04 //CPU向AT写0//P1.2 #define SO_IN ((P1IN & 0x02) == 0x02) //CPU读.//P1.1 #define HIGHTOLOW {_NOP(); SCK_1; _NOP(); SCK_0; _NOP();}
写一字节子程序: void Wr1byte(unsigned char Data) { unsigned char i; for (i=0; i<8; i++) { if ((Data & 0x80) == 0x80) SI_1; else SI_0; HIGHTOLOW; Data = Data<< 1; } }
读一字节子程序:
unsigned char Rd1byte(void) { unsigned char i,medBit=0; unsigned char Data=0; for (i=0; i<8; i++) { HIGHTOLOW; _NOP(); if (SO_IN ) medBit = 1; //if(SO==1)medBit=1; else medBit = 0; Data = (Data << 1) | medBit; return Data; } } |