📄 93c46 mcu.txt
字号:
代码开源 93c46驱动 51系列
本着人人为我,我为人人的思想,大家多多贡献自己的成果哦!在网上找到的,加自己修改就成这个样了!哈哈
#include"public.h"
sbit CS=P0^0;
sbit SK=P0^1;
sbit DI=P0^2;
sbit DO=P0^3;
extern void delay(uint16 t);
/*
void Write_93c46(uint8 addr,uint16 dat)
{
uint8 i;
DI=0;
DO=1;
CLK=0;
CLK=1;
CS=1;
CLK=0;
addr=0xa0|addr;
for(i=8;i>0;i--)
{
DI=addr&0x80;
CLK=1;
CLK=0;
addr<<=1;
}
for(i=16;i>0;i--)
{
DI=dat&0x80;
CLK=1;
CLK=0;
dat<<=1;
}
CS=0;
DI=0;
}
uint16 Read_93c46(uint8 addr)
{
uint8 i;
uint16 temp;
DI=0;
DO=1;
CLK=0;
CLK=1;
CS=1;
CLK=0;
addr=0xC0|addr;
for(i=8;i>0;i--)
{
DI=addr&0x80;
CLK=1;
CLK=0;
addr<<=1;
}
DI=0;
DO=0;
for(i=16;i>0;i--)
{
temp<<=1;
CLK=1;
CLK=0;
if(DO)
temp+=1;
}
CS=0;
return temp;
}
*/
void Ewen(void)
{
unsigned char temp,InData;
CS=0;
SK=0;
CS=1;
InData=0x98; // 10011XXXX
for(temp=9;temp>0;temp--)
{ // 9
DI=InData&0x80;
SK=1; SK=0;
InData<<=1;
}
CS=0;
}
// Disables all programming instructions.
void Ewds(void)
{
unsigned char temp,InData;
CS=0;
SK=0;
CS=1;
InData=0x80; // 10000XXXX
for(temp=9;temp>0;temp--)
{ // 9
DI=InData&0x80;
SK=1; SK=0;
InData<<=1;
}
CS=0;
}
// Reads data stored in memory, at specified address.
unsigned int Read(unsigned char address)
{
unsigned char temp;
unsigned int result;
Ewen();
SK=0; DI=1; // 110 A5-A0
CS=0; CS=1;
SK=1; SK=0; // 1
address=address&0x3f|0x80;
for(temp=8;temp>0;temp--)
{ // 8
DI=address&0x80;
SK=1; SK=0;
address<<=1;
}
DO=1;
for(temp=16;temp>0;temp--)
{ // 16
SK=1;
result=(result<<1)|DO;
SK=0;
}
CS=0;
Ewds();
return(result);
}
// Writes memory location An - A0.
void Write(unsigned char address,unsigned int InData)
{
unsigned char temp;
Ewen();
SK=0; DI=1; // 101 A5-A0
CS=0; CS=1;
SK=1; SK=0; // 1
address=address&0x3f|0x40;
for(temp=8;temp>0;temp--)
{ // 8
DI=address&0x80;
SK=1; SK=0;
address<<=1;
}
for(temp=16;temp>0;temp--)
{ // 16
DI=InData&0x8000;
SK=1; SK=0;
InData<<=1;
}
CS=0; DO=1;
CS=1; SK=1;
while(DO==0)
{ // busy test
SK=0; SK=1;
}
SK=0; CS=0;
Ewds();
}
void main()
{
uint8 buf[5];
uint16 temp;
init_12864f();
Display_12864(0x80,"开始了");
while(1)
{
Write(0x01,0x1234);
temp=Read(0x01);
sprintf(buf,"%x",temp);
Display_12864(0x90,buf);
delay(60000);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -