⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mem9346.c

📁 这是用W77E58编写的控制GSM模块
💻 C
字号:
#include "global.h"
#include "util.h"
#include "mem9346.h"



/***************************************************************
*          93C46                                               *
****************************************************************/
#if 0
unsigned long ReadMem32(unsigned char bTrack)
{

      unsigned char k,rAddress = 0x80;
      unsigned long temp = 0;


      EA = 0;
      rAddress |= (bTrack-1) * 2;


      MEM_CS = 1;

      MEM_DI = 1;
      MEM_SCK = 1;

      MEM_SCK = 1; /*delay 1 us */
      MEM_SCK = 0;
      MEM_SCK = 0; /*delay 1 us */

      MemOutByte(rAddress); /*read 93c46 */

      temp = MemInByte();
      temp = (temp << 8)| MemInByte();
      k = 0;             /*delay  1 us */

      MEM_CS = 0;

      MEM_CS = 1;
      MEM_DI = 1;
      MEM_SCK = 1;
      MEM_SCK = 1;  /*delay 1us*/

      MEM_SCK = 0;
      MEM_SCK = 0;  /*delay 1us */

      rAddress++;
      MemOutByte(rAddress); /*read 93c46*/

      temp = (temp << 8)| MemInByte();
      temp = (temp << 8)| MemInByte();


      k = 0;             /*delay  1 us*/

      MEM_CS = 0;
      MEM_DI = 0;
      EA = 1;

      return temp;

}
#endif

#if 1
unsigned int ReadMem16(unsigned char addr)
{

      unsigned char k,rAddress = 0x80;
      unsigned int temp = 0;


      EA = 0;
      rAddress |= addr;


      MEM_CS = 1;

      MEM_DI = 1;
      MEM_SCK = 1;

      MEM_SCK = 1; /*delay 1 us */
      MEM_SCK = 0;
      MEM_SCK = 0; /*delay 1 us*/

      MemOutByte(rAddress); /*read 93c46*/

      temp = MemInByte();
      temp = (temp << 8)| MemInByte();
      k = 0;             /*delay  1 us*/

      MEM_CS = 0;
      MEM_DI = 0;
      EA = 1;

      return temp;

}
#endif


#if 0
/*save 4 byte */
void  SaveMem32(unsigned char bTrack,unsigned char min,unsigned char sec,unsigned char frame)
{



      unsigned char wAddress = 0x40;
      wAddress |= (bTrack-1) * 2;

      EA = 0;


      MEM_CS = 1;

      MEM_DI = 1;

      MEM_SCK = 1;
      MEM_SCK = 1;    /*delay 1us;*/
      MEM_SCK = 0;
      MEM_SCK = 0;    /*delay 1us; */

      MemOutByte(0x30); /*enable write 93c46*/

      MEM_CS = 0;
      MEM_CS = 1;
      MEM_SCK = 0;
      MEM_SCK = 0;   /*delay 1 us;*/
      MEM_DI = 1;
      MEM_SCK = 1;
      MEM_SCK = 1;   /*delay 1 us;*/
      MEM_SCK = 0;

      MemOutByte(wAddress);                  /*addr */
      MemOutByte(bTrack);        
      MemOutByte(min);            

      MEM_CS = 0;
      MEM_CS = 1;

      delay5ms();

      MEM_CS = 0;
      MEM_CS = 1;

      MEM_SCK = 0;
      MEM_SCK = 0;    /*delay 1us*/

      MEM_DI = 1;
      MEM_SCK = 1;
      MEM_SCK = 1;    /*delay 1us*/
      MEM_SCK = 0;

      wAddress++;

      MemOutByte(wAddress);                  
      MemOutByte(sec);    
      MemOutByte(frame);                    


      MEM_CS = 0;
      MEM_CS = 1;

      delay5ms();

      MEM_CS = 0;
      MEM_CS = 1;

      MEM_DI = 1;
      MEM_SCK = 1;
      MEM_SCK = 1;    /*delay 1us*/

      MEM_SCK = 0;
      MEM_SCK = 0;    /*delay 1us*/

      MemOutByte(0x0);

      MEM_CS = 0;

      EA = 1;

}
#endif

#if 1
void  SaveMem16(unsigned char addr,unsigned int memda)
{
      unsigned char wAddress = 0x40;
      wAddress |= addr;

      EA = 0;


      MEM_CS = 1;

      MEM_DI = 1;

      MEM_SCK = 1;
      MEM_SCK = 1;    /*delay 1us;*/
      MEM_SCK = 0;
      MEM_SCK = 0;    /*delay 1us;*/

      MemOutByte(0x30); /*enable write 93c46 */

      MEM_CS = 0;
      MEM_CS = 1;
      MEM_SCK = 0;
      MEM_SCK = 0;   /*delay 1 us; */
      MEM_DI = 1;
      MEM_SCK = 1;
      MEM_SCK = 1;   /*delay 1 us;*/
      MEM_SCK = 0;

      MemOutByte(wAddress);                  /*addr*/
      MemOutByte((memda>>8) & 0xff);        
      MemOutByte(memda & 0xff);            

      MEM_CS = 0;
      MEM_CS = 1;

      delay5ms();

      MEM_CS = 0;
      MEM_CS = 1;

      MEM_DI = 1;
      MEM_SCK = 1;
      MEM_SCK = 1;    /*delay 1us*/

      MEM_SCK = 0;
      MEM_SCK = 0;    /*delay 1us */

      MemOutByte(0x0);

      MEM_CS = 0;

      EA = 1;

}
#endif

void MemOutByte(unsigned char MemData)
{
      unsigned char i,j;
      j = MemData;

      for(i=0;i<8;i++){
        MEM_DI =(bit)(j & 0x80);
        MEM_SCK = 1;
        j <<= 1;
        MEM_SCK = 0;
      }
}


unsigned char MemInByte(void)
{
      unsigned char i,inByte;

      for(i=0;i<8;i++){
        MEM_SCK = 1;
        inByte <<= 1;
        MEM_SCK = 0;
        if(MEM_DO) inByte |= 0x01;
      }

      return(inByte);

}




void delay5ms(void)
{
      unsigned int i;
      for(i=0;i<1000;i++);
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -