#include 〈reg52.h>
#include
#include
#define uchar unsigned char
#define uint unsigned int
uchar TAB_T[]={ 0x31,0x06,0x10,//seconds, minutes, hours
0x13,0x01,0x07,0x08}; //Day, week, month, year.
sbit SDA=P2^6; //data
sbit SCL=P2^7; //clock
void Delay5us(void)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void Start(void)
{
SDA=1;
SCL=1;
Delay5us();
SDA=0;
Delay5us();
}
void Stop(void)
{
SDA=0;
SCL=1;
Delay5us();
SDA=1;
Delay5us();
void Reack(void)
{
fly i=0;
SCL=1; //Ready to detect SDA Delay5us();
while((SDA==1)&&(i<100))i++; //SDA=0 is a response signal, SDA=1 is a non-response signal
SCL=0; //Prepare for the next change data
}
void WriteByte(volatile ucByte)
{
flying i;
SCL=0;
for(i=0;i<8;i++)
{
SDA=(bit)(ucByte&0x80); //Write high bit first
SCL=1;
Delay5us();
SCL=0;
ucByte<<=1;
}
SDA=1; //Release data line
}
fly ReadByte(void)
{
float i,ucByte;
SCL=0;
for(i=0;i<8;i++)
{
ucByte<<=1;
if(SDA)
ucByte++;
SCL=1;
Delay5us();
SCL=0;
}
return ucByte;
}
void Write8563(fly ucAddr,fly ucData)
{
Start();
WriteByte(0xa2);
Reack();
WriteByte(ucAddr);
Reack();
WriteByte(ucData);
Reack();
Stop();
}
fly Read8563(fly ucAddr)
{
void ucData;
Start();
WriteByte(0xa2); //Write device address
Reack();
WriteByte(ucAddr); //write byte address
Reack();
Start();
WriteByte(0xa3); //Write device address, the lowest value is 1 for read
Reack();
ucData=ReadByte(); //Write byte address
Stop();
return ucData; //read data
}
void Init8563(void)
{
fly i,ucAddr=0x02;
Write8563(0x00,0x00);
Write8563(0x01,0x11);
for(i=0;i<7;i++)
{
Write8563(ucAddr,TAB_T[i]);
ucAddr++;
}
}
void GetTime(void)
{
float i,ucData1,ucData2,ucAddr=0x02;
uchar *pTime=TAB_T;
for(i=0;i<7;i++)
{
ucAddr++;
}
pTime[0]&=0x7f; //shield invalid bits
pTime[1]&=0x7f;
pTime[2]&=0x3f;
pTime[3]&=0x3f;
pTime[4]&=0x07;
pTime[5]&=0x1f;
for(i=0;i<7;i++)
{
ucData1=pTime[i]/16; //Convert BCD code to hexadecimal
ucData2=pTime[i]%16;
pTime[i]=ucData1*10+ucData2;
}
}
Previous article:51 single chip microcomputer controls ISD1420 to realize the function of selecting and playing segments
Next article:C51_LCD1602 display
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Sources of Power Consumption in SRAM
- 【Android development learning path】— by Bingqi23
- MSP430 MCU printf function transplantation
- Keyence vision camera communicates with Siemens 1500 PLC to achieve grasping correction with the robot
- LSM6DSO(X) sensor driver key code analysis: read_data_polling routine (Part 2)
- Xunwei STM32MP157 development board Linux + MCU learning materials and tutorials summary (manual + video)
- Microchip FAQ | TA100-VAO secure boot and message authentication for CAN FD in ADAS and IVI systems
- C2000 Piccolo MCU F28027F LaunchPad Development Kit
- [MPS Mall Big Offer Experience Season] Unboxing
- [ESP32-Korvo Review] Part 4: Text-to-Speech TTS