Circuit:
Note: I use the LEDs on port P2 to detect which step the circuit has reached. I think it is very clear at a glance.
program:
#include
#define unit unsigned int
#define uchar unsigned char
int ok;
sbit scl=P0^0;
sbit sda=P0^1;
sbit led0=P2^0;
sbit led1=P2^1;
sbit led2 =P2^2;
sbit led3=P2^3;
sbit led4=P2^4;
sbit led5=P2^5;
sbit led6=P2^6;
sbit led7=P2^7;
delay(void) //delay
{
int i;
led1=1;
for(i=0;i<1;i++) led1=0;
}
start(void) //start
{
sda=1;
scl=1;
delay();
sda=0;
delay();
scl=0;
led0=0;
}
stop(void) //stop
{
sda=0;
scl=1;
delay();
sda=1;
delay();
scl=0;
}
checkanswer(void) //check answer
{
sda=1;
scl=1;
if(sda==1)
{
F0=1;
led7=0;
}
scl=0;
led3=0;
}
sendabyte(int temps) //send a byte
{
uchar n=8;
while(n--)
{
led2=1;
if((temps&0x80)==0x80)
{
sda=1;
scl=1;
delay();
scl =0;
}
else
{
sda=0;
scl=1;
delay();
scl=0;
}
temps=temps<<1;
led2=0;
}
}
reciveabyte() //recive a byte
{
uchar n=8,tempr;
while(n--)
{ //uchar idata *abyte
scl=1;
tempr=tempr<<1;
if(sda==1)
tempr=tempr |0x01;
else
tempr=tempr&0xfe;
scl=0;
}
ok=tempr;
return(ok);
}
main(void) //MAIN
{
start();
sendabyte(0xa0);
checkanswer();
if(F0==1) return;
sendabyte(0x00);
checkanswer();
if(F0==1) return;
sendabyte(0x11);
checkanswer();
if(F0==1) return;
/*-----------------------*/
start();
sendabyte(0xa0);
checkanswer();
if(F0==1) return;
sendabyte(0x00);
checkanswer();
if(F0==1) return;
start();
sendabyte(0xa1);
checkanswer();
if(F0==1) return;
reciveabyte();
if(ok==0x11) led6=0;
stop();
}
illustrate:
1. Before writing the driver, it is recommended to understand the read and write timing of the 24CXX series chips. The Chinese information can be downloaded from my network disk. The free registration download link is: http://wdpvip.qupan.com/6293600.html
2. Program function: first write a data 0x11 at address 0x00, and then read it out. If the written data is the same as the read data, LED6 will be lit.
Previous article:MCU simulates I2C bus to read and write EEPROM (24CXX) program 2
Next article:Program Status Word Register PSW Introduction
- 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
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- There are six good ways to detect current. How do you decide which one is best?
- Will the GaN RF market be big?
- Practical tips on HGI MCU HC32L110
- Help
- ODX-based diagnostic application software INTEWORK-OBT
- Share the MSP430F5529 clock UCS programming considerations
- RK3288 Information
- FFT based on C2000 series DSP
- Occupy the posting position, ESP32---WS2812 16*16 dot matrix drawing points, lines and surfaces
- About the pitfalls of ADXL362 accelerometer