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
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Here it comes, here comes the weekly review information~~
- MS5192T replaces AD7792
- Why does the output voltage of a power amplifier have errors? (Part 2)
- [Ask] Can anyone recommend some good photoelectric detectors or infrared receiver tubes (urgent)
- [Unmanned driving smart car based on ESP32 road sign identification] Unboxing ESP32-S2-KALUGA-1+K210Sipeed M1 docking station kit
- script_recording_test_no_reply
- RT-thread introductory training
- [RVB2601 Creative Application Development] Power Monitoring
- Lenovo is marching into the "U" world with "wireless dual-core" and showing its general style again
- Pingtouge RISC-V Low Power Board-RVB2601 Development Board Quick Start Guide