📄 93c46.txt
字号:
sbit SYNC=P3^3;
sbit cs_93c46=P2^5;
sbit clk_93c46=P3^5;
sbit di_93c46=P3^4;
sbit do_93c46=P1^4;
//93c46
void start_93c46()
{
do_93c46=1;
cs_93c46=1;
cs_93c46=0;
di_93c46=0;
clk_93c46=0;
cs_93c46=1;
delay1(10);
}
//
void end_93c46()
{
cs_93c46=0;
di_93c46=1;
clk_93c46=1;
}
//
void send_data_93c46(uchar op_data,uchar num)
{
//d7 d6......d0
uchar temp,temp_data;
temp_data=op_data<<(8-num);
for(temp=0;temp<num;temp++)
{if((temp_data&0x80)==0)
di_93c46=0;
else di_93c46=1;
clk_93c46=1;
delay1(2);
clk_93c46=0;
temp_data=temp_data<<1;
}
}
//write_enable
void ewen_93c46()
{
start_93c46();
send_data_93c46(0x04,0x03);
send_data_93c46(0x60,0x07);
end_93c46();
}
//disable all programming
void ewds_93c46()
{
start_93c46();
send_data_93c46(0x04,0x03);
send_data_93c46(0x00,0x07);
end_93c46();
}
// read data from address
uchar read(uchar address)
{
uchar temp1,temp2;
start_93c46();
send_data_93c46(0x06,0x03);
send_data_93c46(address,0x07);
temp2=0;
for(temp1=0;temp1<8;temp1++)
{
temp2=temp2<<1;
clk_93c46=1; clk_93c46=0;
if(do_93c46==1)
{temp2=temp2|0x01;}
}
end_93c46();
return temp2;
}
//write data
uchar write(uchar address,uchar op_data)
{
uchar temp1,temp2;
ewen_93c46();
start_93c46();
send_data_93c46(0x05,0x03);
send_data_93c46(address,0x07);
send_data_93c46(op_data,0x08);
cs_93c46=0;
cs_93c46=1;
temp1=1;
temp2=500;
while(!do_93c46)
{temp2=temp2-1;
if(temp2==0)
{temp1=0;
break; //
}
}
end_93c46();
ewds_93c46();
return temp1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -