Simulation circuit diagram:
Simulation program:
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit SCL=P1^0;
sbit SDA=P1^1;
void delay(void)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
void InitI2C(void)
{
SDA = 1;
SCL = 1;
}
void I2CStart(void)
{
SDA=1;
delay();
SCL=1;
delay();
SDA=0;
delay();
SCL=0;
}
void I2CStop(void)
{
SCL=0;
delay();
SDA=0;
delay();
SCL=1;
delay();
SDA=1;
delay();
}
void I2CSend(volatile byte)
{
volatile mask;
flying i,j;
mask=0x80;
for(i=0;i<8;i++)
{
SCL=0;
delay();
if((mask & byte)==0)
{
SDA=0;
}
else
{
SDA=1;
}
mask>>=1;
delay();
SCL=1;
delay();
}
SCL=0;
SDA=1;
delay();
SCL=1;
j=SDA;
delay();
SCL=0;
}
void write_eeprom(uchar addr, uchar databyte)
{
I2CStart();
I2CSend(0xa0);
I2CSend(addr);
I2CSend(databyte);
I2CStop();
}
volatile I2CRead(void)
{
volatile byte;
flying i;
byte = 0;
for(i = 0; i < 8; i++)
{
SCL = 0;
SDA = 1;
delay();
SCL = 1;
delay();
byte <<= 1;
if(SDA == 1)
{
byte |= 0x01;
}
delay();
}
SCL = 0;
SDA = 1;
delay();
SCL = 1;
delay();
SCL = 0;
return byte;
}
fly read_eeprom(fly addr)
{
fly databyte;
I2CStart();
I2CSend(0xa0);
I2CSend(addr);
I2CStart();
I2CSend(0xa1);
databyte = I2CRead();
I2CStop();
return databyte;
}
main()
{
fly addr=0x00,databyte=0xaa;
fly c=0;
uint i;
InitI2C();
while(1)
{
write_eeprom(addr,databyte);
for(i = 0; i < 1000; i++)
{
delay();
}
c = read_eeprom(addr);
P2=c;
}
}
Previous article:51proteus simulation: button control LED light
Next article:51proteus simulation: adc0804 realizes analog-to-digital conversion
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- DSP basic experiment: light emitting diode display led.c
- [RVB2601 development board trial] speaker experiment
- [Shanghai Hangxin ACM32F070 development board] Light up the LCD screen and touch button function operation, drive the buzzer evaluation
- JTAG debug mode exception handling
- What is EMF testing? What is the difference between EMF and EMC testing?
- Recruiting part-time k8s, devops and other consultants or lecturers
- Commonly used algorithms for drones - Kalman filter (VI)
- Serial port experiment
- IoT products have more and more functions. How can we solve the problem of insufficient MCU memory?
- C2000 Development Red Book