📄 jia.txt.txt
字号:
unsigned char sck[19]={0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0};
unsigned char mosi[19];
unsigned char miso[19];
//发送1BIT数据
void Setbit(n)
{
unsigned char value = 0;
if(tck[n])
value |= 0x01;
if(mosi[n])
value |= 0x02;
DlPortWritePortUchar(0x378, value);
value = DlPortReadPortUchar(0x379);
if(value & 0x80)
miso[n] = 1;
else
miso[n] = 0;
}
//发送一字节数据,返回读出的数据
unsigned char SendByte(unsigned char data)
{
unsigned char n,tmp,ret;
ret = 0;
for(n = 0; n < 19; n++)
{miso[n] = 0;
if(n==0 || n==18)
mosi[n] = 0;
else
tmp = 1<<((n-1)/2);
if((tmp & data) > 0)
mosi[n] = 1;
else
mosi[n] = 0;
Setbit(n);
if(sck[n] == 1)
{tmp = miso[n]<<((n-2)/2);
ret |= tmp;
}
}
return(ret);
}
//编程使能
void EnableProg()
{
SendByte(0xac);
SendByte(0x53);
SendByte(0x55);//下面这两个数随意
SendByte(0x55);
}
//片擦除
void ChipErase()
{
SendByte(0xac);
SendByte(0x80);
SendByte(0x55);//下面这两个数随意
SendByte(0x55);
}
//字节读取
unsigned char ReadByte(unsigned short address)
{
unsigned char Hadd,Ladd,ret;
Ladd = address & 0xff;
Hadd = address >> 8;
SendByte(0x20);
SendByte(Hadd);
SendByte(Ladd);
ret = SendByte(0x55);
return(ret);
}
//字节编程
void ReadByte(unsigned short address,unsigned char data)
{
unsigned char Hadd,Ladd;
Ladd = address & 0xff;
Hadd = address >> 8;
SendByte(0x40);
SendByte(Hadd);
SendByte(Ladd);
SendByte(data);
}
//写保护位
void WriteLockBits(unsigned char mode)
{
SendByte(0xac);
SendByte(0xe0 | mode);
SendByte(0x55);
SendByte(0x55);
}
//读保护位
unsigned char ReadLockBits(void)
{ unsigned char ret;
SendByte(0x24);
SendByte(0x55);
SendByte(0x55);
ret = SendByte(0x55);
ret &= 0x1c;
ret >>= 2;
retrun (ret);
}
//读标志字节
unsigned char ReadSignature(unsigned char address)
{
unsigned char tmp,ret;
tmp = address << 1;
SendByte(0x28);
SendByte(tmp);
tmp = (address &0x1) << 7;
SendByte(tmp);
ret = SendByte(0x55);
return(ret);
}
//页读取
void ReadPage(unsigned char PageAdd,unsigned char *data)
{
int n;
SendByte(0x28);
SendByte(PageAdd);
for(n = 0; n < 256; n++)
*(data + n) = SendByte(0x55);
}
//页编程
void WritePage(unsigned char PageAdd,unsigned char *data)
{
int n;
SendByte(0x50);
SendByte(PageAdd);
for(n = 0; n < 256; n++)
SendByte(*(data +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -