Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/09/12 05:01
Read: 892 times


 
#187646 - help me with 93c46 and at89s52---MikroC
Responding to: ???'s previous message
here is my code for MikroC -
...
//define OP code for Group 1
unsigned char OP_read  = 0x80;	// 2 bit OP + 7 bit address  (DI =1 already)
unsigned char OP_erase = 0xC0;	// 2 bit OP + 7 bit address
unsigned char OP_write = 0x40;	// 2 bit OP + 7 bit address

//define OP code for Group 2
unsigned char OP_EW_enable  = 0x30;	// 4 bit OP + 5 bit X
unsigned char OP_EW_disable = 0x00;	// 4 bit OP + 5 bit X
unsigned char OP_erase_ALL  = 0x20;	// 4 bit OP + 5 bit X
unsigned char OP_write_ALL  = 0x10;	// 4 bit OP + 5 bit X


//define pin
sbit CS at P3.B7;
sbit SK at P3.B6;
sbit DI	at P3.B5;
sbit DO at P3.B4;

unsigned char i,indata,op_h,DT,addr,dta,out_data;
//unsigned char dis_code[] = { 0x28, 0x7E, 0xA2, 0x62,0x74, 0x61, 0x21, 0x7A,0x20, 0x60,0xff};
unsigned char Shift_Left[] = {0xFE, 0xFD, 0xFB, 0xF7,0xEF, 0xDF, 0xBF, 0x7F,};
//unsigned char display[] = {0xff,0xF0,0x0F,0x08,0x09,0xFF,0x05,0x50};

unsigned char dis_code = 0xA2;
//unsigned char Shift_Left = 0x7F;
unsigned char display;

//Group 2
void OP_G2(unsigned char op_h)
{ DI = 1; CS=1; SK=0;
  Delay_ms(2);
  SK=1;
  Delay_ms(2);
  SK=0;
  for(i=0;i<9;i++)
    { DI = (op_h & 0x80);
      SK=1;
      Delay_ms(2);
      op_h <<= 1;
      SK=0;
    }
    Delay_ms(10);

}

void standby(){CS= 0;SK=0;DI=0;}

//Group 1

void OP_G1(unsigned char op_h,unsigned char DT)
{
     DI = 1; CS=1; SK=0;
     Delay_ms(2);
     SK=1;
     Delay_ms(2);
     SK=0;
    i=0;
    while(i<2)
    {
      DI = (op_h & 0x80);
      SK=1;
      Delay_ms(2);
      op_h <<= 1;
      SK=0;
      i++;
    }
    DT<<=1;
    i=0;
    while(i<8)
    {
      DI = (DT & 0x80);
      SK=1;
      Delay_ms(2);
      DT <<= 1;
      SK=0;
      i++;
    }
    DI=0;
}

//---------------------writing-------------

void Into_Chip(unsigned char oph)
{  i=0;
   while(i<8)
    {
      DI = (oph & 0x80);
      SK=1;
      Delay_ms(2);
      oph <<= 1;
      SK=0;
      i++;
    }
}

void WR_Chip(unsigned char addr,unsigned char dta)
{
    OP_G1(OP_write, addr);
    Into_Chip(dta);
    CS=0;
    delay_ms(10);

}


//---------------------reading-------------

unsigned char OUT_Chip()
{
    unsigned char dtt=0;
    i=0;
    while(i<8)
    {   SK = 1;
        dtt |= DO;
        Delay_ms(2);
        SK=0;
        dtt <<= 1;
        i++;
    } //P0=dtt;
    //Delay_ms(500);
    return dtt;
    //P0=dtt;

}


void main()
{  OP_G2(OP_EW_enable); 
   CS=0;
   P0=0x7E;
   P2=0xFE;
   Delay_ms(1000);
   OP_G2(OP_erase_ALL);  
    // CS=0;
    //Delay_ms(1000);
   //OP_G2(OP_write_ALL); CS=0;
   //for(i = 0 ; i < 8; i++)
           WR_Chip(0, dis_code);

   //OP_G2(OP_EW_disable);

   //for(i = 0 ; i < 8; i++){
         OP_G1(OP_read, 0);
         display= OUT_Chip();
       //  }
   standby();

    while(1)
   {
     P2=0xff ;
     for(i=0; i<8; i++)
     {
          P0=display;
          P2=Shift_Left[i];
          delay_ms(400);
     }
   }
}


 



List of 20 messages in thread
TopicAuthorDate
help me with 93c46 and at89s52---MikroC      Mandeep Singh      06/03/12 16:29      
   What You Need to Do Yourself        Michael Karas      06/03/12 17:33      
      need help - 93c46 using AT89s52 - mikroc      Mandeep Singh      06/09/12 04:59      
         MikroC is unwise choice      David Prentice      06/09/12 09:34      
   help me with 93c46 and at89s52---MikroC      Mandeep Singh      06/09/12 05:01      
      So check without scope - adjust code until testable      Per Westermark      06/09/12 06:04      
         you have now 3 times asked help with 93c46/at89s52--MikroC      Erik Malund      06/11/12 07:36      
            93c46/at89s52--MikroC      Mandeep Singh      06/11/12 10:36      
               my suggestion      Erik Malund      06/11/12 11:27      
               You have already been given suggestions      Per Westermark      06/11/12 11:55      
                  help me with 93c46 and at89s52---MikroC      Mandeep Singh      06/12/12 08:33      
                     Use a proper Compiler      David Prentice      06/12/12 08:42      
                        I wanna, I wanna, I wanna,      Erik Malund      06/12/12 09:15      
                     Time to actually prove your logic and your delays      Per Westermark      06/12/12 09:21      
                        ----thanks all for helping out      Mandeep Singh      06/12/12 10:54      
                           do you REALLY expect ....      Erik Malund      06/12/12 11:29      
                     If you can't get MikroC to work ...      Richard Erlacher      06/12/12 15:25      
                        switching to keil      Mandeep Singh      06/13/12 14:32      
                           Example code on this website      David Prentice      06/13/12 15:05      
                           why, oh why      Erik Malund      06/13/12 18:06      

Back to Subject List