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

Problem with writing and reading from AT93C46 (memory device)

Hi

I am experiencing a problem with AT9346 as my could not get the reading from memory by displaying 8 LEDs in order to let me know that the content of memory at address 0x00 has been read. Unfortunately nothing happened yet! :-(

// header files
#include "main.h"
#include "port.h"
#include "delay_loop.h"

//global variables



//Function Prototypes

void write_command(unsigned char DATA);
void read_command(unsigned char ADDRESS);

void send_clock();
void process(unsigned char byte);
void EW_enable();
void EW_disable();
//void Erase_command();


void send_clock()
{
   PULSE_CLOCK=1;
   PULSE_CLOCK=0;
}

void process(unsigned char byte)
{
   unsigned char k,nbit;

   for(k=1;k<=8;k++)

   {
      nbit= byte & 0x80;
      if (nbit != 0)
      DIN=1;
      else
      DIN=0;
      send_clock();
      byte=byte <<1;
    }
}


void read_command(unsigned char ADDRESS)
{
   unsigned char i,m,d=0,loop=8;

   CS=1;

   //Send two 1s (Dummies data)
   for(i=1; i<=2; i++)
   {
   DIN=1;
   send_clock();
   }

   process(ADDRESS);

   for(m=0;m<=8;m++)
   {
   d=d | DOUT;
   send_clock();

      if(loop !=0)
      {
         d=d<<1;
      }
      loop--;
   }

   CS=0;
   CS=1;
   CS=0;

   P1=d;  //Send result to P1 (leds)

}

void write_command(unsigned char DATA)
{
   unsigned char const location=0x00;

   CS=1;

   // Transmit 1,1,0
   DIN=1;
   send_clock();
   DIN=0;
   send_clock();
   DIN=1;
   send_clock();

   process(location); //Select address
   process(DATA);     //Write data

   CS=0;
   CS=1;
   CS=0;

}


void EW_enable()
{

   CS=1;
   DIN=1;
   send_clock();
   DIN=0;
   send_clock();
   process(0x7F);
   CS=0;
   CS=1;
}


void EW_disable()
{
   CS=1;
   DIN=1;
   send_clock();
   DIN=0;
   send_clock();
   process(0x30);
   CS=0;
   CS=1;
}
/*
void Erase_command()
{
   CS=1;
   DIN=1;
   send_clock();
   DIN=1;
   send_clock();
   DIN=1;
   send_clock();
   process(0x00);     //Erase Data at address 0x00
   CS=0;
   CS=1;
}
*/

void main(void)
{
      P1=0;
      CS=0;
      DIN=0;
      DOUT=0;
      PULSE_CLOCK=0;

      EW_enable();
      write_command(0xFF);
      Delay_Loop(200);
      read_command(0x00); //Read data at address 0x00
      EW_disable();

}

Any help would be greatly appreicated

Confusedman

0