This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

atmel

how 2 intialize at89c51ed2 for spi communication with ds1306?

Parents Reply Children
  • "i do not understand that you state "here is my code", code has comments, I see none."

    is that better?

  • "is that better?"

    A little better ;)

    This may be considered better:


    I do not think you are right when you say "here is my code". Code has comments. I see no comments in your post. It could therefore be deduced that you have not actually posted any code for us to view.

    I do admit, however, that mine is way longer than yours.

    ps I totally agree with the sentiments of your original post.

  • 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++);

    }