We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
how 2 intialize at89c51ed2 for spi communication with ds1306?
I hav written the comments plz go through it. #include <REG51xD2.H>
void SPI(unsigned char);
void sdelay(int ); void main(void) {
EA=1; SPSTA=0x00; SPCON=0xd6; /*MSTR(4th bit),SPEN(7th bit),CPHA(2nd bit),7th,0th & 1st bits are enbled. the 7th ,0th & 1st bits are enbled for Fclk Periph/128*/
IEN1=0x04; /* enable spi interrupt */
P1_7=1;/*mOsi enable*/ P1_6=1;/*sck enable*/ P1_1=1;/*slave select*/ sdelay(1); SPI(0x80);/* send an example data */
sdelay(1); while(1); }
void SPI(unsigned char mybyte) {
SPDAT=mybyte;/* read receive data */
while(!(SPSTA&0x80))/* set software flag */ { ; }
SPSTA&=0x7f;
}
void sdelay(int ms) { unsigned int i,j; for(i=0;i<ms;i++) for(j=0;j<135;j++);