#include
sbit CS_93C46=P2^7;
sbit SK_93C46=P2^6;
sbit DI_93C46=P2^5;
sbit DO_93C46=P2^4;
unsigned char RD_93C46_byte(unsigned char addr); // read 1 byte data from the specified address inside 93c46
void WR_93C46_byte(unsigned char addr,unsigned char dat); // write 1 byte data to the specified address inside 93c46
void EWEN_93C46(void); // erase and write enabled
void EWDS_93C46(void); // erase and write disabled
void ERASE_93C46(unsigned char addr); // erase data from the specified address
void delaynms(unsigned char k); // ms delay
void leddisplay(); // digital tube display
unsigned char
//Common cathode code 0-F, all off, all on
unsigned char ledxs[8]={16,16,16,16,16,0,0,0}; //Digital tube display buffer
void main()
{
unsigned char temp;
delaynms(200);
leddisplay();
delaynms(200);delaynms(200);delaynms(200);
WR_93C46_byte(0x01,123);
temp=RD_93C46_byte(0x01);
ledxs[7]=temp%10;
ledxs[6]=(temp/10)%10;
ledxs[5]=temp/100;
leddisplay();
while(1);
}
//--------------------------------------------------------------------
// Read 1 byte of data at the specified address inside 93c46
//--------------------------------------------------------------------
unsigned char RD_93C46_byte(unsigned char addr)
{
unsigned char dat=0,i;
SK_93C46=0;
CS_93C46=0;
CS_93C46=1;
DI_93C46=1;SK_93C46=1;SK_93C46=0;
DI_93C46=1;SK_93C46=1;SK_93C46=0;
DI_93C46=0;SK_93C46=1;SK_93C46=0; // Read data instruction: 110
for(i=0;i<7;i++) // write 7-bit address
{
addr<<=1;
if((addr&0x80)==0x80)
DI_93C46=1;
else
DI_93C46=0;
SK_93C46=1;
SK_93C46=0;
}
DO_93C46=1; // DO=1, prepare for reading
for(i=0;i<8;i++) // read 8-bit data
{
dat<<=1;
SK_93C46=1;
if(DO_93C46) dat+=1;
SK_93C46=0;
}
CS_93C46=0;
return(dat);
}
//---------------------------------------------------------------------------------
// Write 1 byte of data to the specified address inside 93c46
//---------------------------------------------------------------------------------
void WR_93C46_byte(unsigned char addr,unsigned char dat)
{
unsigned char i;
EWEN_93C46(); // erase and write allowed
CS_93C46=0;
SK_93C46=0;
CS_93C46=1;
DI_93C46=1;SK_93C46=1;SK_93C46=0;
DI_93C46=0;SK_93C46=1;SK_93C46=0;
DI_93C46=1;SK_93C46=1;SK_93C46=0; // Write data instruction: 101
for(i=0;i<7;i++) // 写7位地址
{
addr<<=1;
if((addr&0x80)==0x80)
DI_93C46=1;
else
DI_93C46=0;
SK_93C46=1;
SK_93C46=0;
}
for(i=0;i<8;i++) // write 8-bit data
{
if((dat&0x80)==0x80)
DI_93C46=1;
else
DI_93C46=0;
SK_93C46=1;
SK_93C46=0;
dat<<=1;
}
CS_93C46=0;
DO_93C46=1;
CS_93C46=1;
while(DO_93C46==0); // detect busy/idle
SK_93C46=0;
CS_93C46=0;
EWDS_93C46(); // erase and write prohibited
}
//----------------------------------------------------------------------------
// Erase and write are allowed, instruction format: 100 Address: 11xxxxx (7 bits)
//----------------------------------------------------------------------------
void EWEN_93C46(void)
{
unsigned char i,addr;
CS_93C46=0;
SK_93C46=0;
CS_93C46=1;
DI_93C46=1;SK_93C46=1;SK_93C46=0;
DI_93C46=0;SK_93C46=1;SK_93C46=0;
DI_93C46=0;SK_93C46=1;SK_93C46=0; // 100
addr=0x7f; // 01111111B
for(i=0;i<7;i++) // write 7-bit address 11xxxxx
{
addr<<=1;
if((addr&0x80)==0x80)
DI_93C46=1;
else
DI_93C46=0;
SK_93C46=1;
SK_93C46=0;
}
CS_93C46=0;
}
//-----------------------------------------------------------------------------
// Erase and write prohibited, instruction format: 100 Address: 00xxxxx (7 bits)
//-----------------------------------------------------------------------------
void EWDS_93C46(void)
{
unsigned char i,addr;
CS_93C46=0;
SK_93C46=0;
CS_93C46=1;
DI_93C46=1;SK_93C46=1;SK_93C46=0;
DI_93C46=0;SK_93C46=1;SK_93C46=0;
DI_93C46=0;SK_93C46=1;SK_93C46=0; // 100
addr=0x00; // 00000000B
for(i=0;i<7;i++) // write 7-bit address 00xxxxx
{
addr<<=1;
if((addr&0x80)==0x80)
DI_93C46=1;
else
DI_93C46=0;
SK_93C46=1;
SK_93C46=0;
}
CS_93C46=0;
}
//------------------------------------
//Serial digital tube display
//------------------------------------
void leddisplay()
{
unsigned char i;
for(i=0;i<8;i++)
{
SBUF=tab[ledxs[i]];
while(TI==0);
TI=0;
}
}
//---------------------------------------------------------------
//Delay n ms
//---------------------------------------------------------------
void delaynms(unsigned char k)
{
while(k)
{
int i;
i=110;
while(i--);
k=k-1;
}
}
Previous article:X9313 51 programs
Next article:51 programs of TLC5615
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- Phase noise basics and test principles and methods as frequency source (LO)
- Ink screen desktop calendar
- The world's first Pi-powered satellite
- STM32L151C8T6 cannot enter serial port interrupt
- Is there a way to block someone in the forum? It's really annoying.
- How to simulate the sound control circuit in Proteus? Please guide me, thank you.
- Moderator Rewards Announcement for March and April 2019
- Switching Circuit
- [RVB2601 Creative Application Development] My Guitar Environmental Protector - Automatic Dry and Humidity Regulator
- 【NXP Rapid IoT Review】 NO2. Experience Sharing of Mobile App BLE Control Development Kit