📄 mm36sb020.c
字号:
#include <w77c32.h>
#include "mm36sb020.h"
//total 2048 page,every page store 10 card number
//the last 1800 page store card number
//the first 248 page4 store list of card
//0--46 are not used
//47,48 are store list of list of list of card
//49---66 are store list of list of card
//67----246 are store list of card
//247--tail are store card number
sbit wdi=P2^6;
void test_mm(void);
void init_mm36sb020()
{
unsigned int j;
P4&=0x0e;
P4|=0x08;
SoftReset();
for(j=0;j<3000;j++)wdi^=1;
test_mm();
}
void test_mm()
{
/*
unsigned int j;
unsigned char buf[128];
for (j = 0;j < 128;j++)
{
buf[j] = 0;
}
SequentialWrite(buf,0,128);
AutoProgram(0);
for(j=0;j<3000;j++)
wdi^=1;
for (j = 0;j < 128;j++)
{
buf[j] = 1;
}
SequentialWrite(buf,0,128);
AutoProgram(1);
for(j=0;j<3000;j++)
wdi^=1;
for (j = 0;j < 128;j++)
{
buf[j] = 2;
}
SequentialWrite(buf,0,128);
AutoProgram( 2 );
for(j=0;j<3000;j++)
wdi^=1;
SequentialRead( buf,128*0,5 );
if( (buf[0]==0)&&(buf[1]==0)&&(buf[2]==0)&&(buf[3]==0)&&(buf[4]==0) )
j=0;
else
{
for(;;)wdi^=1;
}
SequentialRead( buf,128*1,5 );
if( (buf[0]==1)&&(buf[1]==1)&&(buf[2]==1)&&(buf[3]==1)&&(buf[4]==1) )
j=0;
else
{
for(;;)wdi^=1;
}
SequentialRead( buf,128*2,5 );
if( (buf[0]==2)&&(buf[1]==2)&&(buf[2]==2)&&(buf[3]==2)&&(buf[4]==2) )
j=0;
else
{
for(;;)wdi^=1;
}
*/
}
void do_clear_all_database_data()
{
}
void SoftReset(void)
{
SendByte(0xfe);
SendByte(0xff);
SendByte(0xff);
SendByte(0xff);
}
void EraseChip(void)
{
SendByte(0xf6);
SendByte(0x90);
}
unsigned char ReadStatusRegister(void)
{
SendByte(0x94);
return(GetByte());
}
//read data from flash to mcu
//_addr lowest 7 bit is in page address
//_addr higher 16 bit is page address
//len is length to be read
void SequentialRead(unsigned char *_DES,unsigned long _ADDR,unsigned char _LEN)
{
unsigned char i;
SendByte(0x9c);
SendByte(_ADDR & 0x7f);
_ADDR <<= 1;
SendByte(_ADDR >> 8);
SendByte(_ADDR >> 16);
*DES++ = GetByte();
for (i = 1;i < _LEN;i++)
{
SendByte(0xa0);
*DES++ = GetByte();
}
}
//write data to mm36sb020 buffer
//_src is buffer is mcu
//_addr is pointer of buffer in mm36sb020
//_len is length
void SequentialWrite(unsigned char *_SRC,unsigned char _ADDR,unsigned char _LEN)
{
unsigned char i;
SendByte( 0xa8 );
SendByte( _ADDR );
SendByte( *_SRC++ );
for ( i = 1;i < _LEN;i++ )
{
SendByte( 0xac );
SendByte( *_SRC++ );
}
}
//write mm36sb020 buffer to flash
//_ADDR is pointer of page
void AutoProgram(unsigned int _ADDR)
{
SendByte(0xb0);
SendByte(_ADDR);
SendByte(_ADDR >> 8);
}
void DirectProgram(unsigned int _ADDR)
{
SendByte(0xb4);
SendByte(_ADDR);
SendByte(_ADDR >> 8);
}
unsigned char GetByte(void)
{
unsigned char i,temp;
unsigned char j;
unsigned char a;
P4|=0x02;
for (i = 0; i < 8; i++)
{
P4&=0x0b;
for(j=0;j<1;j++);
temp >>= 1;
P4|=0x04;
for(j=0;j<1;j++);
a=P4;
a&=0x02;
if( a )
temp |= 0x80;
}
P4&=0x0b;
return(temp);
}
void SendByte(unsigned char _CHR)
{
unsigned char i;
unsigned char j;
for (i = 0; i < 8; i++)
{
P4&=0x0b;
for(j=0;j<1;j++);
if( _CHR&0x01 ==0x01 )
{
P4|=0x02;
}
else
{
P4&=0x0d;
}
P4|=0x04;
for(j=0;j<1;j++);
_CHR >>= 1;
}
P4&=0x0b;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -